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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:39:31+00:00 2026-05-23T02:39:31+00:00

I have the following link structure for my portfolio: <?php echo $this->Html->link($post[‘Portfolio’][‘title’], array(‘controller’ =>

  • 0

I have the following link structure for my portfolio:

<?php echo $this->Html->link($post['Portfolio']['title'], array('controller' => 'portfolio', 'action' => 'view', Inflector::slug($post['Portfolio']['title'])), array('title' => $post['Portfolio']['title'])); ?>

Which gives urls like: http://driz.co.uk/portfolio/view/Paperview_Magazine

However how do I get my controller to show the item based on the title?

So far I have this but have not been able to get it to work and just get a blank page (so I ALSO need to check the format is correct and that their is a relevant item)

function view ( $title )
{

    $posts = $this->Portfolio->find('first', array('conditions' => array('Portfolio.title' => $title)
    ));

    if (empty($title))
    {
        $this->cakeError('error404');
    }
    $this->set(compact('posts'));
}
  • 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-23T02:39:32+00:00Added an answer on May 23, 2026 at 2:39 am

    @Ross suggested that you search using Portfolio.slug so here’s how you could do this:

    1. Add a field to your database table called slug. You’ll most likely want a VARCHAR with sufficient length to accommodate the slug.
    2. When you create or update a “Portfolio” record, use the Inflector::slug method to generate a slug and save it to your database. You could always do this in the model’s beforeSave event or if you prefer, in the controller before saving the data.
    3. Update the find call to look for Portfolio.slug instead of Portfolio.title.

    Unfortunately, there’s no way to reverse the Inflector::Slug function as it removes certain characters like apostrophes, quotes, parentheses, etc. which is why you need to save the slug to your database if you want to search for it.

    Here’s how you could use the beforeSave event in your model:

    public function beforeSave(array $options = array())
    {
      // If the title is not empty, create/update the slug.
      if ( ! empty($this->data[$this->alias]['title'] )
        $this->data[$this->alias]['slug'] = Inflector::slug($this->data[$this->alias]['title']);
    
      // Returning true is important otherwise the save or saveAll call will fail.
      return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following file: <html> <head> <title></title> <link rel=css type=text/css href=/empty.css title=css />
I have the following JavaScript code: Link In which the function makewindows does not
I have the following line of code in a link on my webpage: <a
I have a link that I dynamically create which looks something like the following:
Following on from my previous question [link text][1] , I have a new problem.
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following string String str = replace :) :) with some other string;
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following situation. A main table and many other tables linked together with

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.