How to finish the request nicely?

720 views
Skip to first unread message

kimjxie

unread,
Feb 25, 2013, 3:56:35 AM2/25/13
to pha...@googlegroups.com

Greetings!

I have a problem when using phalcon.
In initialize method of a controller , I do something like checking data, then deal with the left job, or send a redirect by controller->response->redirect method if something goes wrong.
But the dispatcher still run with the request at begin and output the page. 
Although I could add a controller->forward('empty/action/do_nothing') after redirect method , but if there a nice way to finish the request immediately ?





Igor Ivanovic

unread,
Feb 25, 2013, 4:02:19 AM2/25/13
to pha...@googlegroups.com
$this->request->redirect('empty/action/do_nothing')
Will redirect you to your action.

$this->dispatcher->forward('empty/action/do_nothing');
This will forward you to your action without redirection
> --
> You received this message because you are subscribed to the Google Groups
> "Phalcon PHP Framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to phalcon+u...@googlegroups.com.
> To post to this group, send email to pha...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/phalcon/-/YvKUKJMyzY8J.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

kimjxie

unread,
Feb 25, 2013, 5:08:44 AM2/25/13
to pha...@googlegroups.com
Yes, I know that.
For example, I want like this in a controller:
$this->response->redirect('redirect/http_header_302');
$this->dispatcher->finish_request(); // This method told the dispatcher: don't do anything but send out the response content immediately. 

But I can't find a method like finish_request, so I'm using like:
$this->response->redirect('redirect/http_header_302');
$this->dispatcher->forward('empty/action/do_nothing');  // avoid any output except http redirect header.

Денис Давыдов

unread,
Feb 25, 2013, 5:13:19 AM2/25/13
to pha...@googlegroups.com
Use:
return $this->response->redirect('redirect/http_header_302');

понедельник, 25 февраля 2013 г., 14:08:44 UTC+4 пользователь kimjxie написал:

kimjxie

unread,
Feb 25, 2013, 5:35:06 AM2/25/13
to pha...@googlegroups.com
sorry for not emphasizing the point:
    I use $this->response->redirect in initialize metod of a controller, 

May be the question is clearer by asking as : How to finish the dispatcher and response immediately in \Phalcon\Mvc\Controller::initialize method, or I should not do like this?

Igor Ivanovic

unread,
Feb 25, 2013, 5:38:28 AM2/25/13
to pha...@googlegroups.com
You can stop rendering like this:
$this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_NO_RENDER);
> https://groups.google.com/d/msg/phalcon/-/TY5XjL-QWkQJ.

Igor Ivanovic

unread,
Feb 25, 2013, 5:39:24 AM2/25/13
to pha...@googlegroups.com
this->response->redirect must be in action

Igor Ivanovic

unread,
Feb 25, 2013, 5:41:05 AM2/25/13
to pha...@googlegroups.com
you can use also:

public function beforeExecuteRoute($dispatcher)
{
$this->response->redirect

kimjxie

unread,
Feb 25, 2013, 12:24:37 PM2/25/13
to pha...@googlegroups.com
According to your post, I found more details about dispatcher.
I used the redirect method at wrong place.  beforeExecuteRoute is nice.
Thank you very much.   :-)

在 2013年2月25日星期一UTC+8下午6时41分05秒,Igor Ivanovic写道:
Reply all
Reply to author
Forward
0 new messages