Routing first parameter in URL to an action

2010-03-01 Thread jbov
I have set up a blog using URL slugs. Say my domain is darn.it and the
title for my first post is I lost my shoe. My blog posts are
displaying at darn.it/posts/i-lost-my-shoe. Easy as pie, er, cake.

I want to route it so the first parameter in the url is the slug. So
darn.it/i-lost-my-shoe would map to controller = posts, action =
view. Below is my routing, but I'm missing something because it's not
passing the slug to the view method properly. Or maybe it's not
calling the view method. Any advice?

Router::connect(
 '/:slug',
 array('controller' = 'posts', 'action' = 'view'),
 array('slug' = '^[a-zA-Z0-9_]{1,}$')
);

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


Re: Routing first parameter in URL to an action

2010-03-01 Thread Lucca Mordente
if its not calling the view method, try to add  \- to your regex as
follows:

 '^[a-zA-Z0-9_\-]{1,}$'


else if the parameter just isn't being passed, add the 'pass' option
to route:

Router::connect(
 '/:slug',
 array('controller' = 'posts', 'action' = 'view'),
 array('slug' = '^[a-zA-Z0-9_]{1,}$', 'pass'=array('slug'))
);


hope it helps (:


On 1 mar, 12:39, jbov jonathan.li...@gmail.com wrote:
 I have set up a blog using URL slugs. Say my domain is darn.it and the
 title for my first post is I lost my shoe. My blog posts are
 displaying at darn.it/posts/i-lost-my-shoe. Easy as pie, er, cake.

 I want to route it so the first parameter in the url is the slug. So
 darn.it/i-lost-my-shoe would map to controller = posts, action =
 view. Below is my routing, but I'm missing something because it's not
 passing the slug to the view method properly. Or maybe it's not
 calling the view method. Any advice?

 Router::connect(
      '/:slug',
      array('controller' = 'posts', 'action' = 'view'),
      array('slug' = '^[a-zA-Z0-9_]{1,}$')
 );

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


Re: Routing first parameter in URL to an action

2010-03-01 Thread jbov
No dice :-(

Here's my view method:

function view($slug) {
$post = $this-Post-findBySlug($slug);
$postTitle = $post['Post']['title'];
$this-set(array(
'post'=$post,
'pageheader'=$postTitle
));
}

Anything I'm missing?




On Mar 1, 5:55 pm, Lucca Mordente luccamorde...@gmail.com wrote:
 if its not calling the view method, try to add  \- to your regex as
 follows:

  '^[a-zA-Z0-9_\-]{1,}$'

 else if the parameter just isn't being passed, add the 'pass' option
 to route:

 Router::connect(
      '/:slug',
      array('controller' = 'posts', 'action' = 'view'),
      array('slug' = '^[a-zA-Z0-9_]{1,}$', 'pass'=array('slug'))
 );

 hope it helps (:

 On 1 mar, 12:39, jbov jonathan.li...@gmail.com wrote:



  I have set up a blog using URL slugs. Say my domain is darn.it and the
  title for my first post is I lost my shoe. My blog posts are
  displaying at darn.it/posts/i-lost-my-shoe. Easy as pie, er, cake.

  I want to route it so the first parameter in the url is the slug. So
  darn.it/i-lost-my-shoe would map to controller = posts, action =
  view. Below is my routing, but I'm missing something because it's not
  passing the slug to the view method properly. Or maybe it's not
  calling the view method. Any advice?

  Router::connect(
       '/:slug',
       array('controller' = 'posts', 'action' = 'view'),
       array('slug' = '^[a-zA-Z0-9_]{1,}$')
  );

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


Re: Routing first parameter in URL to an action

2010-03-01 Thread Lucca Mordente
what do you get?
missing view or something like this?


On 1 mar, 13:34, jbov jonathan.li...@gmail.com wrote:
 No dice :-(

 Here's my view method:

         function view($slug) {
                 $post = $this-Post-findBySlug($slug);
                 $postTitle = $post['Post']['title'];
                 $this-set(array(
                                 'post'=$post,
                                 'pageheader'=$postTitle
                 ));
         }

 Anything I'm missing?

 On Mar 1, 5:55 pm, Lucca Mordente luccamorde...@gmail.com wrote:



  if its not calling the view method, try to add  \- to your regex as
  follows:

   '^[a-zA-Z0-9_\-]{1,}$'

  else if the parameter just isn't being passed, add the 'pass' option
  to route:

  Router::connect(
       '/:slug',
       array('controller' = 'posts', 'action' = 'view'),
       array('slug' = '^[a-zA-Z0-9_]{1,}$', 'pass'=array('slug'))
  );

  hope it helps (:

  On 1 mar, 12:39, jbov jonathan.li...@gmail.com wrote:

   I have set up a blog using URL slugs. Say my domain is darn.it and the
   title for my first post is I lost my shoe. My blog posts are
   displaying at darn.it/posts/i-lost-my-shoe. Easy as pie, er, cake.

   I want to route it so the first parameter in the url is the slug. So
   darn.it/i-lost-my-shoe would map to controller = posts, action =
   view. Below is my routing, but I'm missing something because it's not
   passing the slug to the view method properly. Or maybe it's not
   calling the view method. Any advice?

   Router::connect(
        '/:slug',
        array('controller' = 'posts', 'action' = 'view'),
        array('slug' = '^[a-zA-Z0-9_]{1,}$')
   );

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


Re: Routing first parameter in URL to an action

2010-03-01 Thread jbov
Notice (8): Undefined variable: javascript [APP/views/layouts/
default.ctp, line 35]

Fatal error: Call to a member function link() on a non-object in /
private/var/web/localhost/www.jonathanlibov.com/app/views/layouts/
default.ctp on line 35

Same thing I would get if I tried localhost/www.jonathanlibov.com/
foobar or localhost/www.jonathanlibov.com/posts/foobar

(i.e., the same thing I get if I try a controller or a view that
doesn't exist)




On Mar 1, 6:54 pm, Lucca Mordente luccamorde...@gmail.com wrote:
 what do you get?
 missing view or something like this?

 On 1 mar, 13:34, jbov jonathan.li...@gmail.com wrote:



  No dice :-(

  Here's my view method:

          function view($slug) {
                  $post = $this-Post-findBySlug($slug);
                  $postTitle = $post['Post']['title'];
                  $this-set(array(
                                  'post'=$post,
                                  'pageheader'=$postTitle
                  ));
          }

  Anything I'm missing?

  On Mar 1, 5:55 pm, Lucca Mordente luccamorde...@gmail.com wrote:

   if its not calling the view method, try to add  \- to your regex as
   follows:

    '^[a-zA-Z0-9_\-]{1,}$'

   else if the parameter just isn't being passed, add the 'pass' option
   to route:

   Router::connect(
        '/:slug',
        array('controller' = 'posts', 'action' = 'view'),
        array('slug' = '^[a-zA-Z0-9_]{1,}$', 'pass'=array('slug'))
   );

   hope it helps (:

   On 1 mar, 12:39, jbov jonathan.li...@gmail.com wrote:

I have set up a blog using URL slugs. Say my domain is darn.it and the
title for my first post is I lost my shoe. My blog posts are
displaying at darn.it/posts/i-lost-my-shoe. Easy as pie, er, cake.

I want to route it so the first parameter in the url is the slug. So
darn.it/i-lost-my-shoe would map to controller = posts, action =
view. Below is my routing, but I'm missing something because it's not
passing the slug to the view method properly. Or maybe it's not
calling the view method. Any advice?

Router::connect(
     '/:slug',
     array('controller' = 'posts', 'action' = 'view'),
     array('slug' = '^[a-zA-Z0-9_]{1,}$')
);

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


Re: Routing first parameter in URL to an action

2010-03-01 Thread cricket
Assuming your slugs are already lowercased, try '[-_a-z0-9]+' instead.

On Mar 1, 11:34 am, jbov jonathan.li...@gmail.com wrote:
 No dice :-(

 Here's my view method:

         function view($slug) {
                 $post = $this-Post-findBySlug($slug);
                 $postTitle = $post['Post']['title'];
                 $this-set(array(
                                 'post'=$post,
                                 'pageheader'=$postTitle
                 ));
         }

 Anything I'm missing?

 On Mar 1, 5:55 pm, Lucca Mordente luccamorde...@gmail.com wrote:

  if its not calling the view method, try to add  \- to your regex as
  follows:

   '^[a-zA-Z0-9_\-]{1,}$'

  else if the parameter just isn't being passed, add the 'pass' option
  to route:

  Router::connect(
       '/:slug',
       array('controller' = 'posts', 'action' = 'view'),
       array('slug' = '^[a-zA-Z0-9_]{1,}$', 'pass'=array('slug'))
  );

  hope it helps (:

  On 1 mar, 12:39, jbov jonathan.li...@gmail.com wrote:

   I have set up a blog using URL slugs. Say my domain is darn.it and the
   title for my first post is I lost my shoe. My blog posts are
   displaying at darn.it/posts/i-lost-my-shoe. Easy as pie, er, cake.

   I want to route it so the first parameter in the url is the slug. So
   darn.it/i-lost-my-shoe would map to controller = posts, action =
   view. Below is my routing, but I'm missing something because it's not
   passing the slug to the view method properly. Or maybe it's not
   calling the view method. Any advice?

   Router::connect(
        '/:slug',
        array('controller' = 'posts', 'action' = 'view'),
        array('slug' = '^[a-zA-Z0-9_]{1,}$')
   );



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


Re: Routing first parameter in URL to an action

2010-03-01 Thread Lucca Mordente
does your PostsController or AppController has the Javascript and Html
helpers?


On 1 mar, 14:11, jbov jonathan.li...@gmail.com wrote:
 Notice (8): Undefined variable: javascript [APP/views/layouts/
 default.ctp, line 35]

 Fatal error: Call to a member function link() on a non-object in /
 private/var/web/localhost/www.jonathanlibov.com/app/views/layouts/
 default.ctp on line 35

 Same thing I would get if I tried localhost/www.jonathanlibov.com/
 foobar or localhost/www.jonathanlibov.com/posts/foobar

 (i.e., the same thing I get if I try a controller or a view that
 doesn't exist)

 On Mar 1, 6:54 pm, Lucca Mordente luccamorde...@gmail.com wrote:



  what do you get?
  missing view or something like this?

  On 1 mar, 13:34, jbov jonathan.li...@gmail.com wrote:

   No dice :-(

   Here's my view method:

           function view($slug) {
                   $post = $this-Post-findBySlug($slug);
                   $postTitle = $post['Post']['title'];
                   $this-set(array(
                                   'post'=$post,
                                   'pageheader'=$postTitle
                   ));
           }

   Anything I'm missing?

   On Mar 1, 5:55 pm, Lucca Mordente luccamorde...@gmail.com wrote:

if its not calling the view method, try to add  \- to your regex as
follows:

 '^[a-zA-Z0-9_\-]{1,}$'

else if the parameter just isn't being passed, add the 'pass' option
to route:

Router::connect(
     '/:slug',
     array('controller' = 'posts', 'action' = 'view'),
     array('slug' = '^[a-zA-Z0-9_]{1,}$', 'pass'=array('slug'))
);

hope it helps (:

On 1 mar, 12:39, jbov jonathan.li...@gmail.com wrote:

 I have set up a blog using URL slugs. Say my domain is darn.it and the
 title for my first post is I lost my shoe. My blog posts are
 displaying at darn.it/posts/i-lost-my-shoe. Easy as pie, er, cake.

 I want to route it so the first parameter in the url is the slug. So
 darn.it/i-lost-my-shoe would map to controller = posts, action =
 view. Below is my routing, but I'm missing something because it's not
 passing the slug to the view method properly. Or maybe it's not
 calling the view method. Any advice?

 Router::connect(
      '/:slug',
      array('controller' = 'posts', 'action' = 'view'),
      array('slug' = '^[a-zA-Z0-9_]{1,}$')
 );

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


Re: Routing first parameter in URL to an action

2010-03-01 Thread jbov
Jiminy cricket that did the trick! I've been working on this on-and-
off for days and didn't suspect that it was the Regex.




On Mar 1, 7:14 pm, cricket zijn.digi...@gmail.com wrote:
 Assuming your slugs are already lowercased, try '[-_a-z0-9]+' instead.

 On Mar 1, 11:34 am, jbov jonathan.li...@gmail.com wrote:



  No dice :-(

  Here's my view method:

          function view($slug) {
                  $post = $this-Post-findBySlug($slug);
                  $postTitle = $post['Post']['title'];
                  $this-set(array(
                                  'post'=$post,
                                  'pageheader'=$postTitle
                  ));
          }

  Anything I'm missing?

  On Mar 1, 5:55 pm, Lucca Mordente luccamorde...@gmail.com wrote:

   if its not calling the view method, try to add  \- to your regex as
   follows:

    '^[a-zA-Z0-9_\-]{1,}$'

   else if the parameter just isn't being passed, add the 'pass' option
   to route:

   Router::connect(
        '/:slug',
        array('controller' = 'posts', 'action' = 'view'),
        array('slug' = '^[a-zA-Z0-9_]{1,}$', 'pass'=array('slug'))
   );

   hope it helps (:

   On 1 mar, 12:39, jbov jonathan.li...@gmail.com wrote:

I have set up a blog using URL slugs. Say my domain is darn.it and the
title for my first post is I lost my shoe. My blog posts are
displaying at darn.it/posts/i-lost-my-shoe. Easy as pie, er, cake.

I want to route it so the first parameter in the url is the slug. So
darn.it/i-lost-my-shoe would map to controller = posts, action =
view. Below is my routing, but I'm missing something because it's not
passing the slug to the view method properly. Or maybe it's not
calling the view method. Any advice?

Router::connect(
     '/:slug',
     array('controller' = 'posts', 'action' = 'view'),
     array('slug' = '^[a-zA-Z0-9_]{1,}$')
);

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


Re: Routing first parameter in URL to an action

2010-03-01 Thread jbov
I just added the Javascript helper to the AppController and that took
care of the Notice (8) issue. Thanks!



On Mar 1, 8:02 pm, Lucca Mordente luccamorde...@gmail.com wrote:
 does your PostsController or AppController has the Javascript and Html
 helpers?

 On 1 mar, 14:11, jbov jonathan.li...@gmail.com wrote:



  Notice (8): Undefined variable: javascript [APP/views/layouts/
  default.ctp, line 35]

  Fatal error: Call to a member function link() on a non-object in /
  private/var/web/localhost/www.jonathanlibov.com/app/views/layouts/
  default.ctp on line 35

  Same thing I would get if I tried localhost/www.jonathanlibov.com/
  foobar or localhost/www.jonathanlibov.com/posts/foobar

  (i.e., the same thing I get if I try a controller or a view that
  doesn't exist)

  On Mar 1, 6:54 pm, Lucca Mordente luccamorde...@gmail.com wrote:

   what do you get?
   missing view or something like this?

   On 1 mar, 13:34, jbov jonathan.li...@gmail.com wrote:

No dice :-(

Here's my view method:

        function view($slug) {
                $post = $this-Post-findBySlug($slug);
                $postTitle = $post['Post']['title'];
                $this-set(array(
                                'post'=$post,
                                'pageheader'=$postTitle
                ));
        }

Anything I'm missing?

On Mar 1, 5:55 pm, Lucca Mordente luccamorde...@gmail.com wrote:

 if its not calling the view method, try to add  \- to your regex as
 follows:

  '^[a-zA-Z0-9_\-]{1,}$'

 else if the parameter just isn't being passed, add the 'pass' option
 to route:

 Router::connect(
      '/:slug',
      array('controller' = 'posts', 'action' = 'view'),
      array('slug' = '^[a-zA-Z0-9_]{1,}$', 'pass'=array('slug'))
 );

 hope it helps (:

 On 1 mar, 12:39, jbov jonathan.li...@gmail.com wrote:

  I have set up a blog using URL slugs. Say my domain is darn.it and 
  the
  title for my first post is I lost my shoe. My blog posts are
  displaying at darn.it/posts/i-lost-my-shoe. Easy as pie, er, cake.

  I want to route it so the first parameter in the url is the slug. So
  darn.it/i-lost-my-shoe would map to controller = posts, action =
  view. Below is my routing, but I'm missing something because it's 
  not
  passing the slug to the view method properly. Or maybe it's not
  calling the view method. Any advice?

  Router::connect(
       '/:slug',
       array('controller' = 'posts', 'action' = 'view'),
       array('slug' = '^[a-zA-Z0-9_]{1,}$')
  );

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