2008年7月21日星期一

Re: [fw-mvc] Callbacks with ContextSwitch Action Helper

Thanks, Matthew.

I apologize, an exception *will* be thrown if unable to call the callback, but I was looking at a cached version of the page :(

-Hector

Matthew Weier O'Phinney wrote:
-- Hector Virgen <djvirgen@gmail.com> wrote (on Monday, 21 July 2008, 09:44 AM -0700):   
Can someone please show me an example of how to use callbacks with the ContextSwitch action helper? I have read the documentation at http:// framework.zend.com/manual/en/zend.controller.actionhelpers.html# zend.controller.actionhelpers.contextswitch.custom but there are no examples.  I have specified bogus callbacks in my $spec array hoping to throw a descriptive exception but none was thrown. Here is my test code:      // From within an action controller     public function init()     {         $contextSwitch = $this->_helper->getHelper('contextSwitch');                 $context = 'text';         $spec = array(             'suffix'        => 'text',             'headers'       => array(                 'Content-type' => 'text/plain'             ),             'callbacks'     => array(                 'init'          => 'testinit'                 'post'          => 'testpost'             )         );                 $contextSwitch->addContext($context, $spec);         $contextSwitch->addActionContext('view', 'text')                       ->initContext();     }  If the above code looks correct, where should I be defining my callbacks? Are they global functions, or methods of the current action controller, or methods of the ContextSwitch helper? Thanks!     
 Here's how it looks for them:    * If the callback is a string and is a method in the ContextSwitch     class (or the class you're extending it with), that will be called.    * If the callback is a string and is an existing function, that will     be called.    * If the callback is an array, then the array will be passed to     call_user_func() (the array should contain two members, the class or     object, and the method to call).    

没有评论: