Welcome Guest, Not a member yet? Register   Sign In
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

(This post was last modified: 04-13-2016, 12:34 PM by Wouter60.)

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

(This post was last modified: 04-14-2016, 12:22 PM by Wouter60.)

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




Theme © iAndrew 2016 - Forum software by © MyBB