Complex Urls

17 views
Skip to first unread message

Don Pinkster

unread,
Apr 4, 2011, 5:29:47 AM4/4/11
to sph...@googlegroups.com
Hi,

I want to have an url like /posts/5/edit. I want to go to the PostEdit
controller with 5 as parameter. Is this possible?

Thanks.

TacoV

unread,
Apr 4, 2011, 5:35:52 AM4/4/11
to sphoof
Hey,

Regardless of how easy it would be to do this (I´m not sure about that
from the top of my head), the URL we designed the controllers for
wouldn't be /posts/5/edit but rather /posts/5?edit. Please see some
explanation of this choice in http://sphoof.nl/controller.html. You
can then use SpController::name() to retrieve the parameter.
TL;DR version of the link: a URL points to a resource, not to a
resource+action.

Cheers,

Taco

Don Pinkster

unread,
Apr 4, 2011, 5:45:09 AM4/4/11
to sph...@googlegroups.com
Hey,

Yeah I aware of that part, but embracing HTTP the following seems more
logical to me:

Imagine the following url:
/blog/posts/5/edit

Posts belongs to a Blog
5 belongs to a Posts collection
Edit belongs to the My-First-Post

Am I wrong in this mindset? :-)

Thanks for thinking with me.

Don

> --
> You received this message because you are subscribed to the Google Groups "sphoof" group.
>
> post: sph...@googlegroups.com.
> Unsubscribe: sphoof+un...@googlegroups.com
> Options: http://groups.google.com/group/sphoof?hl=en
> Docs: http://sphoof.nl/
>

Don Pinkster

unread,
Apr 4, 2011, 5:46:59 AM4/4/11
to sph...@googlegroups.com
Nevermind my latest reaction; I had the following scheme in my head:
/posts/edit/5

Thanks.

Don

Berry Langerak

unread,
Apr 4, 2011, 6:13:27 AM4/4/11
to sph...@googlegroups.com
Hi.

On 04/04/2011 11:45 AM, Don Pinkster wrote:
> Yeah I aware of that part, but embracing HTTP the following seems more
> logical to me:
>
> Imagine the following url:
> /blog/posts/5/edit
>
> Posts belongs to a Blog
> 5 belongs to a Posts collection
> Edit belongs to the My-First-Post
>
> Am I wrong in this mindset? :-)

Sorry to say, but yes, the opposite is true. You see, in HTTP every
segment of a URL should point to a *resource*. In your example, the blog
itself would be a resource, namely, a collection of posts. The post
itself would also be a resource. "edit", however, is a verb, not a noun,
so it isn't a resource. The "edit" _action_ would be yielded by
appending the ?edit query parameter, which will result in calling
getEdit( ) *on the resource*.

It would be rather trivial to implement ($this->context->name( ) would
yield "5" in your examplary URL), but I would advice against it.


Cheers,

Berry.

Don Pinkster

unread,
Apr 4, 2011, 6:31:38 AM4/4/11
to sph...@googlegroups.com
I stand corrected. Thanks for thinking with me!

Don

Reply all
Reply to author
Forward
0 new messages