Yii Framework Forum: Url object - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Url object Handling Url as an object

#1 User is offline   tydeas_dr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 158
  • Joined: 16-April 10
  • Location:Greece

Posted 30 April 2012 - 07:29 AM

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.
Follow me on twitter @dmtrsslvdr
Check my *new* blog @ tumblr
1

#2 User is offline   phpnode 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 141
  • Joined: 18-April 11

Posted 30 April 2012 - 07:39 AM

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

#3 User is offline   tydeas_dr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 158
  • Joined: 16-April 10
  • Location:Greece

Posted 30 April 2012 - 07:43 AM

It's only about parsing but also generating urls. And no, I would prefer something more DRY. :)
Follow me on twitter @dmtrsslvdr
Check my *new* blog @ tumblr
0

#4 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 30 April 2012 - 07:53 AM

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().
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#5 User is offline   tydeas_dr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 158
  • Joined: 16-April 10
  • Location:Greece

Posted 30 April 2012 - 07:57 AM

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?
Follow me on twitter @dmtrsslvdr
Check my *new* blog @ tumblr
0

#6 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 30 April 2012 - 08:02 AM

Sounds more like you'd want an enhanced version of CUrlManager.createUrl(). Still don't see the need for a CUrl class.
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#7 User is offline   tydeas_dr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 158
  • Joined: 16-April 10
  • Location:Greece

Posted 30 April 2012 - 08:05 AM

It's more likely that the CUrlManager has to do with your application urls and not a third party service urls.
Follow me on twitter @dmtrsslvdr
Check my *new* blog @ tumblr
0

#8 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 30 April 2012 - 08:10 AM

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.
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#9 User is offline   tydeas_dr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 158
  • Joined: 16-April 10
  • Location:Greece

Posted 30 April 2012 - 08:16 AM

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.
Follow me on twitter @dmtrsslvdr
Check my *new* blog @ tumblr
1

#10 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 30 April 2012 - 08:18 AM

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.
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#11 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 30 April 2012 - 08:24 AM

Just for reference: Horde_Url is doing that.
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#12 User is offline   tydeas_dr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 158
  • Joined: 16-April 10
  • Location:Greece

Posted 30 April 2012 - 08:27 AM

@Da:Sourcerer, I am pretty sure more use cases will appear if more people get involved in the converstation.
Follow me on twitter @dmtrsslvdr
Check my *new* blog @ tumblr
0

#13 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 270
  • Joined: 15-March 09

Posted 30 April 2012 - 05:25 PM

Also for reference: http://qt-project.or...t-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.n...ts/absoluteurl/
Don't like ads in my sig...
0

#14 User is offline   Jaggi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 90
  • Joined: 05-September 11

Posted 01 May 2012 - 03:38 AM

View Posttydeas_dr, on 30 April 2012 - 07:57 AM, said:

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?


whats wrong with create url function?

$this->createUrl();
See my development site @ www.CodeTheInter.net (BETA)

Posted Image Posted Image

Quote

If you make it idiot proof, they'll build a better idiot
0

#15 User is offline   tydeas_dr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 158
  • Joined: 16-April 10
  • Location:Greece

Posted 21 May 2012 - 03:16 PM

View PostJaggi, on 01 May 2012 - 03:38 AM, said:

whats wrong with create url function?

$this->createUrl();

As I said before
$this->createUrl()
( 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.
Follow me on twitter @dmtrsslvdr
Check my *new* blog @ tumblr
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users