Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8695415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:01:42+00:00 2026-06-13T01:01:42+00:00

I am new with cakePHP, I wish to rewrite my urls in my application.

  • 0

I am new with cakePHP, I wish to rewrite my urls in my application.

For some of my Controllers I want to navigate as.

`controller/action/id/slug`.

for this I write rule as,

Router::connect(
        '/products/:id/:slug', array('controller' => 'products', 'action' => 'view'), array('pass' => array('id'), 'id' => '[0-9]+')
);

I am writing link as..

echo $this->Html->link($record['Category']['name'], array('controller' => 'categories', 'action' => 'index', 'slug' => $record['Category']['slug']), array('escape' => false)); 

Questions

  1. Is the rule only application to mentioned controller and action i.e. product and view resp. ?

  2. Why my url (on hover) is showing as controller/action/slug:slug_name instead of controller/action/slug_name ?

  3. In same controller I wish to use different url rewriting such as action/id/slug_name or somewhere I sent /action or somewhere I use only slug action/slug_name. Is only single rule is written for all? Or I have to define separate rule for each controller and action.

  4. Creating common rule for all controllers as well ?

Please describe more. I tried to read the documentation but bit confused with it. How my params would get request for all sort of types I have mentioned.

Write now I am using only simple methods to get params as

 controller/action/param1:param_val1/param2:param_val2,
 echo $this->Html->link('Val', array('controller' => 'categories',
 'action' => 'index', 'param1' => param_val1, 'param2' => param_val2,),
 array('escape' => false));

And so on. But I wish to have pretty clear n beautiful url along with better and faster moves. Like passing slug I wish to directly fetch findBySlug or some sort of way making it pretty more good.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:01:44+00:00Added an answer on June 13, 2026 at 1:01 am

    1) Yes, When you create a Router::connect rule is only aplicable for one case, namely is applicable for one url or group os urls.

    2) You should do it in this way

    echo $this->Html->link($record['Category']['name'], array('controller' => 'categories', 'action' => 'index',  $record['Category']['slug']), array('escape' => false));
    

    3) You must create a rule for those urls, only when the structure of the url is different

    According with your examples, the rules will be as follows

    # only for action/slug_name case
    Router::connect('/products/:slug', array('controller' => 'products', 'action' => 'view'), array('pass' => array('slug'), 'slug'=>'[a-z_]+'));
    # for action/id/slug_name case
    Router::connect('/products/:id/:slug', array('controller' => 'products', 'action' => 'view'), array('pass' => array('id','slug'), 'id' => '[0-9]+','slug'=>'[a-z_]+'));
    

    4) I recommend you to write the urls without using the HTML component of CakePHP. Not because it’s bad, but because it is much faster and easier

    instead of doing this:

    controller/action/param1:param_val1/param2:param_val2,
     echo $this->Html->link('Val', array('controller' => 'categories','action' => 'index', 'param1' => param_val1, 'param2' => param_val2,),array('escape' => false));
    

    much better to do this:

    controller/action/param_val1/param_val2
    
     echo 'controller/action/'.$param_val1.DS.$param_val2;
    

    Also is better for SEO, and url-friendly

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a new CakePHP site, and I wish to redirect some old urls
I am new in cakephp and I want to import controller in my controller
I'm new to cakephp and trying to write a simple app with it, however
I'm new to cakephp and following this tutorial. http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html I have created the blog
I'm new to CakePHP and I trying out some of the tutorials on it.
I'm new to cakephp and I'm having some problems with setting up a local
I'm new to CakePHP and i want to migrate from my custom lib to
I am new to CakePHP and want an admin panel on my custom CMS
(New to CakePHP, so this may be an obvious thing, but I was unable
I'm new with cakephp and I've just finished putting my controllers, models and views

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.