handle any exception with errorController

classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|

handle any exception with errorController

waigani-2
Is it possible? I want to throw an exception in the preDispatch of a plugin if you are not allowed to view the page. I then want to handle that exception via the errorController. I can wrap the $front->dispatch() in a try / catch and catch the exception in the bootstrap, but then how do I forward that onto the errorController, as the front controller has not been dispatched? I've read the manual and other posts and have not found an answer nor an alternative method.
Reply | Threaded
Open this post in threaded view
|

Re: handle any exception with errorController

jasonistaken
Waigani wrote:
> Is it possible? I want to throw an exception in the preDispatch of a plugin
> if you are not allowed to view the page. I then want to handle that
> exception via the errorController. I can wrap the $front->dispatch() in a
> try / catch and catch the exception in the bootstrap, but then how do I
> forward that onto the errorController, as the front controller has not been
> dispatched? I've read the manual and other posts and have not found an
> answer nor an alternative method.
>  
I think you may be misunderstanding the dispatching process of the front
controller. Here's a run down:

    1.  Request/Response/Router/Dispatcher initialization
    2.  routeStartup()
        * call plugins registered with this hook
    3.  Routing
        * Updates Request object based on matched information from
          routing
    4.  routeShutdown()
        * call plugins registered with this hook
    5.  dispatchLoopStartup()
        * call plugins registered with this hook
        6.  preDispatch()
            * call plugins registered with this hook
        7.  Dispatch action
            8.  action helper preDispatch()
            9.  action controller preDispatch()
            10. action method
                * UNLESS a _forward() or redirect has occurred
            11. action controller postDispatch()
            12. action helper postDispatch()
        13. postDispatch()
            * call plugins registered with this hook
        /* repeat 6 - 13 as necessary */
    14. dispatchLoopShutdown()
        * call plugins registered with this hook
    15. send response

The preDispatch hooks of action helpers and action controllers ad re
steps 8 and 9, respectively. The ErrorHandler front controller plugin is
registered basically right away.

In short, if you throw an exception in the preDispatch of a
controller/action it _will_ be caught by the ErrorHandler plugin, and
thus forwarded to the error controller.
Reply | Threaded
Open this post in threaded view
|

Re: handle any exception with errorController

waigani-2
Thanks for the run down. Is it possible to throw an error in a plugin though? So far the errorController has missed it.


Jason Webster wrote
Waigani wrote:
> Is it possible? I want to throw an exception in the preDispatch of a plugin
> if you are not allowed to view the page. I then want to handle that
> exception via the errorController. I can wrap the $front->dispatch() in a
> try / catch and catch the exception in the bootstrap, but then how do I
> forward that onto the errorController, as the front controller has not been
> dispatched? I've read the manual and other posts and have not found an
> answer nor an alternative method.
>  
I think you may be misunderstanding the dispatching process of the front
controller. Here's a run down:

    1.  Request/Response/Router/Dispatcher initialization
    2.  routeStartup()
        * call plugins registered with this hook
    3.  Routing
        * Updates Request object based on matched information from
          routing
    4.  routeShutdown()
        * call plugins registered with this hook
    5.  dispatchLoopStartup()
        * call plugins registered with this hook
        6.  preDispatch()
            * call plugins registered with this hook
        7.  Dispatch action
            8.  action helper preDispatch()
            9.  action controller preDispatch()
            10. action method
                * UNLESS a _forward() or redirect has occurred
            11. action controller postDispatch()
            12. action helper postDispatch()
        13. postDispatch()
            * call plugins registered with this hook
        /* repeat 6 - 13 as necessary */
    14. dispatchLoopShutdown()
        * call plugins registered with this hook
    15. send response

The preDispatch hooks of action helpers and action controllers ad re
steps 8 and 9, respectively. The ErrorHandler front controller plugin is
registered basically right away.

In short, if you throw an exception in the preDispatch of a
controller/action it _will_ be caught by the ErrorHandler plugin, and
thus forwarded to the error controller.
Reply | Threaded
Open this post in threaded view
|

Re: handle any exception with errorController

jasonistaken
The Plugin Broker (Zend_Controller_Plugin_Broker) _should_ catch any
exceptions thrown by controller plugins. Well, not should, it does.
Perhaps this is an issue with how you're instantiating your plugins??

Waigani wrote:

> Thanks for the run down. Is it possible to throw an error in a plugin though?
> So far the errorController has missed it.
>
>
>
> Jason Webster wrote:
>  
>> Waigani wrote:
>>    
>>> Is it possible? I want to throw an exception in the preDispatch of a
>>> plugin
>>> if you are not allowed to view the page. I then want to handle that
>>> exception via the errorController. I can wrap the $front->dispatch() in a
>>> try / catch and catch the exception in the bootstrap, but then how do I
>>> forward that onto the errorController, as the front controller has not
>>> been
>>> dispatched? I've read the manual and other posts and have not found an
>>> answer nor an alternative method.
>>>  
>>>      
>> I think you may be misunderstanding the dispatching process of the front
>> controller. Here's a run down:
>>
>>     1.  Request/Response/Router/Dispatcher initialization
>>     2.  routeStartup()
>>         * call plugins registered with this hook
>>     3.  Routing
>>         * Updates Request object based on matched information from
>>           routing
>>     4.  routeShutdown()
>>         * call plugins registered with this hook
>>     5.  dispatchLoopStartup()
>>         * call plugins registered with this hook
>>         6.  preDispatch()
>>             * call plugins registered with this hook
>>         7.  Dispatch action
>>             8.  action helper preDispatch()
>>             9.  action controller preDispatch()
>>             10. action method
>>                 * UNLESS a _forward() or redirect has occurred
>>             11. action controller postDispatch()
>>             12. action helper postDispatch()
>>         13. postDispatch()
>>             * call plugins registered with this hook
>>         /* repeat 6 - 13 as necessary */
>>     14. dispatchLoopShutdown()
>>         * call plugins registered with this hook
>>     15. send response
>>
>> The preDispatch hooks of action helpers and action controllers ad re
>> steps 8 and 9, respectively. The ErrorHandler front controller plugin is
>> registered basically right away.
>>
>> In short, if you throw an exception in the preDispatch of a
>> controller/action it _will_ be caught by the ErrorHandler plugin, and
>> thus forwarded to the error controller.
>>
>>
>>    
>
>  

Reply | Threaded
Open this post in threaded view
|

Re: handle any exception with errorController

waigani-2
The code

throw new Zend_Exception('test');

in the predispatch hook of a plugin returns

Fatal error: Uncaught exception 'Zend_Exception' with message 'test'  …

I am registering my plugins via $frontController->registerPlugin() method.

Is this not the expected behaviour?


Jason Webster wrote
The Plugin Broker (Zend_Controller_Plugin_Broker) _should_ catch any
exceptions thrown by controller plugins. Well, not should, it does.
Perhaps this is an issue with how you're instantiating your plugins??

Waigani wrote:
> Thanks for the run down. Is it possible to throw an error in a plugin though?
> So far the errorController has missed it.
>
>
>
> Jason Webster wrote:
>  
>> Waigani wrote:
>>    
>>> Is it possible? I want to throw an exception in the preDispatch of a
>>> plugin
>>> if you are not allowed to view the page. I then want to handle that
>>> exception via the errorController. I can wrap the $front->dispatch() in a
>>> try / catch and catch the exception in the bootstrap, but then how do I
>>> forward that onto the errorController, as the front controller has not
>>> been
>>> dispatched? I've read the manual and other posts and have not found an
>>> answer nor an alternative method.
>>>  
>>>      
>> I think you may be misunderstanding the dispatching process of the front
>> controller. Here's a run down:
>>
>>     1.  Request/Response/Router/Dispatcher initialization
>>     2.  routeStartup()
>>         * call plugins registered with this hook
>>     3.  Routing
>>         * Updates Request object based on matched information from
>>           routing
>>     4.  routeShutdown()
>>         * call plugins registered with this hook
>>     5.  dispatchLoopStartup()
>>         * call plugins registered with this hook
>>         6.  preDispatch()
>>             * call plugins registered with this hook
>>         7.  Dispatch action
>>             8.  action helper preDispatch()
>>             9.  action controller preDispatch()
>>             10. action method
>>                 * UNLESS a _forward() or redirect has occurred
>>             11. action controller postDispatch()
>>             12. action helper postDispatch()
>>         13. postDispatch()
>>             * call plugins registered with this hook
>>         /* repeat 6 - 13 as necessary */
>>     14. dispatchLoopShutdown()
>>         * call plugins registered with this hook
>>     15. send response
>>
>> The preDispatch hooks of action helpers and action controllers ad re
>> steps 8 and 9, respectively. The ErrorHandler front controller plugin is
>> registered basically right away.
>>
>> In short, if you throw an exception in the preDispatch of a
>> controller/action it _will_ be caught by the ErrorHandler plugin, and
>> thus forwarded to the error controller.
>>
>>
>>    
>
>  
Reply | Threaded
Open this post in threaded view
|

Re: handle any exception with errorController

waigani-2
throw exceptions is not on and I've also tested the dispatchLoopStartup in the plugins broker. It is not catching the exception.


Waigani wrote
The code

throw new Zend_Exception('test');

in the predispatch hook of a plugin returns

Fatal error: Uncaught exception 'Zend_Exception' with message 'test'  …

I am registering my plugins via $frontController->registerPlugin() method.

Is this not the expected behaviour?


Jason Webster wrote
The Plugin Broker (Zend_Controller_Plugin_Broker) _should_ catch any
exceptions thrown by controller plugins. Well, not should, it does.
Perhaps this is an issue with how you're instantiating your plugins??

Waigani wrote:
> Thanks for the run down. Is it possible to throw an error in a plugin though?
> So far the errorController has missed it.
>
>
>
> Jason Webster wrote:
>  
>> Waigani wrote:
>>    
>>> Is it possible? I want to throw an exception in the preDispatch of a
>>> plugin
>>> if you are not allowed to view the page. I then want to handle that
>>> exception via the errorController. I can wrap the $front->dispatch() in a
>>> try / catch and catch the exception in the bootstrap, but then how do I
>>> forward that onto the errorController, as the front controller has not
>>> been
>>> dispatched? I've read the manual and other posts and have not found an
>>> answer nor an alternative method.
>>>  
>>>      
>> I think you may be misunderstanding the dispatching process of the front
>> controller. Here's a run down:
>>
>>     1.  Request/Response/Router/Dispatcher initialization
>>     2.  routeStartup()
>>         * call plugins registered with this hook
>>     3.  Routing
>>         * Updates Request object based on matched information from
>>           routing
>>     4.  routeShutdown()
>>         * call plugins registered with this hook
>>     5.  dispatchLoopStartup()
>>         * call plugins registered with this hook
>>         6.  preDispatch()
>>             * call plugins registered with this hook
>>         7.  Dispatch action
>>             8.  action helper preDispatch()
>>             9.  action controller preDispatch()
>>             10. action method
>>                 * UNLESS a _forward() or redirect has occurred
>>             11. action controller postDispatch()
>>             12. action helper postDispatch()
>>         13. postDispatch()
>>             * call plugins registered with this hook
>>         /* repeat 6 - 13 as necessary */
>>     14. dispatchLoopShutdown()
>>         * call plugins registered with this hook
>>     15. send response
>>
>> The preDispatch hooks of action helpers and action controllers ad re
>> steps 8 and 9, respectively. The ErrorHandler front controller plugin is
>> registered basically right away.
>>
>> In short, if you throw an exception in the preDispatch of a
>> controller/action it _will_ be caught by the ErrorHandler plugin, and
>> thus forwarded to the error controller.
>>
>>
>>    
>
>  
Reply | Threaded
Open this post in threaded view
|

Re: handle any exception with errorController

waigani-2
correction, it is catching the exception when thrown from dispatchLoopStartup from my plugin, but not whe it is thrown from preDispatch. Is this the expected behaviour?


Waigani wrote
throw exceptions is not on and I've also tested the dispatchLoopStartup in the plugins broker. It is not catching the exception.


Waigani wrote
The code

throw new Zend_Exception('test');

in the predispatch hook of a plugin returns

Fatal error: Uncaught exception 'Zend_Exception' with message 'test'  …

I am registering my plugins via $frontController->registerPlugin() method.

Is this not the expected behaviour?


Jason Webster wrote
The Plugin Broker (Zend_Controller_Plugin_Broker) _should_ catch any
exceptions thrown by controller plugins. Well, not should, it does.
Perhaps this is an issue with how you're instantiating your plugins??

Waigani wrote:
> Thanks for the run down. Is it possible to throw an error in a plugin though?
> So far the errorController has missed it.
>
>
>
> Jason Webster wrote:
>  
>> Waigani wrote:
>>    
>>> Is it possible? I want to throw an exception in the preDispatch of a
>>> plugin
>>> if you are not allowed to view the page. I then want to handle that
>>> exception via the errorController. I can wrap the $front->dispatch() in a
>>> try / catch and catch the exception in the bootstrap, but then how do I
>>> forward that onto the errorController, as the front controller has not
>>> been
>>> dispatched? I've read the manual and other posts and have not found an
>>> answer nor an alternative method.
>>>  
>>>      
>> I think you may be misunderstanding the dispatching process of the front
>> controller. Here's a run down:
>>
>>     1.  Request/Response/Router/Dispatcher initialization
>>     2.  routeStartup()
>>         * call plugins registered with this hook
>>     3.  Routing
>>         * Updates Request object based on matched information from
>>           routing
>>     4.  routeShutdown()
>>         * call plugins registered with this hook
>>     5.  dispatchLoopStartup()
>>         * call plugins registered with this hook
>>         6.  preDispatch()
>>             * call plugins registered with this hook
>>         7.  Dispatch action
>>             8.  action helper preDispatch()
>>             9.  action controller preDispatch()
>>             10. action method
>>                 * UNLESS a _forward() or redirect has occurred
>>             11. action controller postDispatch()
>>             12. action helper postDispatch()
>>         13. postDispatch()
>>             * call plugins registered with this hook
>>         /* repeat 6 - 13 as necessary */
>>     14. dispatchLoopShutdown()
>>         * call plugins registered with this hook
>>     15. send response
>>
>> The preDispatch hooks of action helpers and action controllers ad re
>> steps 8 and 9, respectively. The ErrorHandler front controller plugin is
>> registered basically right away.
>>
>> In short, if you throw an exception in the preDispatch of a
>> controller/action it _will_ be caught by the ErrorHandler plugin, and
>> thus forwarded to the error controller.
>>
>>
>>    
>
>  
Reply | Threaded
Open this post in threaded view
|

Re: handle any exception with errorController

waigani-2
When I throw an exception from dispatchLoopStartup I get the following output:
___
Application Error
this is index view

This is error view

The following error occurred:
exception 'Zend_Exception' with message 'test'
___

So its catching the exception but both the index action from the index controller and error action from the error controller are called, both views are rendered also. This is all looking very similar to the following logged bug (marked as resolved): http://framework.zend.com/issues/browse/ZF-2461



Waigani wrote
correction, it is catching the exception when thrown from dispatchLoopStartup from my plugin, but not whe it is thrown from preDispatch. Is this the expected behaviour?


Waigani wrote
throw exceptions is not on and I've also tested the dispatchLoopStartup in the plugins broker. It is not catching the exception.


Waigani wrote
The code

throw new Zend_Exception('test');

in the predispatch hook of a plugin returns

Fatal error: Uncaught exception 'Zend_Exception' with message 'test'  …

I am registering my plugins via $frontController->registerPlugin() method.

Is this not the expected behaviour?


Jason Webster wrote
The Plugin Broker (Zend_Controller_Plugin_Broker) _should_ catch any
exceptions thrown by controller plugins. Well, not should, it does.
Perhaps this is an issue with how you're instantiating your plugins??

Waigani wrote:
> Thanks for the run down. Is it possible to throw an error in a plugin though?
> So far the errorController has missed it.
>
>
>
> Jason Webster wrote:
>  
>> Waigani wrote:
>>    
>>> Is it possible? I want to throw an exception in the preDispatch of a
>>> plugin
>>> if you are not allowed to view the page. I then want to handle that
>>> exception via the errorController. I can wrap the $front->dispatch() in a
>>> try / catch and catch the exception in the bootstrap, but then how do I
>>> forward that onto the errorController, as the front controller has not
>>> been
>>> dispatched? I've read the manual and other posts and have not found an
>>> answer nor an alternative method.
>>>  
>>>      
>> I think you may be misunderstanding the dispatching process of the front
>> controller. Here's a run down:
>>
>>     1.  Request/Response/Router/Dispatcher initialization
>>     2.  routeStartup()
>>         * call plugins registered with this hook
>>     3.  Routing
>>         * Updates Request object based on matched information from
>>           routing
>>     4.  routeShutdown()
>>         * call plugins registered with this hook
>>     5.  dispatchLoopStartup()
>>         * call plugins registered with this hook
>>         6.  preDispatch()
>>             * call plugins registered with this hook
>>         7.  Dispatch action
>>             8.  action helper preDispatch()
>>             9.  action controller preDispatch()
>>             10. action method
>>                 * UNLESS a _forward() or redirect has occurred
>>             11. action controller postDispatch()
>>             12. action helper postDispatch()
>>         13. postDispatch()
>>             * call plugins registered with this hook
>>         /* repeat 6 - 13 as necessary */
>>     14. dispatchLoopShutdown()
>>         * call plugins registered with this hook
>>     15. send response
>>
>> The preDispatch hooks of action helpers and action controllers ad re
>> steps 8 and 9, respectively. The ErrorHandler front controller plugin is
>> registered basically right away.
>>
>> In short, if you throw an exception in the preDispatch of a
>> controller/action it _will_ be caught by the ErrorHandler plugin, and
>> thus forwarded to the error controller.
>>
>>
>>    
>
>  
Reply | Threaded
Open this post in threaded view
|

