I'm a function, CakePHP and OOPHP noob so please be patient with me ;)
I have a 301 redirect script I use in the view function of the controllers to compare the slug in the url to the slug in the db and if they don't match 301 redirect to the url with the right slug
I'm trying to turn it into custom functions but I haven't had much success...
This is the code:
$pieces = explode('__', $this->params['pass'][0]);
if (!isset($pieces[2])) {
if ($pieces[1] != $this->Smartphone->field('slug')) {
$this->redirect(array('action' => 'view', $this->Smartphone->field('id').'__'.$this->Smartphone->field('slug')));
}
}
My guess is a function would look something like:
public function 301redirect($model) {
$pieces = explode('__', $this->params['pass'][0]);
if (!isset($pieces[2])) {
if ($pieces[1] != $this->Smartphone->field('slug')) {
$this->redirect(array('action' => 'view', $this->$model->field('id').'__'.$this->$model->field('slug')));
}
}
}
Can you guys tell me what I should put where to get this function to work?
Thnx!