webdev - Zend Framework Tutorials
Thanks for joining me in the third installment of this tutorial series on Zend_Application. In this tutorial we are going to create your .ini file and configure it to function correctly with your application.
Zend_Application comes with a lot of ready to use Resource plugins. The objective here is to use the resource plugins and keep your bootstrap relatively clean. It is actually advisable to create your own resource plugins customized for your application, but for now we'll use the defualt ones shipped with Zend_Application.
The relevant documentation I'd really like you to read:
create and/or edit application/config/config.ini
First we are going to simply create our relevant sections in the config file.
[production]
[development : testing]
[development : production]
Zend_Application provides the base functionality of the component, and the entry point to your Zend Framework application. It's purpose is two-fold: to setup the PHP environment (including autoloading), and to execute your application bootstrap. Typically, you will pass all configuration to the Zend_Application constructor, but you can also configure the object entirely using its own methods.
As you can see, we have our basic configuration in place. The Application is still not fully functional. We have a few more things to take care of.
[production]
;error reporting
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
;set timezone
phpsettings.date.timezone = "America/Chicago"
;include path
includePaths.library = APPLICATION_PATH "/../library"
;bootstrap
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
;autoloadernamespaces
autoloadernamespaces.0 = "App_"
autoloadernamespaces.1 = "Zend_"
autoloadernamespaces.2 = "ZendX_"
[development : testing]
;error reporting
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
;error reporting
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
Now we need to tell our configuration file about our front controllers, and for it to throw exceptions. Lets edit the above file to look like the following: (the difference is empasized via bold.)
[production]
;error reporting
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
;set timezone
phpsettings.date.timezone = "America/Chicago"
;include path
includePaths.library = APPLICATION_PATH "/../library"
;bootstrap
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
;autoloadernamespaces
autoloadernamespaces.0 = "App_"
autoloadernamespaces.1 = "Zend_"
autoloadernamespaces.2 = "ZendX_"
;resources.frontController
resources.frontController.env = APPLICATION_ENV
resources.frontController.throwerrors = false
[development : testing]
;error reporting
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
;resources.frontController
resources.frontController.throwerrors = true
[development : production]
;error reporting
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
;resources.frontController
resources.frontController.throwerrors = true
Alright, for now, we're done with the testing and the development sections. Basically what we did was tell our frontcontroller resource (which is already registered via Zend_Applicatin's Bootstrap) to throw exceptions only if the APPLICATION_ENV is set to testing or development, which you should set in your .htaccess file.
What we want to do now, is to let our front controller resource know that we want to use modules. If you recall from the pre 1.8 days, we had to use the following methods to accomplish this. This hasn't changed, you can specify these settings via a php array(), or with the ini file. Let's use the ini file.
public static function setupFrontController()
{
self::$frontController->setControllerDirectory(
array(
'default' => self::$root . '/application/controllers',
'admin' => self::$root . '/application/admin/controllers'
)
);
}
Which is specified like this, but this isn't really neccessery as the setModuleDirectory() method should be used instead.
resources.frontController.controllerDirectory.default = MODULE_PATH "/default/controllers"
resources.frontController.controllerDirectory.admin = MODULE_PATH "/admin/controllers"
public static function setupFrontController()
{
self::$frontController->setModuleDirectory('application/modules/');
}
Which is then specified like this.
resources.frontController.moduleDirectory = MODULE_PATH
Lets go ahead and seup our entire Front Controller using the .ini file.
[production]
;resources.frontController
resources.frontController.moduleDirectory = MODULE_PATH
resources.frontController.moduleControllerDirectoryName = "controllers"
resources.frontController.plugins.moduleswitcher = "App_Controller_Plugin_ModuleSwitcher"
resources.frontController.env = APPLICATION_ENV
resources.frontController.throwerrors = false
resources.frontController.defaultModule = "default"
resources.frontController.defaultAction = "index"
resources.frontController.defaultControllerName = "index
The bits in BOLD are very important. Now we must register our front controller plugin. Following PEAR paths, you can load any number of plugins this way.
Now we can setup our Database Resource.
;resources.database
resources.db.params.adapter = PDO_MYSQL
resources.db.isdefaulttableadapter = true
resources.db.params.host =
resources.db.params.username =
resources.db.params.password =
resources.db.params.dbname =
And you can even have module specific resources, for example:
;resources.database.default
default.resources.db.params.adapter = PDO_MYSQL
default.resources.db.isdefaulttableadapter = true
default.resources.db.params.host =
default.resources.db.params.username =
default.resources.db.params.password =
default.resources.db.params.dbname =
;resources.database.admin
admin.resources.db.params.adapter = PDO_MYSQL
admin.resources.db.isdefaulttableadapter = true
admin.resources.db.params.host =
admin.resources.db.params.username =
admin.resources.db.params.password =
admin.resources.db.params.dbname =
Lets go ahead and setup our Locale.
;resources.locale
resources.locale.default = en_US
Now your application should be running. Our final config should look like the following, given you didn't customize it too heavily.
[production]
;error reporting
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
;set timezone
phpsettings.date.timezone = "America/Chicago"
;include path
includePaths.library = APPLICATION_PATH "/../library"
;bootstrap
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
;autoloader
autoloadernamespaces.0 = "App_"
autoloadernamespaces.1 = "Zend_"
autoloadernamespaces.2 = "ZendX_"
;resources.frontController
resources.frontController.moduleDirectory = MODULE_PATH
resources.frontController.moduleControllerDirectoryName = "controllers"
resources.frontController.plugins.moduleswitcher = "App_Controller_Plugin_ModuleSwitcher"
resources.frontController.env = APPLICATION_ENV
resources.frontController.throwerrors = false
resources.frontController.defaultModule = "default"
resources.frontController.defaultAction = "index"
resources.frontController.defaultControllerName = "index"
;resources misc
resources.locale.default = en_US
;resources.database
resources.db.params.adapter = PDO_MYSQL
resources.db.isdefaulttableadapter = true
resources.db.params.host =
resources.db.params.username =
resources.db.params.password =
resources.db.params.dbname =
[testing : production]
;error reporting
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
;resources.frontController
resources.frontcontroller.throwerrors = true
[development : production]
;error reporting
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
;resources.frontController
resources.frontcontroller.throwerrors = true
Now our application should be 100% functional. Go ahead, load it up in the browser. If you have configured everything correctly you should be able to see http://localhost/sample/public/index.php/default/index (to be precise) and in general http://localhost/sample/public/ would call the default module, as thats the one we setup as our default. Go ahead and now go to http://localhost/sample/public/index.php/admin/index and you will see the admin layout and index controller identify themselves to you.
I am feeling really tired right now. I have typed up enough for now. Try to get your heads around this. If you have any questions, you can contact me here via comments or on irc.freenode.net #zftalk| < Prev | Next > |
|---|
My Twitter
- feed:
- follow:
- bio:C.E.O Frosted Web, Social Media Marketing & Development | C.T.O. Sky Social Media Inc, former Debian contributor, maintainer and developer. Currently w/FreeBSD.
- web:
- location:Baton Rouge, LA. USA
- updates:389
- followers:136
- following:15
Last 0 tweets in past 30 days from atirjavid:
People talking about '@Linux':




















