Monday, March 19, 2012

Re: How do I redirect?

First off, change your core configuration so you aren't using the default salt and cipherSeed (this can be found in your apps core.php file in the Config folder), that is if this app matters which it seems like it is just a practice app but still good practice.
It appears your routes(app Config folder, routes.php) are set so that when you visit your tests index it will direct you towards the default home page that is set in the cake core.
I recommend modifying this, so that when people visit your index (/) it is routed to the controller and action of your choice. Which in this case seems to be tests controller and action index.
The line of code will look like this
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Modify it to
Router::connect('/', array('controller' => 'tests', 'action' => 'index');
For the record, it is not recommended to use print when debugging, if you just want to do browser debugging use cakes debug function. You can use it anywhere, and it accepts any type of variable and will output it cleanly.

On Monday, March 19, 2012 6:41:51 PM UTC-7, 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: