Welcome Guest, Not a member yet? Register   Sign In
how to send parameter to index function
#1

[eluser]minhbu[/eluser]
I want to pass some parameter to index function. Who can help me ?
#2

[eluser]bmchild[/eluser]
You can use the URI method for passing parameters by using a URL like http://www.example.com/index.php/control...x/variable where you actually specify the index as the method to use.

then it should be accessible by the $this->uri->segment(3)
#3

[eluser]rt30000[/eluser]
I have used...
Code:
function index($id=0) // Specify a default parameter value if none is supplied to avoid php undefined var error
{
   // Code....
   if ($id <> 0)
   {
     // A parameter value has been passed
     echo $id;
   }
}
...where $id is the parameter passed, and 0 is the default value if none is specified (or else you will get an 'undefined' php error).

This should be right, I just wrote it real quick but use something similar in my application.
#4

[eluser]minhbu[/eluser]
thanks everybody.
i use
http://www.example.com/index.php/control...x/variable =>good

but http://www.example.com/index.php/controller/variable =>badly. I want to use this style
#5

[eluser]Colin Williams[/eluser]
Implementing a _remap(), in the Controller that needs this, is another way to achieve this. Look at the Controllers page in the User Guide or search this forum for "_remap" if you want more info.
#6

[eluser]minhbu[/eluser]
i have a link
http://localhost/blog/westlife
i want to write this url to browse it will display blog of westlife
http://localhost/blog/listblog
when i write this url to browse it will display manager blog part
how can i do it ??
Help me !
#7

[eluser]JoostV[/eluser]
You can setup custom routing in /config/routes.php. Have a look at the user guide, it's all in there. Use either wildcards or regular expressions. Set the rules that must be checked first on top.

Code:
$route['blog/listblog'] = 'blog/manager'; // If a URI starts with blog/manager it will be redirected here
$route['blog/(.*)'] = "blog/show/$1"; // Any other URI that starts with blog/ will be redirected here

Note: in controller blog/show(), the parameter 'westlife' will be available in segment 2, because that is where it is in the actual URI.
#9

[eluser]ducuytran[/eluser]
[quote author="bmchild" date="1224195575"]You can use the URI method for passing parameters by using a URL like http://www.example.com/index.php/control...x/variable where you actually specify the index as the method to use.

then it should be accessible by the $this->uri->segment(3)[/quote]

Thanks bmchild!
My case:
... admincp/gallery/(:any)

With gallery is a controller, so my index() will be like this:

function index() {
$par = $this->uri->segment(3);
//Watever you wanna do with that $par
...
}
#10

[eluser]flackend[/eluser]
In the past I've use the _remap() function until I realize I could use routes:

Code:
$route['controller/(:any)']        = 'controller/index/$1';
$route['controller/(:any)/(:any)'] = 'controller/index/$1/$2';




Theme © iAndrew 2016 - Forum software by © MyBB