Tuesday, March 20, 2012

Re: How do I redirect?

class TestsController extends AppController {   public function index()   {   }    public function change()   {     $this->redirect(array('controller' => 'tests', 'action' => 'index'));   } }


then create the file /View/Tests/index.ctp containing "in the index" or whatever output you like.

open http://host/tests/
to see if it shows what's in your index.ctp file (if not, then this is your problem, not the redirection).

if index works, now open http://host/tests/change/ and it will redirect you.

On Tuesday, March 20, 2012 3:41:51 AM UTC+2, glevine wrote:
@thatsgreat2345 That was just a typo.

Commenting out the print statements in the change method has no effect. I never see the "in the index" print statement and the browser simply shows a blank page with a couple of warnings about changing the salt and cipherSeed. The url in the location bar remains http://www.example.com/tests/change.

On Monday, March 19, 2012 3:53:44 PM UTC-4, thatsgreat2345 wrote:
Your problem is you are redirecting to test controller when in fact you should be redirecting to tests controller.
$this->redirect(array('controller' => 'tests', 'action' => 'index'));


On Monday, March 19, 2012 7:56:09 AM UTC-7, glevine wrote:
Right, so in the example I was mainly just wanting to show that I was reaching those points in the code. Theoretically, if I remove the "print 'before redirect';" statement then I should never see "after redirect" but I should see "in the index" upon the new page load (since that is post redirect).

For some reason, I was still unable to redirect when I wasn't printing to the screen before the call to exit. However, I may have just been tired and didn't realize I still had a print before exit. So I'll try again and respond back with the results.

Thanks

On Monday, March 19, 2012 7:56:28 AM UTC-4, euromark wrote:
no you can't! or: you really shoudn't
you should simply do everything before redirecting.

theoretically, you can manually call exit() if you set the exit param to false on redirect.
but to me this makes no sense.


>> can we do some process after redirect.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: