Zendcasts Forum

A community of developers who work with the Zend Framework and other enterprise PHP technologies

You are not logged in.

#1 2010-08-01 22:11:48

iiTyr
Member
Registered: 2010-03-27
Posts: 13

Front Controller Plugins & Exceptions

Hi all,

In my application i have a Front Controller Plugin which is build to check wether the visitor has access to the requested page with use of Zend_Acl.

Now when the user is not allowed on a page i would like to throw an Exception (the best thing to do i figured).

Now the problem here is that my error page (Error Action in Error Controller) isnt being rendered properly.

It feels a little as if the layout starts to render...then the exception is thrown, then it starts to Render the entire error page (including the layout again).

Extra Info.
-Exceptions thrown in Controllers are working as intended.
-I have tried using PreDispatch() instead of dispatchLoopStartup, it had no effect

Here is the code that checks if the user is allowed somewhere and if not throw the exception

public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)    
    {
        $this->role = $this->getRole($request);
        $this->resource = strtolower($request->getControllerName() . '-'
                                     . $request->getActionName());     

          if(!$this->acl->isAllowed($this->role, $this->resource))
          {
              throw new Exception(My_Acl_Acl::NOT_ALLOWED, 404);
          }        
    }

Offline

#2 2010-08-10 08:21:43

Jon Lebensold
Administrator
Registered: 2009-06-27
Posts: 279

Re: Front Controller Plugins & Exceptions

Hi iiTyr,

is dispatchLoopStartup being called a second time? Waht does you errorController look like?

Best,
-
Jon

Offline

#3 2010-08-10 21:03:58

iiTyr
Member
Registered: 2010-03-27
Posts: 13

Re: Front Controller Plugins & Exceptions

The Error Controller is just a default out of the box ErrorController

As for the calling of dispatchLoopStartup, this only seems to happen once

This only seems to happen when the exception is thrown...

I did some more trying, and it seems like the ErrorController Renders the layout normaly, untill just before it is going to render the phtml file for the error action...

Then it renders the entire requested page (so from Doctype till </html> (which wasnt supposed to be seen by the visitor) and then continues on with the error.phtml and finished the layout normaly.

Offline

#4 2010-08-10 21:16:45

iiTyr
Member
Registered: 2010-03-27
Posts: 13

Re: Front Controller Plugins & Exceptions

And Nevermind...

I added the following code to the top of my errorAction inside of my ErrorController, which cleared out any body content rendered prior to the error occuring...

$this->getResponse()->clearBody();

Offline

Board footer

Powered by FluxBB