Url object

NOTICE: I am not referring to cUrl but a Url object

Hello ppl,

Do you think it would be nice to introduce a Url object in the yii 2.0. This would be used internally in CUrlManager and CHttpRequest but it would hold the logic and functionality around urls like:

  • Creating a PATH or GET url ( currently in CUrlManager )

  • Be able to getRequestUri from a url ( part of the CHttpRequest ), so people would be able to handle url with common Yii functions.

Please let me know what you think about it. It’s just a draft thought.

Friendly and geeky.

Why? What does it offer that parse_url() doesn’t?

It’s only about parsing but also generating urls. And no, I would prefer something more DRY. :)

Dunno, something’s telling me that weren’t such a good idea. I clearly see how you got there, but it doesn’t feel right.

I’m currently experimenting with phpnode’s work on a CHttpResponse class and had about the same idea. I left the URLs as strings eventualy. It looked a lot like bloat to me. And … yeah, well, what phpnode said: There’s always parse_url().

Again, It’s not about parsing url. It’s about generating url as well.

I want to consume an api that has PATH format instead of GET. So I have ‘http://some.api.com/’ and an array like array(‘user’=>1) where 1 the id of the user. How can I create it ? Of course there is a php way but wouldn’t be nice to be able to have a yii premade infastructure for this stuff?

Sounds more like you’d want an enhanced version of CUrlManager.createUrl(). Still don’t see the need for a CUrl class.

It’s more likely that the CUrlManager has to do with your application urls and not a third party service urls.

As is, yes. But it could surely be enhanced to craft URLs for other sites as well. By the way: Zend Framework has a support class for URIs.

I would really did not want to mix up this 2, this is why I mentioned creating this object to handle the urls and the urlmanager will use this object internally for the application urls.

But then you’re still mixing this? :huh:

Anyway, I might have actually found a purpose for this class: It could be useful if you want to add/remove GET-params dynamicaly from a URL.

Just for reference: Horde_Url is doing that.

@Da:Sourcerer, I am pretty sure more use cases will appear if more people get involved in the converstation.

Also for reference: http://qt-project.org/doc/qt-4.8/QUrl.html

Eye-catching from the API: Support for port, userinfo (both missing in horde_url) and a whole lot seems to be about encoding.

For a recent project, I searched a way to transform a relative URL into an absolute one. Think this would be another candidate for such a class. In the end, I used this: http://sourceforge.net/projects/absoluteurl/

whats wrong with create url function?


As I said before


( God knows what $this refers to ) has to do with your Yii Application urls and not third party urls like REST service that you want to consume.