Re: handle any exception with errorController

weierophinney
Administrator
In reply to this post by waigani-2
-- Waigani <[hidden email]> wrote
(on Monday, 03 November 2008, 09:59 PM -0800):
> Is it possible? I want to throw an exception in the preDispatch of a plugin
> if you are not allowed to view the page. I then want to handle that
> exception via the errorController. I can wrap the $front->dispatch() in a
> try / catch and catch the exception in the bootstrap, but then how do I
> forward that onto the errorController, as the front controller has not been
> dispatched? I've read the manual and other posts and have not found an
> answer nor an alternative method.

Currently, throwing exceptions in plugins is unhandled, and you must
handle them manually, as you are attempting to do.

Probably the easiest way to re-dispatch in this case is to simply set an
error message in the session, and then redirect to an error page where
you display that message.

We *have* noted this issue for a future Zend_Controller improvement.

--
Matthew Weier O'Phinney
Software Architect       | [hidden email]
Zend Framework           | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|

Re: handle any exception with errorController

keith Pope-4
Would adding an exception to the Response work though?

2008/11/4 Matthew Weier O'Phinney <[hidden email]>:

> -- Waigani <[hidden email]> wrote
> (on Monday, 03 November 2008, 09:59 PM -0800):
>> Is it possible? I want to throw an exception in the preDispatch of a plugin
>> if you are not allowed to view the page. I then want to handle that
>> exception via the errorController. I can wrap the $front->dispatch() in a
>> try / catch and catch the exception in the bootstrap, but then how do I
>> forward that onto the errorController, as the front controller has not been
>> dispatched? I've read the manual and other posts and have not found an
>> answer nor an alternative method.
>
> Currently, throwing exceptions in plugins is unhandled, and you must
> handle them manually, as you are attempting to do.
>
> Probably the easiest way to re-dispatch in this case is to simply set an
> error message in the session, and then redirect to an error page where
> you display that message.
>
> We *have* noted this issue for a future Zend_Controller improvement.
>
> --
> Matthew Weier O'Phinney
> Software Architect       | [hidden email]
> Zend Framework           | http://framework.zend.com/
>



--
----------------------------------------------------------------------
[MuTe]
----------------------------------------------------------------------
Reply | Threaded
Open this post in threaded view
|

Filter Digits on Zend_Form

Bagus Nugroho-2
In reply to this post by weierophinney
Re: [fw-general] handle any exception with errorController
Hi All,
I'm trying using 'Digits' filter on Zend_Form like this :
======
class My_Form_Project_Test extends Zend_Form{
 public function __construct($options = null){
  parent::__construct($options);
  
  $update = new Zend_Form_Element_Text('test');
  $update->setLabel('Test')
      ->addFilter('Digits');
     
     
  $submit = new Zend_Form_Element_Submit('submit');
  $submit->setLabel('Submit');
     
     
  $this->addElements(array($update, $submit));
 }
}
 
then, when input '1000asdf', I'm expecting get '1000' but the code above give me '1000asdf' instead of '1000' as expected.
Is any wrong with my code above.
..
 
thanks in advance, bn
Reply | Threaded
Open this post in threaded view
|

Re: Filter Digits on Zend_Form

weierophinney
Administrator
-- Bagus Nugroho <[hidden email]> wrote
(on Tuesday, 04 November 2008, 10:18 PM +0700):

> I'm trying using 'Digits' filter on Zend_Form like this :
> ======
> class My_Form_Project_Test extends Zend_Form{
>  public function __construct($options = null){
>   parent::__construct($options);
>  
>   $update = new Zend_Form_Element_Text('test');
>   $update->setLabel('Test')
>       ->addFilter('Digits');
>      
>      
>   $submit = new Zend_Form_Element_Submit('submit');
>   $submit->setLabel('Submit');
>      
>      
>   $this->addElements(array($update, $submit));
>  }
> }
>  
> then, when input '1000asdf', I'm expecting get '1000' but the code above give
> me '1000asdf' instead of '1000' as expected.
> Is any wrong with my code above.

How are you retrieving the element value?

--
Matthew Weier O'Phinney
Software Architect       | [hidden email]
Zend Framework           | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|

Re: handle any exception with errorController

jasonistaken
In reply to this post by weierophinney
Huh? I really don't understand. Matthew, could you please elaborate?

The preDispatch method of the Plugin Broker has a try/catch block that
should grab anything, and send it to the request object? no?


Matthew Weier O'Phinney wrote:

> -- Waigani <[hidden email]> wrote
> (on Monday, 03 November 2008, 09:59 PM -0800):
>  
>> Is it possible? I want to throw an exception in the preDispatch of a plugin
>> if you are not allowed to view the page. I then want to handle that
>> exception via the errorController. I can wrap the $front->dispatch() in a
>> try / catch and catch the exception in the bootstrap, but then how do I
>> forward that onto the errorController, as the front controller has not been
>> dispatched? I've read the manual and other posts and have not found an
>> answer nor an alternative method.
>>    
>
> Currently, throwing exceptions in plugins is unhandled, and you must
> handle them manually, as you are attempting to do.
>
> Probably the easiest way to re-dispatch in this case is to simply set an
> error message in the session, and then redirect to an error page where
> you display that message.
>
> We *have* noted this issue for a future Zend_Controller improvement.
>
>  

Reply | Threaded
Open this post in threaded view
|

Re: handle any exception with errorController

weierophinney
Administrator
-- Jason Webster <[hidden email]> wrote
(on Tuesday, 04 November 2008, 08:26 AM -0800):
> Huh? I really don't understand. Matthew, could you please elaborate?
>
> The preDispatch method of the Plugin Broker has a try/catch block that  
> should grab anything, and send it to the request object? no?

Oh, never mind. I forgot that Ralph added that for 1.6.

The problem now is one of making sure that on preDispatch(), we forward
to the ErrorController if an exception is present in the response. Can
you open an issue for that, please?


> Matthew Weier O'Phinney wrote:
>> -- Waigani <[hidden email]> wrote
>> (on Monday, 03 November 2008, 09:59 PM -0800):
>>  
>>> Is it possible? I want to throw an exception in the preDispatch of a plugin
>>> if you are not allowed to view the page. I then want to handle that
>>> exception via the errorController. I can wrap the $front->dispatch() in a
>>> try / catch and catch the exception in the bootstrap, but then how do I
>>> forward that onto the errorController, as the front controller has not been
>>> dispatched? I've read the manual and other posts and have not found an
>>> answer nor an alternative method.
>>>    
>>
>> Currently, throwing exceptions in plugins is unhandled, and you must
>> handle them manually, as you are attempting to do.
>>
>> Probably the easiest way to re-dispatch in this case is to simply set an
>> error message in the session, and then redirect to an error page where
>> you display that message.
>>
>> We *have* noted this issue for a future Zend_Controller improvement.
>>
>>  
>

--
Matthew Weier O'Phinney
Software Architect       | [hidden email]
Zend Framework           | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|

Re: handle any exception with errorController

waigani-2
In reply to this post by keith Pope-4
Yeah, I'm trying that:

$this->getResponse()->setException(new Zend_Exception("test"));

It does get handled in dispatchLoopStartup by the error controller, but orginal action also gets called as well as the error action (and you get two views rendered - orginal and error). When I throw an exception in a plugin, I want to stop everything and just handle that exception in the error controller.


keith Pope-4 wrote
Would adding an exception to the Response work though?

2008/11/4 Matthew Weier O'Phinney <matthew@zend.com>:
> -- Waigani <jesse.meek@otago.ac.nz> wrote
> (on Monday, 03 November 2008, 09:59 PM -0800):
>> Is it possible? I want to throw an exception in the preDispatch of a plugin
>> if you are not allowed to view the page. I then want to handle that
>> exception via the errorController. I can wrap the $front->dispatch() in a
>> try / catch and catch the exception in the bootstrap, but then how do I
>> forward that onto the errorController, as the front controller has not been
>> dispatched? I've read the manual and other posts and have not found an
>> answer nor an alternative method.
>
> Currently, throwing exceptions in plugins is unhandled, and you must
> handle them manually, as you are attempting to do.
>
> Probably the easiest way to re-dispatch in this case is to simply set an
> error message in the session, and then redirect to an error page where
> you display that message.
>
> We *have* noted this issue for a future Zend_Controller improvement.
>
> --
> Matthew Weier O'Phinney
> Software Architect       | matthew@zend.com
> Zend Framework           | http://framework.zend.com/
>



--
----------------------------------------------------------------------
[MuTe]
----------------------------------------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: handle any exception with errorController

jasonistaken
You can manually clear the response body.

$response->clearBody()

I think I'll file a ticket and start work on improving the Exception
handling with regards to plugins.

Waigani wrote:

