• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get url from a controller and method

#1
Hello,
Is posible get url from a controller and method

Something like this:
file routes.php
$route['blog/from/controller/home'] = 'ControllerName/Home';

And anywhere controller
$url = $this->router->get_url('ControllerName','Home');
echo $url;
//exit must be "blog/from/controller/home"
Reply

#2
Did you try this:
PHP Code:
$this->load->helper('url');  // if you need this often, autoload the helper in config/autoload.php
echo current_url(); 
Reply

#3
(04-13-2016, 12:33 PM)Wouter60 Wrote: Did you try this:
PHP Code:
$this->load->helper('url');  // if you need this often, autoload the helper in config/autoload.php
echo current_url(); 

thanks, but i want know a url from another Controller not current url, you know?
Reply

#4
Maybe this will help you:
PHP Code:
if (file_exists(APPPATH.'config/routes.php'))
{
    include(
APPPATH.'config/routes.php');
}        
echo 
'<pre>';
print_r($route);
echo 
'</pre>'

You can determine which controller/method is assigned to which route:
PHP Code:
$find 'ControllerName/Home';
$key array_search($find,$route);   //returns the key of the route array element with the search value
echo $key

If you're working with different config.php files for different environments, the code will need a little more tweaking.
Take a look at the system/core/Router.php file.
Reply

#5
Check URI library. Maybe

PHP Code:
$this->uri->uri_string(); 

or

PHP Code:
$this->uri->ruri_string(); 

could work for you.
Reply

#6
This was the exact problem that I was facing. I called it named routes.
I have created a infrastructure for it to work, may be you can check and see if it is the right solution or not.

Here is the link : https://github.com/aajiwani/LaravelRouti...odeIgniter
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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