Re: redirection, rendering, or manually setting a view?
On 10 mayo, 00:13, soytuny [EMAIL PROTECTED] wrote: You can render the home view with $this-render('../pages/home'); IMO that's a bad habit that shouldn't be propogated - the unwary may think it's an equivalent to using requestAction and will start doing $this-render('../products/index'); wondering why there are lots of errors on the page. A better idea would be to simply redirect - if for whatever reason you don't want the url to change you could do something like the following: //controller code $this-set('requestUrl','/pages/home'); $this-viewPath = _generic; // - making cake look in the folder / app/views/_generic $this-render('pseudo_redirect'); // /app/views/_generic/pseudo_redirect.thtml ?php echo $this-requestAction($requestUrl,array('return'); ? But again: it would be simpler to just redirect. hth, AD --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: redirection, rendering, or manually setting a view?
Nice, that makes a lot of sense. Since I'm writing the error message to the session anyway, there is no reason to not forward. I switched my code to: $this-Session-setFlash('Validation failed.'); $this-redirect('../pages/home'); exit(); 2007/5/10, AD7six [EMAIL PROTECTED]: On 10 mayo, 00:13, soytuny [EMAIL PROTECTED] wrote: You can render the home view with $this-render('../pages/home'); IMO that's a bad habit that shouldn't be propogated - the unwary may think it's an equivalent to using requestAction and will start doing $this-render('../products/index'); wondering why there are lots of errors on the page. A better idea would be to simply redirect - if for whatever reason you don't want the url to change you could do something like the following: //controller code $this-set('requestUrl','/pages/home'); $this-viewPath = _generic; // - making cake look in the folder / app/views/_generic $this-render('pseudo_redirect'); // /app/views/_generic/pseudo_redirect.thtml ?php echo $this-requestAction($requestUrl,array('return'); ? But again: it would be simpler to just redirect. hth, AD --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: redirection, rendering, or manually setting a view?
You can render the home view with $this-render('../pages/home'); If you would like to set an error message and redirect you can use $this-Session-setFlash('You ain't no user!'); To display the flash message, you need this line in your layout (or view) if($session-check('Message.flash')) $session-flash(); HTH, Russell Austin On May 9, 2:23 pm, Greg Cerveny [EMAIL PROTECTED] wrote: Hello, I've created my default home page (/views/pages/home.thmtl) to include a login form for my application. This works fine, but if the login fails, I am unsure how to handle it. I would like to send the user back to the front page and display an appropriate error message. Here is my existing logic (mostly from the tutorial): function login() { $this-set('error', false); if (!empty($this-data)) { $someone = $this-User-findByUsername($this-data['User']['username']); if(!empty($someone['User']['password']) $someone['User']['password'] == md5($this-data['User']['password'])) { $this-Session-write('User', $someone['User']); $this-redirect('/ideas'); } else { $this-redirect('/'); } } } So, in the else statement... Should (Can?) I tell the controller to display the home.thtml view? Should I redirect with a url param of the error message? Should I render an action? Thanks! -greg --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: redirection, rendering, or manually setting a view?
Nice. I'm looking good :) Thanks a lot! 2007/5/9, soytuny [EMAIL PROTECTED]: You can render the home view with $this-render('../pages/home'); If you would like to set an error message and redirect you can use $this-Session-setFlash('You ain't no user!'); To display the flash message, you need this line in your layout (or view) if($session-check('Message.flash')) $session-flash(); HTH, Russell Austin On May 9, 2:23 pm, Greg Cerveny [EMAIL PROTECTED] wrote: Hello, I've created my default home page (/views/pages/home.thmtl) to include a login form for my application. This works fine, but if the login fails, I am unsure how to handle it. I would like to send the user back to the front page and display an appropriate error message. Here is my existing logic (mostly from the tutorial): function login() { $this-set('error', false); if (!empty($this-data)) { $someone = $this-User-findByUsername($this-data['User']['username']); if(!empty($someone['User']['password']) $someone['User']['password'] == md5($this-data['User']['password'])) { $this-Session-write('User', $someone['User']); $this-redirect('/ideas'); } else { $this-redirect('/'); } } } So, in the else statement... Should (Can?) I tell the controller to display the home.thtml view? Should I redirect with a url param of the error message? Should I render an action? Thanks! -greg --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---