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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:27:47+00:00 2026-05-23T11:27:47+00:00

I have the following code in my PortfolioController: function index() { $this->set(‘posts’, $this->Portfolio->find(‘all’)); }

  • 0

I have the following code in my PortfolioController:

function index()
    {
        $this->set('posts', $this->Portfolio->find('all'));
    }

function view ( $id, $slug )    
    {   
        $post = $this->Portfolio->read(null, Tiny::reverseTiny($id));

        $this->set(compact('post'));
    }

However in order to get the view to remove /view/ from the URL, I have added the following to my routes: Router::connect('/portfolio/*', array('controller' => 'portfolio', 'action' => 'view'));

This breaks the index method as it overrides it by calling the view method instead and shows a blank view

How do I fix this?

  • 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-05-23T11:27:47+00:00Added an answer on May 23, 2026 at 11:27 am

    What are you trying to do exactly? (And what’s with $slug?)

    It sounds like what you want to do is remove the action (or at least the view() action?) from displaying in the URL, amirite? Kind of like the default pages_controller display() method – catch-all action for static pages?

    How do I fix this?

    Well, I’d suggest starting with un-breaking that route, because otherwise it’s doing exactly what you told it to:

    Router::connect('/portfolio/*',        
    // * is a wildcard matching anything & everything after /portfolio/
        array('controller' => 'portfolio', 
    // and routing to portfolio's view() action, with or w/o required $args to pass
              'action' => 'view'));       
    

    so what you see when you call index() is not a blank view, it’s a suppressed fatal error, which is what happens when index() reroutes to view() and doesn’t have an $id to pass in for the first arg.

    Note the ending DS. Route order matters; first rule that catches, wins. The following routes would all map to index by default if the url’s action were omitted, but they’re not the same.

    // Targets inside the controller (its methods)
    Router::connect('/portfolio/', 
         array('controller' => 'portfolio', 'action' => 'index'));
    

    is not the same as

    // Targets the controller
    Router::connect('/portfolio', 
    // Specifies the default controller action, can be whatever
        array('controller' => 'portfolio', 'action' => 'index'));
    

    For what you’re trying to do, it should be

    // Targets the controller
    Router::connect('/portfolio', 
    // Routes to 'controller default method' which is index() by Cake default 
        array('controller' => 'portfolio');
    

    This allows Cake to enforce auto default mapping to the controller’s index() whenever the action is missing from the URL.

    It would still have worked except for the trailing DS and trailing asterisk. The same rule that should catch index() reroutes to view() instead, thanks to the trailing asterisk targeting all actions in portfolio.

    Hence Foo’s suggestion doesn’t work -> trailing DS + wildcard:

    Router::connect('/portfolio/', 
    // the trailing DS changes it to target 'inside portfolio' instead of 'portfolio'
        array('controller'=>'portfolio', 'action'=>'index'));
    // trailing arbitrary wildcard maps any / all actions directly to view() method
    Router::connect('/portfolio/*',
        array('controller' => 'portfolio', 'action' => 'view'));
    

    Which just ensures ALL actions in portfolio map directly to portfolio view() method (including /portfolio/index action). Do not pass go, etc. Any portfolio action resolves to the wildcard no matter what, aliasing the whole controller to that method. So you could knock the DS off the first route but any url starting with /portfolio that isn’t /portfolio would still route to view(). Including the url /portfolio/index.

    Try this:

    // catches portfolio/index() without index in the url
    Router::connect('/portfolio', 
        array('controller' => 'portfolio')); 
    // maps to portfolio/view() without view in url, just /portfolio/integer id 
    Router::connect('/portfolio/:id', 
        array('action'=>'view',  array('id' => '[0-9]+')); 
    // routes everything else in portfolio as usual
    Router::connect('/portfolio/:action/*', 
        array('controller'=>'portfolio'));
    

    Routes can be tricky. Here are some links; HTH. 🙂

    http://bakery.cakephp.org/articles/Frank/2009/11/02/cakephp-s-routing-explained

    http://book.cakephp.org/view/46/Routes-Configuration

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

Sidebar

Related Questions

I have following code function Model(onChanged) { this.array = new Array(); this.onChanged = onChanged;
I have following code in my application: // to set tip - photo in
I have following code in a html form <select name=category class=input onchange=ShowTB(this,'suggest');> <option value=0
I have following code to set the font for setting the telugu font. while
I have following code: string date = 13.04.2012; string date2 = (DateTime.Parse(date).AddDays(1)).ToString(); This is
I have following code: canvas=new MembershipFunctionComponent(functions); canvas.setPreferredSize(new Dimension((int)this.getWidth(), (int)this.getHeight())); canvas.addMouseListener(canvas); pane.add(canvas); MembsershipFunctionComponent extends JComponent.
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following code which add BackButton on my view's navigation item's tabbar. It
I have following code to find if row is selected, which is selected and
I have following code in my MVC2 view: <tr class=edit style=display:none> <td> <%= Html.DropDownList(drpFields,

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.