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 9149469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:28:53+00:00 2026-06-17T11:28:53+00:00

I don’t know the first thing about doing queries in CakePHP OR doing routes

  • 0

I don’t know the first thing about doing queries in CakePHP OR doing routes in CakePHP so I don’t even know how to start to find a solution for my question. Maybe you can help.

I want users to be able to go to:

http://www.domain.com/movies/1

OR

http://www.domain.com/movie-nickname

Both would access the “pages” controller, “view” action. And they should both come up with the page id = 1.

(I don’t want them to simply go to http://www.domain.com/pages/1)

Each page has a nickname for the URL, but if left blank the url will be http://www.domain.com/CATEGORY/PAGE as shown in the first example.

If the nickname is not left blank, is there a way I can do a query inside my route that says “SELECT id FROM pages WHERE nickname = ‘nickname'”

On top of this, if the nickname in the pages table is “this that”, the URL should be http://www.domain.com/this-that, meaning the hyphen needs to be replaced with spaces and THEN execute the query.

I have the route for the first URL which is:

Router::connect(
    '/:category/:page',
    array('controller' => 'pages', 'action' => 'view'),
    array(
        'pass' => array('page'),
        'page' => '[0-9]+',
        'category' => 'shows|music|games|books|hobbies'
    )
);

Is the second option I am looking for possible?

  • 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-17T11:28:53+00:00Added an answer on June 17, 2026 at 11:28 am

    I figured out my custom routing.

    App::uses('ClassRegistry', 'Utility');
    
    // HOMEPAGE
    Router::connect('/', array('controller' => 'index', 'action' => 'index'));
    
    $requestURI = explode('/', $_SERVER['REQUEST_URI']);
    $scriptName = explode('/',$_SERVER['SCRIPT_NAME']);
    
    for($i= 0;$i < sizeof($scriptName);$i++)
            {
          if ($requestURI[$i]     == $scriptName[$i])
                  {
                    unset($requestURI[$i]);
                }
          }
    
    $param = array_values($requestURI);
    
    $param1 = $param[0]; // domain.com/page-nickname
    $param2 = $param[1]; // domain.com/category_id/page_id
    
    // convert 'page-nickname' to 'page nickname' which is what it would be in db
    $pagelink = str_replace('-', ' ', $param1);
    
    // initiate Page mode;
    $pagesModel = ClassRegistry::init('Page');
    
    // check if there is a matching page in the db that has link column like 'page nickname'
    $matchedpage = $pagesModel->find('first', array(
        'conditions' => array('Page.link LIKE' => "$pagelink"), 'recursive' => '0'
    ));
    
    
    // Cache::write('routepagelinks', $pagelinks);
    
    // if there is a match
    if($matchedpage['Page']['id']){
        Router::connect('/' . $param1, array('controller' => 'pages', 'action' => 'view', 'page' => $matchedpage['Page']['id']), array(
        'pass' => array('page'),
        'page' => '[0-9]+'
        ));
    
    // ... more custom routing if there is a match
    
    }
    
    // general routing info here
    
    
    // if no page-nickname, routes page for domain.com/category_id/page_id
    Router::connect(
    '/:category/:page',
    array('controller' => 'pages', 'action' => 'view'),
    array(
        'pass' => array('page'),
        'page' => '[0-9]+',
        'category' => 'shows|music|games|books|hobbies'
        )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know a whole lot about streams. Why does the first version work using
Don't know why but I can't find a solution to this. I have 3
don't know if the title describes anything about what I'm trying to say but
Don't these two mean the same thing, first get the value and then increment?
Don't know if it's I'm doing it wrong or if there's a bug (I
I don't have much knowledge about the IPv6 protocol, so sorry if the question
Don't know if it matters, but the msg.d is about 300 rows long. I
Don't know if this has been answered before. Have custom routes to users. If
Don't know much about encryption... Say I'm preparing a SAML request to submit to
Don't know much about running a function on every item in an array, still

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.