Welcome Guest, Not a member yet? Register   Sign In
I hope this is not a bug!
#1

[eluser]Fierymind[/eluser]
In my project, I'm doing my best to shorten URLS without editing .htaccess file.

so I used _remap function as main function in the controller to skip the function part in URLs

so
http://localhost/project/index.php/controller/variable1
will run similar to
http://localhost/project/index.php/contr.../variable1

and this work just fine ... but what if I want to pass more variables?

like:
http://localhost/project/index.php/contr.../variable2

in that case, you always get "Missing argument" warnning even if you put default values like:

Code:
function _remap(variable1='something',variable2='something else')

Is there any way to force _remap take more than 1 arguments?
#2

[eluser]Fierymind[/eluser]
can anyone confirm or deny the fact that _remap function can take only 1 argument?
#3

[eluser]OwanH[/eluser]
[quote author="Fierymind" date="1184127308"]can anyone confirm or deny the fact that _remap function can take only 1 argument?[/quote]

CI's _remap function only accepts one argument, that being the first segment in the URL after the controller name, usually the function name in a non-_remaped URL. However you can get the remaining segments in the URL by using the URI class.

I've included an example controller class to help clarify. Here it is:

Code:
<?php
class Test extends Controller {

  function Test()
  {
    parent::Controller();
    echo "Class Test initialised<br />";
  }
  
  function index()
  {
    echo "index function called<br />";
  }
  
  function _remap($method, $arg1 = "default", $arg2 = "default2")
  {
    echo "_remap invoked with the following arguments:<br />method: $method<br />arg1: $arg1" .
         "<br />arg2: $arg2<br /><br />Total URI segments: " . $this->uri->total_segments() .
         "<br />The segments are:<br />";
    echo "<div>";
    
    for ($i = 1; $i <= $this->uri->total_segments(); $i++)
    {
      echo "<div>$i.&nbsp;&nbsp;" . $this->uri->segment($i) . "</div>";
    }

    echo "</div>";
  } // _remap
}
?&gt;

I ran some tests of this controller and here's the output I got:

1. With a URL of http://localhost/ci_playground/test/ I got the following output:

Code:
Class Test initialised
_remap invoked with the following arguments:
method: index
arg1: default
arg2: default2

Total URI segments: 1
The segments are:
1.  test

2. With a URL of http://localhost/ci_playground/test/mega/ I got the following output:

Code:
Class Test initialised
_remap invoked with the following arguments:
method: mega
arg1: default
arg2: default2

Total URI segments: 2
The segments are:
1.  test
2.  mega

3. With a URL of http://localhost/ci_playground/test/mega/trans/ I got the following output:

Code:
Class Test initialised
_remap invoked with the following arguments:
method: mega
arg1: default
arg2: default2

Total URI segments: 3
The segments are:
1.  test
2.  mega
3.  trans

4. With a URL of http://localhost/ci_playground/test/mega/trans/formers I got the following output:

Code:
Class Test initialised
_remap invoked with the following arguments:
method: mega
arg1: default
arg2: default2

Total URI segments: 4
The segments are:
1.  test
2.  mega
3.  trans
4.  formers

So the key functions here are:

Code:
$this->uri->total_segments()

and

$this->uri->segment(n)

where n is the segment whose value you want
#4

[eluser]Fierymind[/eluser]
very nice .. thank you very much.




Theme © iAndrew 2016 - Forum software by © MyBB