Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Cakephp replace id on url

Posted on 2010-08-19
3
Medium Priority
?
423 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

618 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