Solved

Cakephp replace id on url

Posted on 2010-08-19
3
395 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
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
ganesh_gns earned 500 total points
Comment Utility
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
Comment Utility
Will try and get back to you.

Thanks!
0
 

Author Comment

by:error77
Comment Utility
Hi ganesh_gns,

I tested your code but it didn't work.

Any ideas why?

thx
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now