> Yeah, I'm trying that:
>
> $this->getResponse()->setException(new Zend_Exception("test"));
>
> It does get handled in dispatchLoopStartup by the error controller, but
> orginal action also gets called as well as the error action (and you get two
> views rendered - orginal and error). When I throw an exception in a plugin,
> I want to stop everything and just handle that exception in the error
> controller.
>
>
>
> keith Pope-4 wrote:
>  
>> Would adding an exception to the Response work though?
>>
>> 2008/11/4 Matthew Weier O'Phinney <[hidden email]>:
>>    
>>> -- Waigani <[hidden email]> wrote
>>> (on Monday, 03 November 2008, 09:59 PM -0800):
>>>      
>>>> Is it possible? I want to throw an exception in the preDispatch of a
>>>> plugin
>>>> if you are not allowed to view the page. I then want to handle that
>>>> exception via the errorController. I can wrap the $front->dispatch() in
>>>> a
>>>> try / catch and catch the exception in the bootstrap, but then how do I
>>>> forward that onto the errorController, as the front controller has not
>>>> been
>>>> dispatched? I've read the manual and other posts and have not found an
>>>> answer nor an alternative method.
>>>>        
>>> Currently, throwing exceptions in plugins is unhandled, and you must
>>> handle them manually, as you are attempting to do.
>>>
>>> Probably the easiest way to re-dispatch in this case is to simply set an
>>> error message in the session, and then redirect to an error page where
>>> you display that message.
>>>
>>> We *have* noted this issue for a future Zend_Controller improvement.
>>>
>>> --
>>> Matthew Weier O'Phinney
>>> Software Architect       | [hidden email]
>>> Zend Framework           | http://framework.zend.com/
>>>
>>>      
>>
>> --
>> ----------------------------------------------------------------------
>> [MuTe]
>> ----------------------------------------------------------------------
>>
>>
>>    
>
>  

Reply | Threaded
Open this post in threaded view
|

RE: Filter Digits on Zend_Form

Bagus Nugroho-2
In reply to this post by weierophinney
Re: [fw-general] Filter Digits on Zend_Form
I'm key in '1000asdf' on input text.
Like this one :
================
 public function testAction(){
  $form = new My_Form_Project_Test();
  
  if($this->_request->isPost()){
       print_r($this->_request->getPost());
  }else{
      echo $form;
  }
 }
 
and the output like this :
    Array ( [test] => 1000asdf [submit] => Submit )
 
=====
 
Thanks, bn


From: Matthew Weier O'Phinney [mailto:[hidden email]]
Sent: Sel 04-Nop-2008 23:06
To: [hidden email]
Subject: Re: [fw-general] Filter Digits on Zend_Form

-- Bagus Nugroho <[hidden email]> wrote
(on Tuesday, 04 November 2008, 10:18 PM +0700):


> I'm trying using 'Digits' filter on Zend_Form like this :
> ======
> class My_Form_Project_Test extends Zend_Form{
>  public function __construct($options = null){
>   parent::__construct($options);
>  
>   $update = new Zend_Form_Element_Text('test');
>   $update->setLabel('Test')
>       ->addFilter('Digits');
>     
>     
>   $submit = new Zend_Form_Element_Submit('submit');
>   $submit->setLabel('Submit');
>     
>     
>   $this->addElements(array($update, $submit));
>  }
> }

> then, when input '1000asdf', I'm expecting get '1000' but the code above give
> me '1000asdf' instead of '1000' as expected.
> Is any wrong with my code above.

How are you retrieving the element value?

--
Matthew Weier O'Phinney
Software Architect       | [hidden email]
Zend Framework           | http://framework.zend.com/

Reply | Threaded
Open this post in threaded view
|

Re: Filter Digits on Zend_Form

weierophinney
Administrator
-- Bagus Nugroho <[hidden email]> wrote
(on Wednesday, 05 November 2008, 06:40 PM +0700):

> I'm key in '1000asdf' on input text.
> Like this one :
> ================
>  public function testAction(){
>   $form = new My_Form_Project_Test();
>  
>   if($this->_request->isPost()){
>        print_r($this->_request->getPost());
>   }else{
>       echo $form;
>   }
>  }
>  
> and the output like this :
>     Array ( [test] => 1000asdf [submit] => Submit )

Well, you need to pass the data to the form's or element's isValid()
method -- it doesn't get automagically validated or filtered for you.
You need to do the following:

    $request = $this->getRequest();
    if ($request->isPost() && $form->isValid($request->getPost())) {
        print_r($form->getValues());
    } else {
        echo $form;
    }

(It's better to do that echoing in the view script, though -- the above
is just for demonstration purposes.)


> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> From: Matthew Weier O'Phinney [mailto:[hidden email]]
> Sent: Sel 04-Nop-2008 23:06
> To: [hidden email]
> Subject: Re: [fw-general] Filter Digits on Zend_Form
>
>
> -- Bagus Nugroho <[hidden email]> wrote
> (on Tuesday, 04 November 2008, 10:18 PM +0700):
> > I'm trying using 'Digits' filter on Zend_Form like this :
> > ======
> > class My_Form_Project_Test extends Zend_Form{
> >  public function __construct($options = null){
> >   parent::__construct($options);
> >  
> >   $update = new Zend_Form_Element_Text('test');
> >   $update->setLabel('Test')
> >       ->addFilter('Digits');
> >    
> >    
> >   $submit = new Zend_Form_Element_Submit('submit');
> >   $submit->setLabel('Submit');
> >    
> >    
> >   $this->addElements(array($update, $submit));
> >  }
> > }
> >
> > then, when input '1000asdf', I'm expecting get '1000' but the code above give
> > me '1000asdf' instead of '1000' as expected.
> > Is any wrong with my code above.
>
> How are you retrieving the element value?
>
> --
> Matthew Weier O'Phinney
> Software Architect       | [hidden email]
> Zend Framework           | http://framework.zend.com/
>
>

--
Matthew Weier O'Phinney
Software Architect       | [hidden email]
Zend Framework           | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|

RE: Filter Digits on Zend_Form

Bagus Nugroho-2
Re: [fw-general] Filter Digits on Zend_Form
Ok, thank you
 
Rgds, bn


From: Matthew Weier O'Phinney [mailto:[hidden email]]
Sent: Rabu 05-Nop-2008 20:22
To: [hidden email]
Subject: Re: [fw-general] Filter Digits on Zend_Form

-- Bagus Nugroho <[hidden email]> wrote
(on Wednesday, 05 November 2008, 06:40 PM +0700):


> I'm key in '1000asdf' on input text.
> Like this one :
> ================
>  public function testAction(){
>   $form = new My_Form_Project_Test();
>  
>   if($this->_request->isPost()){
>        print_r($this->_request->getPost());
>   }else{
>       echo $form;
>   }
>  }

> and the output like this :
>     Array ( [test] => 1000asdf [submit] => Submit )

Well, you need to pass the data to the form's or element's isValid()
method -- it doesn't get automagically validated or filtered for you.
You need to do the following:

    $request = $this->getRequest();
    if ($request->isPost() && $form->isValid($request->getPost())) {
        print_r($form->getValues());
    } else {
        echo $form;
    }

(It's better to do that echoing in the view script, though -- the above
is just for demonstration purposes.)


> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> From: Matthew Weier O'Phinney [[hidden email]]
> Sent: Sel 04-Nop-2008 23:06
> To: [hidden email]
> Subject: Re: [fw-general] Filter Digits on Zend_Form
>
>
> -- Bagus Nugroho <[hidden email]> wrote
> (on Tuesday, 04 November 2008, 10:18 PM +0700):
> > I'm trying using 'Digits' filter on Zend_Form like this :
> > ======
> > class My_Form_Project_Test extends Zend_Form{
> >  public function __construct($options = null){
> >   parent::__construct($options);
> > 
> >   $update = new Zend_Form_Element_Text('test');
> >   $update->setLabel('Test')
> >       ->addFilter('Digits');
> >    
> >    
> >   $submit = new Zend_Form_Element_Submit('submit');
> >   $submit->setLabel('Submit');
> >    
> >    
> >   $this->addElements(array($update, $submit));
> >  }
> > }
> >
> > then, when input '1000asdf', I'm expecting get '1000' but the code above give
> > me '1000asdf' instead of '1000' as expected.
> > Is any wrong with my code above.
>
> How are you retrieving the element value?
>
> --
> Matthew Weier O'Phinney
> Software Architect       | [hidden email]
> Zend Framework           | http://framework.zend.com/
>
>

--
Matthew Weier O'Phinney
Software Architect       | [hidden email]
Zend Framework           | http://framework.zend.com/

Reply | Threaded
Open this post in threaded view
|

"Multi-div" tags on Zend Form

Bagus Nugroho-2
In reply to this post by weierophinney
Re: [fw-general] Filter Digits on Zend_Form
Hi All,
I'm found interested autocomplete(based jQuery) like this :
===========================================
<form>
    <div><input type="text" ......></div>
    <div class="class1" id="id1">
      <img src="...">  
      <div class="class2" id="id2">
         &nbsp;
      </div>
  </div>
</form>
===========================================
Is possible convert this code into Zend_Form?
I'm still trying to understand how decorators work, Matthew article very helpfull but I have no idea how can build "multi-divs" within Zend_Form as the code above.
 
 
Thanks in advance, again
bn