i used zend_tool to setup a project then to create module blog with index controller etc but i guess the default config setup by zend_tool does not work with modules so i edited it
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.moduleDirectoryControllerName = "controllers"
i guess these are required for modules? also i moved the folders, controllers, models, views into the modules/ folder
but i get a blank screen when i try to go to http://servername which shld load Default module's index controller and action. even if i try to go http://servername/nonexistentpage it also shows a blank screen instead of a 404
You don't have to move controllers, models, and views.
These are directories of the default module, which is not placed in modules directory (by default).
All you need is:
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =
If you want to place default module in the modules too, you have to set up the app like this:
; Default Application Resource Namespace
appnamespace = "YourPrefix"
; FrontController Resource Settings
resources.frontController.defaultController = "index"
resources.frontController.defaultAction = "index"
resources.frontController.defaultModule = "modulename"
resources.frontController.prefixDefaultModule = true
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.displayExceptions = 1
The reason you do not see anything is that the app throws errors, which are not shown due to your configuration. Try these settings:
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
Ensure you have SetEnv APPICATION_ENV development in your .htaccess
Upgrade Zend Framework to the newest version. Newest Zend Tool generates /docs directory with README.txt, which describes how to set up virtual host.
Hope this helps :)
And…
Welcome to the SO!
Related
I've enabled development mode using composer development-enable . How can I check in my module's config/module.config.php that development is enabled or not?
I've also added SetEnv APPLICATION_ENV development in public/.htaccess and tried to use it in module.config.php using echo APPLICATION_ENV;exit; but it doesn't give me environment.
How I can set and get application environment in zend framework 3?
use the correct function ;)
$environment = getenv('APPLICATION_ENV');
Usage for config in ZF2/3:
$env = getenv('APPLICATION_ENV'); // Expect null or "development"
$modules = [];
if ($env === 'development') {
//Array of modules used only for development
$modules = array_merge_recursive($modules, [
'Zf2Whoops',
]);
}
In just Zend Framework nothing special happens with the usage of composer development-enable. However, if you use Apigility at some point, it will create a development.config.php file for you which disables application caches.
First of all I am a newbie. I installed zend framework in my wamp server successfulley. My include path is as follows:
include_path = ".;E:\wamp\bin\php\zend_framework\library"
I have create a project name "mehedi". But when I browse to my Bootstrap.php file in mehedi/application/ directory it shows the following error :
Fatal error: Class 'Zend_Application_Bootstrap_Bootstrap' not found in E:\wamp`\www\mehedi\application\Bootstrap.php on line 4`
When I browse to other php files except mehedi/public/index.php it shows some Fatal Error.
Is everything ok or I have missed something important.
Here is the application configuration in my mehedi/application/configs/application.ini file :
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
If you set up your application using the Zend_Tool command line interface and it put the .htaccess file in the public folder, as is the default. This behavior you described is to be expected. The ZF MVC routes all requests through the index.php file (except for resources like images, css and javascript). So if you can route to your Bootstrap.php file directly, then you worry.
All urls in ZF should be in the form www.example.com/moduleName/controllerName/actionName with the abiltiy to append parameters as required. Also note that the moduleName is optional and will default to the controllerName if no moduleName matches a route.
To test your installation use the url like: mehedi/public/index/ and you should see the default welcome screen. As you add controllers and actions you'll automatically add new url routes.
[EDIT]
for example, if you add a controller called AdminController (if you add it with Zend_Tool it will be built with the indexAction() automatically). You will automatically be able to route to the AdminController/indexAction with a url of www.mehedi.com/admin/index and it would work. (in most applications index is specified as the default action so www.mehedi.com/admin would achieve the same result)
P.S. Do your self a favor and setup a virtul host it makes life so much easier
here is an example what your vhosts might look like, it's important to declare the localhost as the first vhost if you intend to use it.
httpd-vhosts.conf with Include conf/extra/httpd-vhosts.conf enabled in httpd.conf
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
DocumentRoot "C:\Zend\Apache2/htdocs" #I use Zend server, make this match your wamp setup
ServerName localhost
#directory settings for localhost are typically defined in httpd.conf
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "E:/wamp/www/mehedi/public"
ServerName www.mehedi.com
ErrorLog "path/to/your/log/file"
<directory "E:/wamp/www/mehedi">
Options Indexes FollowSymlinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>
</VirtualHost>
it's important to remember this kind of vhost setup is intended to be used on a local dev machine or an internal network server, you would not want to do this on a production server unless you really know what you are doing.
applications coupled with the realization ZendFramework + Doctrine 1.2 for some time, but now they have their first experience with the use of more modules. I requested a default module is visible to everyone with a certain layout and an admin module with a different layout.
So far in my applications I have always used the following structure:
/app
/application
/acls
/configs
/controllers
/forms
/layouts
/models --> models by doctrine
/generated --> base models by doctrine
/plugins
/views
/Bootstrap.php
/data
/doctrine
/data
/migrations
/schema
/schema.yml
/doctrine.php
/library
/public
/tests
So my question is: how should the structure of my application to do what is required?
I tried using zend tool and see what kind of structure I created the command:
zf create module admin
course after launching
zf create project app
I noticed that the create command module I created a folder modules in application.
Into modules created admin and inside it has created controllers, models and views.
So in addition to separating means zf controller and view correctly, but also models.
But my doctrine creates all the models on the one hand! :D
How can I do to use templates created by doctrine for each module?
Then how do I assign a new layout for the admin module?
For the party guest you advise me to leave the facility that currently use or move it all in a form default?
Sorry if I made a lot of questions, maybe too much, but I am really very confused about it!
Thanks
After a thorough documentation I've found the right project structure
/app
/application
/acls
/configs
application.ini
/layouts
/scripts
admin.phtml
default.phtml
/models --> models by doctrine
/generated --> base models by doctrine
/modules
/admin
/controllers
/forms
/view
/default
/controllers
/forms
/view
/plugins
/Bootstrap.php
/data
/doctrine
/data
/migrations
/schema
/schema.yml
/doctrine.php
/library
/public
/tests
To view a different layout according to where you are module I used the following plugins:
class Plugin_Layout extends Zend_Controller_Plugin_Abstract
{
/**
* Called before an action is dispatched by Zend_Controller_Dispatcher.
*
* #param Zend_Controller_Request_Abstract $request
* #return void
*/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$layout = Zend_Layout::getMvcInstance();
$module = $request->getModuleName();
switch ($module) {
case 'default':
$layout->setLayout('default');
break;
case 'admin':
$layout->setLayout('admin');
break;
default:
$layout->setLayout('default');
break;
}
}
}
into Bootstrap.php file
/**
* #return Zend_Application_Module_Autoloader
*/
protected function _initAutoload()
{
$autoloader = new Zend_Application_Module_Autoloader(array('namespace' => '', 'basePath' => APPLICATION_PATH));
$autoloader->addResourceType('plugin', 'plugins', 'Plugin');
return $autoloader;
}
into application.ini file
resources.frontController.plugins.auth = Plugin_Layout
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
the plugin described above according to the module in use will set the layout with the name of module.phtml within "layouts/scripts".
How to Autoload forms within a module
add the two below lines to your application.ini file
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = ""
Create a boostrap file for each module. The file, named Bootstrap.php, should be placed in the root of the module directory and the class name should be {module name}_Boostrap. This bootstrap file will cause zend framework to automatically add the new forms directory to the autoloader.
class Admin_Bootstrap extends Zend_Application_Module_Bootstrap {}
Add for form class to the /forms directory. A login form would have a filename of Login.php and a class name of {module name}_Form_Login
class Admin_Form_Login extends Zend_Form
Call your form from a controller file from within the same module
$form = new Admin_Form_Login();
Simple and effective! ;)
I'm following the tutorial on setting up WURFL with Zend Framework to enable easy mobile browser detection.
http://framework.zend.com/manual/en/zend.http.user-agent.html#zend.http.user-agent.quick-start
I have got it setup to the point where it can detect a desktop browser and give me all the details and features of that browser, but when I try to access the website using an iPhone (mobile safari) it throws an error when trying to write to the cache directory.
Here's what I'm seeing in my error logs:
2011-06-08T22:32:34-07:00 ERR (3): The file cache directory does not exist and could not be created. Please make sure the cache directory is writeable: /var/tmp
However in my configuration at /application/configs/wurfl-config.php I have set the cache directory to the following:
<?php
$resourcesDir = dirname(__FILE__) . '/../../data/wurfl/';
$wurfl['main-file'] = $resourcesDir . 'wurfl-2.0.27.zip';
$wurfl['patches'] = array($resourcesDir . 'web_browsers_patch.xml');
$persistence['provider'] = 'file';
$persistence['dir'] = $resourcesDir . '/cache/';
$cache['provider'] = null;
$configuration['wurfl'] = $wurfl;
$configuration['persistence'] = $persistence;
$configuration['cache'] = $cache;
I've also ensured it is writable by the server, but wurfl seems to think my cache directory is still /var/tmp
How can I get wurfl to observe my cache directory setting?
Notes: The tutorial uses wurfl-1.1 as the example, I have only been able to find wurfl-1.3 on sourceforge. This may be an issue.
Notes: I have these lines in my application.ini file:
; WURFL
resources.useragent.wurflapi.wurfl_api_version = "1.1"
resources.useragent.wurflapi.wurfl_lib_dir = APPLICATION_PATH "/../library/wurfl-php-1.3.0/WURFL/"
resources.useragent.wurflapi.wurfl_config_file = APPLICATION_PATH "/configs/wurfl-config.php"
Not sure if this is the correct way to fix it, but for me the issue was solved by adding an extra .dir after the persistence.dir key (using WURFL 1.3.0):
In application.ini: (I don't use the php config file as I prefer not to mix in php code if I can use .ini directives)
resources.useragent.wurflapi.wurfl_config_array.persistence.dir.dir = APPLICATION_PATH "/../data/wurfl/cache/"
So my complete config for WURFL looks like this in Zend's application.ini:
; Mobile device detection
resources.useragent.storage.adapter = "Session"
resources.useragent.wurflapi.wurfl_api_version = "1.1"
resources.useragent.wurflapi.wurfl_lib_dir = APPLICATION_PATH "/../library/WURFL/"
resources.useragent.wurflapi.wurfl_config_array.wurfl.main-file = APPLICATION_PATH "/../data/wurfl/wurfl.xml"
resources.useragent.wurflapi.wurfl_config_array.wurfl.patches[] = APPLICATION_PATH "/../data/wurfl/web_browsers_patch.xml"
resources.useragent.wurflapi.wurfl_config_array.persistence.provider = "file"
resources.useragent.wurflapi.wurfl_config_array.persistence.dir.dir = APPLICATION_PATH "/../data/wurfl/cache/"
perhaps a bug in the framework regarding how it reads the config array it's being passed?
I just resolved the problem ;)
remove the [] from the code line below:
resources.useragent.wurflapi.wurfl_config_array.wurfl.patches[] = APPLICATION_PATH "/../data/wurfl/web_browsers_patch.xml"
transform it to:
resources.useragent.wurflapi.wurfl_config_array.wurfl.patches = APPLICATION_PATH "/../data/wurfl/web_browsers_patch.xml"
It seems the format of the parameters has changed in version 1.3 - the WURFL docs here have the details and an example file.
So for the original question, the $persistence['dir'] line needs to be changed to:
$persistence['params'] = array(
'dir' => $resourcesDir . '/cache/'
);
I solved the problem using Wurfl 1.3.1 and reading this:
http://wurfl.sourceforge.net/nphp/
With regards to Jens Wegar's answer above, there is a bug-fix request in to fix this as it's not clear.
http://framework.zend.com/issues/browse/ZF-12284
Did you configure the UserAgent resource to use the settings you are showing here?
You have to add resource.useragent.wurfl_* entries into your application.ini file.
Here is a sample:
resources.useragent.wurflapi.wurfl_api_version = "1.1"
resources.useragent.wurflapi.wurfl_lib_dir = APPLICATION_PATH "/../library/WURFL/"
resources.useragent.wurflapi.wurfl_config_file = APPLICATION_PATH "/configs/wurfl-config.php"
Still struggling to get doctrine working properly on my system. I have a yaml file that describes the structure of my database and tables. (I am following the tutorial on zendcast). I have my doctrine script file as
#!/usr/bin/env php
<?php
chdir(dirname(__FILE__));
include('doctrine.php');
and the doctrine.php file contains
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/..'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->getBootstrap()->bootstrap('doctrine');
$config = $application->getOption('doctrine');
$cli = new Doctrine_Cli($config);
$cli->run($_SERVER['argv']);
My application.ini excerpt is
autoloaderNamespaces[] = "Doctrine_"
;--
;Database
;--
doctrine.dsn = "mysql://root:softna#localhost/gepm2"
doctrine.data_fixtures_path = APPLICATION_PATH "/configs/data/fixtures"
doctrine.sql_path = APPLICATION_PATH "/configs/data/sql"
doctrine.migrations_path = APPLICATION_PATH "/configs/migrations"
doctrine.yaml_schema_path = APPLICATION_PATH "/configs/schema.yml"
doctrine.models_path = APPLICATION_PATH "/../library/Gepm/Model"
When I run:
D:\www\gepm2\application\scripts>php doctrine build-all-reload
I get the ff feedback:
D:\www\gepm2\application\scripts>php doctrine build-all-reload
build-all-reload - Are you sure you wish to drop your databases? (y/n) y
build-all-reload - Successfully dropped database for connection named 'doctrine'
build-all-reload - Successfully created database for connection named 'doctrine'
build-all-reload - Created tables successfully
build-all-reload - Data was successfully loaded
However when I check mysql only the database is created no tables are generated. I have struggled with this for a whole day. Someone help.
EDIT
All right I got it working now.But to be honest with you the only changes I made to the code was to
1. set the time zone,
2. remove the underscore from the end of the utoloaderNamespaces[] value so utoloaderNamespaces[] = "Doctrine_" became autoloaderNamespaces[] = "Doctrine" and
3. move the doctrine database declarations to the bottom of the [production] section in the applications.ini
I am so far behind on schedule with what I am working on that I cannot mess about with these changes to see which one or why it worked. I will do say later when I have some down time. In the meantime a more knowledgeable geek may be able to explain why it may have worked. cheers.
The way doctrine creates tables in the db is by loading the models and reading the definitions within each of these models. If the CLI is not able to load the models then the table creation will fail. Unfortunately the CLI task does not report this.
Further I would advise you to check other CLI tasks such as generate-migrations-diff and migrate. I have had issues with these in the past and have resolved them successfully.