Welcome Guest, Not a member yet? Register   Sign In
Can be method used as id?
#1

[eluser]AndyBrandy[/eluser]
Hi,

Can i use method as id or parameter?
I need From this url : example.com/text/programing/1/

go to the class "text" and here goes to index.

It's real?
#2

[eluser]Michael Wales[/eluser]
Code:
<?php
  class Text extends Controller {
    function _remap($method) {
      if ($method == 'programming') {
        $this->index();
      }
    }

    function index() {
      echo '<a href=\"http://ellislab.com/codeigniter/user-guide/general/controllers.html#remapping\">Read the Docs</a>';
    }
  }
?&gt;
#3

[eluser]AndyBrandy[/eluser]
Aha!

Thanks. :roll:
#4

[eluser]sophistry[/eluser]
You could also do this with the Routing rules.

Code:
// not tested
route['text/([a-z]+)'] = "text/index/$1";

Be careful if you use _remap() you have to tell your controller what to do with all the other function names that might come in.

I think if all you want to do is pass parameters to an index function you are better off with routing.
#5

[eluser]AndyBrandy[/eluser]
I want use this for remap all functions in class. But
both sides are good ideas.
#6

[eluser]Phil Sturgeon[/eluser]
Remap has a few flaws, you have to manually input any URL segments to the controller.

For example:

Code:
&lt;?php
  class Text extends Controller {
    function _remap($method) {
      if ($method == 'programming') {
        $this->index();
      }
    }

    function index($param) {
      echo $param;
    }
  }
?&gt;

Wont work, $param will show as blank. Use routes for this sort of thing if you need variables from the URL.
#7

[eluser]Michael Wales[/eluser]
Or just use the URI helper. I agree though, rerouting is a good way to go. Remapping is nice for little things.




Theme © iAndrew 2016 - Forum software by © MyBB