Re: How to set a variable inside an extended Cake Class
Write below router in route.php Router::connect('/cms_pages/:action/*', array('controller' => 'cms_pages', 'action' => 'view'), array( 'routeClass' => 'SluggableRoute', 'your_variable_name' => array('your_variable_value') )); Write below code in a file in app/libs/Sluggable_route .php class SluggableRoute extends CakeRoute { function parse($url) { $params = parent::parse($url); if (empty($params)) { return false; } if (isset($this->options['your_variable_name']) && isset($params['_args_'])) { // Do something } } } -- Thanks & Regards Chetan Patel -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
Re: How to set a variable inside an extended Cake Class
CakeRoute doesn't talk to View. You can set params to be passed to the controller, though. For example (in parse method): $params = parent::parse($url); ... $slugs = array_flip(Set::extract("/Page/slug_${params['lang']}", $data)); if (isset($slugs[$params['slug']])) { $params['pass'][] = $params['slug']; return $params; } On Wed, Aug 29, 2012 at 3:50 PM, Leonhart wrote: > Hi guys > I'm stuck on a new problem these hours... I've just coded an extended > CakeRoute and I need to set some variables. Unfortunately, the $this->set() > function can't be used as it points to the extended CakeRoute class. How can > I set a variable inside the parse() function for showing it inside the view? > > I really thank all of you for your suggests. > Leonhart > > -- > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com. > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com. > Visit this group at http://groups.google.com/group/cake-php?hl=en-US. > > -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
How to set a variable inside an extended Cake Class
Hi guys I'm stuck on a new problem these hours... I've just coded an extended CakeRoute and I need to set some variables. Unfortunately, the $this->set() function can't be used as it points to the extended CakeRoute class. How can I set a variable inside the parse() function for showing it inside the view? I really thank all of you for your suggests. Leonhart -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en-US.