Zendcasts Forum

A community of developers who work with the Zend Framework and other enterprise PHP technologies

You are not logged in.

#1 2010-03-03 14:52:55

miika
Member
From: Finland
Registered: 2010-03-03
Posts: 10

SEF urls?

Hello!

What would be the best way to do sef urls?

I mean that if I have, for example, post controller with view action and post with id 10, I would have url like http://www.example.com/post/view/10.

But if I want to url be like http://www.example.com/post/my-article-title/, what I have to do? What would be the best way? Or Zend Framework way to do that?

Last edited by miika (2010-03-03 14:53:51)

Offline

#2 2010-03-04 13:30:37

Jon Lebensold
Administrator
Registered: 2009-06-27
Posts: 279

Re: SEF urls?

Hey miika,

you could definitely do it, however you'll need to configure a special route. I would suggest something like:
/post/:title/:id
so it would become
http://www.example.com/post/my-article-title/10

this way, it would be easy to parse out the id with $this->_getParam('id');

alternatively, you could append it to the post title, explode() on '-', reverse the stack and array_pop the top or grab the last element in the array.

with Zend_Route, you can basically create any kind of url structure you want and route it to the PostController::viewAction();

good luck!

Offline

Board footer

Powered by FluxBB