Callbacks with ContextSwitch Action Helper

View: New views
3 Messages — Rating Filter:   Alert me  

Callbacks with ContextSwitch Action Helper

by Hector Virgen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

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!

-Hector

Re: Callbacks with ContextSwitch Action Helper

by Matthew Weier O'Phinney-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-- Hector Virgen <djvirgen@...> 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).

--
Matthew Weier O'Phinney
Software Architect       | matthew@...
Zend Framework           | http://framework.zend.com/

Re: Callbacks with ContextSwitch Action Helper

by Hector Virgen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@... 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).

  
LightInTheBox - Buy quality products at wholesale price