Welcome Guest, Not a member yet? Register   Sign In
Segmentation URL
#1

[eluser]cinewbie81[/eluser]
Instead of www.mysite.com/index.php/myclass/myfunction/myparam&key=12345&name=testing

Is there any way for me to make the url to be more simple and readable ? I was wondering if there's any way for me to hide the controller, function, and parameter segmentation from the url ??
#2

[eluser]Chris Newton[/eluser]
You could hide the parameters by POSTing them instead of sending them as a query string.
#3

[eluser]cinewbie81[/eluser]
what about controller and fuction ?
#4

[eluser]nate_02631[/eluser]
Unless you're only going to have only one controller and function, you at least have to show the function, and can use routing to hide the controller(s) (in routes.php).. i.e.
Code:
$route['myfunction' . '/(.*)'] = 'mycontroller/myfunction/$1';
You can optionally set a "greedy" route, so that a particular controller/function needs only have the parameters passed in the url:
Code:
$route['(.*)'] = 'mydefaultcontroller/mydefaultfunction/$1';
Though you have to explicitly define routes for each of your controllers before the "greedy" route, or they won't work correctly...
Code:
$route['mycontroller'] = 'mycontroller';
$route['mycontroller' . '/(.*)']   = 'mycontroller/$1';
You can also use mod_rewrite to get rid of the "index.php" as well, of course (see user manual)... and the values in the query string are not necessary.

Assuming you are using mod_rewrite and use routing to hide myclass, the URL:
www.mysite.com/index.php/myclass/myfunction/myparam&key=12345&name=testing
becomes:
www.mysite.com/myfunction/12345/testing
...which is passed to your myclass controller function as:
Code:
myfunction($key, $name) {
  ...
}
And of course it helps to name your controllers, functions, and parameters so they make sense.. for example in my admin, the URLs resemble:
www.mysite.com/admin/product/update/55
#5

[eluser]Fatih[/eluser]
Hi everyone,

I have a strange problem about segmentation URL. I have two different controllers and I want to use all of them with this method. Therefore I added two lines on routed.php like these:

Code:
$route['mycontroller1/(.*)'] = "mycontroller1/index/$1";
$route['mycontroller2/(.*)'] = "mycontroller2/index/$1";

But it is interesting that, only mycontroller2 is working correctly. mycontroller1 is not working. mycontroller1's name and mycontroller2's name are different. But only works below line as correctly.

Why?
#6

[eluser]Fatih[/eluser]
It is fixed.

I found this thread. Also, I added some codes into my controllers as given below:

Code:
function _remap($method) {
    if ($this->uri->segment(2)) {
        $method = $this->uri->segment(2);
    }

        $this->index($method);
    }

Then I remove these codes "route['bla bla']" from my route.php.

Everything are fine now.




Theme © iAndrew 2016 - Forum software by © MyBB