Solved

Cakephp replace id on url

Posted on 2010-08-19
3
414 Views
Last Modified: 2013-11-10
Hi all,

I am using cakephp and I am using a view to display records ... my code is very similar to this one:

http://book.cakephp.org/view/1536/Creating-Post-Views

My URL would be like: /view/1   where 1 is the id of the record to show.

My question is: How can I have the title field (got example) to show in the url insyead of the id?

Thanks

0
Comment
Question by:error77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
ganesh_gns earned 500 total points
ID: 33482332
Hi,
Use the attach code it will solve your problem



<!-- File: /app/views/posts/index.ctp -->

<h1>Blog posts</h1>
<table>
	<tr>
		<th>Id</th>
		<th>Title</th>
		<th>Created</th>
	</tr>

	<!-- Here is where we loop through our $posts array, printing out post info -->

	<?php foreach ($posts as $post): ?>
	<tr>
		<td><?php echo $post['Post']['title']; ?></td>
		<td>
			<?php echo $html->link($post['Post']['title'], 
array('controller' => 'posts', 'action' => 'view', $post['Post']['title'])); ?>
		</td>
		<td><?php echo $post['Post']['created']; ?></td>
	</tr>
	<?php endforeach; ?>

</table>

---------------------------

<?php
class PostsController extends AppController {

	var $name = 'Posts';

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

	function view($id = null) {
		$this->Post->title = $title;
		$this->set('post', $this->Post->read());
	}
}
?>

Open in new window

0
 

Author Comment

by:error77
ID: 33482680
Will try and get back to you.

Thanks!
0
 

Author Comment

by:error77
ID: 33490692
Hi ganesh_gns,

I tested your code but it didn't work.

Any ideas why?

thx
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question