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

  • Home
  • SEARCH
  • 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 9236983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:25:54+00:00 2026-06-18T07:25:54+00:00

I’m using Cakephp 2+ and I have a model called ‘posts’, and posts can

  • 0

I’m using Cakephp 2+ and I have a model called ‘posts’, and posts can be different types, for example – blog post, message, etc.

In config/routes.php, How do I set up my routing so that I have /posts/12/post-title or /blog/14/blog-title?

At the moment I have this:

Router::connect('/:type/add', array('controller' => 'posts', 'action' => 'add'),
    array('pass' => array('type')));

Router::connect('/:type/:action', array('controller' => 'posts'),
    array('pass' => array('type')));

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

But the problem is that this is then used for every URL, so cakephp thinks that my user profile page should look at my posts controller because it think’s i’m passing in a :type –

…

#View Profile
Router::connect('/profile/:id', array('controller' => 'users', 'action' => 'view'),
    array('pass' => array('id'), 'id' => '[0-9]+'));

Does anyone know the means of doing this properly? Many thanks

  • 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-18T07:25:55+00:00Added an answer on June 18, 2026 at 7:25 am

    First of all, the order of your routes matter, if multiple routes will match an URL, the first matching route will be handled

    Next, you can limit ‘what’ will be considered a ‘type’ by setting a regular expression for the ‘type’ key in the last argument of Router::connect(), just as you did for ‘id’. You might be able to either include all valid types in the regular expression, or add a ‘negative’ part to the regular expression that excludes values, e.g. Controller names

    Something like this:

    Router::connect(
        '/:type/:action',
        array(
             'controller'  => 'posts',
        ),
        array(
             /**
              * Custom type:
                  * only allow 'post', 'blog' or 'message' as type here
                  * to prevent overlapping with 'controllers'
              */
             'type'   => '(post|blog|message)',
    
             // Define what should be passed to the 'view' action as arguments
             'pass'   => array('type'),
    
             /**
              * Optionally, define what parameters should be automatically preserved
              * when creating URLs/links
              */
             'persist' => array('type'),
        )
    );
    
    Router::connect(
        '/:type/:id/:slug',
        array(
             'controller'  => 'posts',
             'action'      => 'view',
        ),
        array(
             /**
              * Custom type:
                  * only allow 'post', 'blog' or 'message' as type here
                  * to prevent overlapping with 'controllers'
              */
             'type'   => '(post|blog|message)',
             'id'     => '[0-9]+',
    
             // Define what should be passed to the 'view' action as arguments
             'pass'         => array('type', 'id', 'slug'),
    
             /**
              * Optionally, define what parameters should be automatically preserved
              * when creating URLs/links
              */
             'persist' => array('type'),
        )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am using JSon response to parse title,date content and thumbnail images and place
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

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.