views:

40

answers:

2

Let's say I have a controller template with a before function like so...

public function before()
  {
     parent::before();
     if ($this->request === Request::instance()) 
     {
         // its a main request, throw an exception or redirect
         Request::instance()->redirect('/');
     }
     else
     {
        // ok
     }
  }

But let's say I don't want to redirect, I want to stop the Request flow, and do nothing.

Does an exception do this? Is there a simple way, like Request::die();?

EDIT:: I actually don't want to halt the Request flow, just prevent this controller from doing anything. It's likely that this controller was called from another controller, and I want to pass the control back to the calling controller.'

Thanks!

A: 

You can set a class variable in before() say:

$this->execute = false;

Then in your action:

public function action_example()
{
    if (!$this->execute) return;
    // etc
}
Zahymaka
A: 

1.Use exceptions (not tested yet):

try
(
   Request->instance()->execute();
}
catch (MyRequest_Exception $e)
{
   // do what you want
}

echo Request->instance()->send_headers->response();

// somewhere in before()
if ($error)
{
   throw new MyRequest_Exception($errortext);
}

2.Change action name.

biakaveron
Right now, I'm just calling a fake action, but I want to use exceptions, so I'm picking this. If I find it doesn't work, I'll come back and update this.
brennanag