jonathan ELORE
jonathan ELORE

Reputation: 21

Routes not recognized

Because I need to have routes like this :

/my-example-of-product-p120.htm
/my-example-of-category-c10.htm 

I write my routes:

Router::connect(
        '/:slug-p:id',
        array('controller' => 'product', 'action' => 'view'),
        array('pass' => array('id'),
              array(
                  'id' => '[0-9]+',
                  'slug'=>"[a-z0-9\-]+"
              )
        )
    );

Router::connect(
        '/:slug-c:id',
        array('controller' => 'categories', 'action' => 'view'),
        array('pass' => array('id'),
              array(
                  'id' => '[0-9]+',
                  'slug'=>"[a-z0-9\-]+"
              )
        )
    );

But CakePhp doesn't recognize my routes. Can anyone help me with this, please?

Upvotes: 1

Views: 64

Answers (1)

jonathan ELORE
jonathan ELORE

Reputation: 21

the problem comes from the separator between :slug and :id ("-p" or "-c") so I simply put it in argument

Router::connect(
        '/:slug:sep:id',
        array('controller' => 'product', 'action' => 'view'),
        array('pass' => array('id'),
              array(
                  'id' => '[0-9]+',
                  'sep' => '-p',
                  'slug'=>"[a-z0-9\-]+"
              )
        )
    );
Router::connect(
        '/:slug:sep:id',
        array('controller' => 'categories', 'action' => 'view'),
        array('pass' => array('id'),
              array(
                  'id' => '[0-9]+',
                  'sep' => '-c',
                  'slug'=>"[a-z0-9\-]+"
              )
        )
    );

Upvotes: 1

Related Questions