ok ... it still exists. And it's not that easy to test.
---------------------------
Exlpaination:
Almost all of my action have multiple contexts belonging to what the user want to do with the 'data'. I have e.g. html, json, xml, pdf and one for another 'normal' view: dashboard, so that I can react on the context in dthe controller and use different views to present the data.
Now I use the inflector in my extend of the Zend_Controller_Action to inflect the viewScrtipt target to organize my view files in subfolders.
The problem now is exactly the dashboard.
In this view multiple actions will be processed by the action helper with the context dashboard, so the function will called each time a action helper runs and one time for the dashboard view itself.
1. call is ok (context == '')
2. call is ok (context == 'dashboard' )
3. call is not ok (context == 'dashboard' ) => FATAL
this is my work around:
Unable to find source-code formatter for language: php. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
[...]
/**
* Inflector target
* @var string
*/
protected $_inflectorTarget = ':controller/:context:action.:suffix';
[...]
/**
* sets the inflector for the viewRenderer in context mode
* and give the view the context
* @return void
*/
protected function setContextInflector() {
$currentContext = $this->getContext();
$inflector = $this->_helper->getHelper('viewRenderer')->getInflector();
$this->_context = ( $currentContext == '' || $currentContext == 'html' ) ? '' : $this->getContext(). '/';
if ($inflector->getRules('context') == false) {
$inflector
->addFilterRule(':context' ,array('Word_CamelCaseToDash', 'StringToLower'));
}
$inflector
->setStaticRuleReference('suffix' , $this->_viewSuffix)
->setStaticRuleReference('context' , $this->_context)
->setTargetReference($this->_inflectorTarget)
;
$this->view->currentContext = $currentContext;
}
[...]
and so it does not work:
Unable to find source-code formatter for language: php. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
[...]
/**
* Inflector target
* @var string
*/
protected $_inflectorTarget = ':controller/:context:action.:suffix';
[...]
/**
* sets the inflector for the viewRenderer in context mode
* and give the view the context
* @return void
*/
protected function setContextInflector() {
$currentContext = $this->getContext();
$inflector = $this->_helper->getHelper('viewRenderer')->getInflector();
$this->_context = ( $currentContext == '' || $currentContext == 'html' ) ? '' : $this->getContext(). '/';
if ($inflector->getRules('context') == false) {
$inflector
;
}
$inflector
->addFilterRule(':context' ,array('Word_CamelCaseToDash', 'StringToLower'))
->setStaticRuleReference('suffix' , $this->_viewSuffix)
->setStaticRuleReference('context' , $this->_context)
->setTargetReference($this->_inflectorTarget)
;
$this->view->currentContext = $currentContext;
}
[...]
Dont hesitate to contact me if you need more informations.
Could solve that by checking if the Rule is set already, but solves not the problem, that "$this->_rules[$spec]" is a string not an array, second time.
if ($inflector->getRules('context') == false) { $inflector ->addFilterRule(':context' ,array('Word_CamelCaseToDash', 'StringToLower')); } $inflector ->setStaticRuleReference('suffix' , $this->_viewSuffix) ->setStaticRuleReference('context' , $this->_context) ->setTargetReference($this->_inflectorTarget) ;if ($inflector->getRules('context') == false) { $inflector ->addFilterRule(':context' ,array('Word_CamelCaseToDash', 'StringToLower')); } $inflector ->setStaticRuleReference('suffix' , $this->_viewSuffix) ->setStaticRuleReference('context' , $this->_context) ->setTargetReference($this->_inflectorTarget) ;