sensimevanidus

22 July, 2010

Change Default Controller in Zend Framework

By default, Zend Framework dispatches a request to the IndexController if no other controller is defined (modules, controllers and actions are selected via URL). Like me, you may want to change the default controller for some reason. In Zend Framework, you can do that by adding or changing the resources.frontController.defaultControllerName property in the application.ini file. It looks like this:

resources.frontController.defaultControllerName = "auth"

Now Zend Framework sees the AuthController as the default controller.

That’s all. Hope this helps…

sensimevanidus

20 July, 2010

Fetching Configuration Data from Action Controllers in Zend Framework

If you’re familiar with Zend Framework, you probably know what an application-specific configuration file is. I tend to use application.ini file (located under the /application/configs directory) to store my application’s configuration data and generally use these variables in the bootstrap file.

Today, I needed to reach smtp configuration values from within a controller and it took some time to figure out how to do that although it was simple as this:

$mailOptions = $this->getInvokeArg('bootstrap')->getOption('mail');

This code snippet fetches these mail configuration data; 

mail.transport.smtp.host = "<some_host_value>"
mail.transport.smtp.port = "<some_port_value>"
mail.transport.smtp.user = "<some_user_value>"
mail.transport.smtp.pass = "<some_pass_value>"

from the application.ini file as a PHP array:

array(1) {
["transport"]=>
array(1) {
["smtp"]=>
array(4) {
["host"]=>
string(19) "<some_host_value>"
["port"]=>
string(3) "<some_port_value>"
["user"]=>
string(19) "<some_user_value>"
["pass"]=>
string(7) "<some_pass_value>"
}
}
}

You can also fetch all configuration data via:

$options = $this->getInvokeArg('bootstrap')->getOptions();

That’s all! Hope that helps…