Here a few of those "how did that work again" things, in Zend framework. Mostly for myself but hey, I'm not greedy. If you know some new/nifty ones, feel free to leave a comment!
Overriding the default view script for your controller method:
public function myactionAction() {
$this->_helper->viewRenderer->setScriptAction('alternateView');
}
Preventing automatic view rendering:
public function myactionAction() {
$this->_helper->viewRenderer->setNoRender( true );
}
Preventing any output:
public function myactionAction() {
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender( true );
}
Enabling plugin caching
// Enable plugin cachingif ($registry->configuration->enablePluginLoaderCache ==
true) { $pluginLoaderCacheFile = APPLICATION_PATH .
'/cache/pluginLoaderCache.php';
if (is_readable($pluginLoaderCacheFile)) { include $pluginLoaderCacheFile;
} Zend_Loader_PluginLoader::
setIncludeFileCache($pluginLoaderCacheFile);
} Being tidy
// throw warnings when using uninitialized view variablesZend_Layout::
getMvcInstance()->getView
()->strictVars
( true );
// Strict session handlingZend_Session::
setOptions(array('strict' =>
true));
Zend_Session::
start();
$myPunkSession =
new Zend_Session_Namespace
('Punk');
Forwarding to another controller method
This might seem fairly obvious, but it took me a while to figure this out. Simply because I was looking in the wrong direction, or at least not in the 'forward' direction. Also, this method calls the init() method of the controller also. So after a forward, init() get's called N+1 times.
public function __call($name, $argv) {
/** do stuff **/
// Forward to the other controller, not via redirects.
$this->_forward('controller_name');
}
Ini config and arrays
When you want to define an array kind of structure in your ini config directive. You'll soon notice that it aint gonna happen. However you can solve it like this:
/**
* Ini:
* valid.indices.0 = "A index"
* valid.indices.1 = "Another index"
* valid.indices.2 = "fubar"
**/$indices = Zend_Registry::
get('configuration')->valid->indices->toArray
();
if (in_array($input,
$indices,
true)) { // Valid $input} else { // Invalid $input} Constants in the ini config
Concatenating in ini files is a bit different, the following results in: /path/to/app/application/default/temp/sessions.
session.save_path = APPLICATION_PATH"default/temp/sessions"