I found my problem. It was two problems really.

The first problem was that $post was not set in the controller. The
second problem was a misplaced parentheses in the redirect function.
The third problem was I was creating urls that were hyphenated but
forgot to add the second parameter to the Inflector::slug() function
so that it was looping around never getting a match.

On Jan 18, 2:30 pm, john lyles <confidentia...@gmail.com> wrote:
> Ok sorry. Here's a more full explanation:
>
> In my index.ctp I have links that look like this: <?php echo 
> $this->Html->link($post['Post']['title'], array('controller' => 'posts',
>
> 'action' => 'view', $post['Post']['id'],Inflector::slug($post['Post']
> ['title'], '-'))); ?>
>
> Then in the PostsController view() method, this is what it looks like:
>
> function view($id = null) {
>                 if (!$id) {
>                         $this->Session->setFlash(__('Invalid post', true));
>                         $this->redirect(array('action' => 'index'));
>                 }
>
>                 $post = $this->set('post', $this->Post->read(null, $id));
>                 $this->theme = 'jonlyles';
>
>               if(Inflector::slug($post['Post']['title']) != 
> $this->params['pass'][1] || count($this->params['pass']) != 2 ) {
>
> $post = $this->Post->read(null, $id);
>               $this->redirect(array($id, Inflector::slug($post['Post']
> ['title']), 301));
>                }
>         }
>
> If I remove the last if condition there are no errors, but then no
> protection against bad urls either.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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 For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to