• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Relative internal URLs

#1
[eluser]Unknown[/eluser]
Hi everyone,

I have just started checking out CodeIgniter. Since I have been using CakePHP for the past 2 years I have not been able to discover how to create relative URLs (something I am used to). FYI: I have tried searching in the wiki and these forums without much luck.

What I want to do
I want to create an URL for the action/function/method called "dosomething" (as an example) in the current controller from a view-file that may be used in more than one controller.

What I have tried doing so far
I get the same results regardless of a preceding slash. The URL helper seems to only handle "complete" urls that can be prepended by config-values for the installation.
'dosomething'
'/dosomething'

I think that I may be able to get something going by using segment(0) the uri class to get the controller name but from what I have read that will fail as soon as I start putting thing in a folder or change some routing.

What I am looking for is the preferred or official or supported way of determining the current controller and action names from within a view.

Thanks in advance for any hints and tips on this subject.

#2
[eluser]BravoAlpha[/eluser]
[quote author="Eimermusic" date="1192643202"]I think that I may be able to get something going by using segment(0) the uri class to get the controller name but from what I have read that will fail as soon as I start putting thing in a folder or change some routing.[/quote]

User Guide: URI Class
Quote:$this->uri->rsegment(n)
This function is identical to [$this->uri->segment(n)], except that it lets you retrieve a specific segment from your re-routed URI in the event you are using CodeIgniter's URI Routing feature.

Also:
Code:
$this->uri->router->class
$this->uri->router->method

#3
[eluser]Unknown[/eluser]
Thanks for the quick reply.
$this->uri->router->... looks like a useful thing I hadn't found.

The problem with segment and rsegment when I tried them was that I could not easily get at the class and method names. When putting stuff in folders segment(1) returns the folder but otherwise returns the class.

I think the router class is where the info I am after is stored. I see variables for some other useful bits of data also.
Thanks again.

/Martin


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.