how to send parameter to index function |
[eluser]minhbu[/eluser]
I want to pass some parameter to index function. Who can help me ?
[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)
[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 This should be right, I just wrote it real quick but use something similar in my application.
[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
[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.
[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 !
[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 Note: in controller blog/show(), the parameter 'westlife' will be available in segment 2, because that is where it is in the actual URI.
[eluser]minhbu[/eluser]
http://localhost/blog/listblog Listbog it is a function and same functions have hot very much. So this way....... ex http://localhost/blog/insertblog http://localhost/blog/editblog http://localhost/blog/insertsong http://localhost/blog/insertalbum http://localhost/blog/listalbum http://localhost/blog/listsong.. ......... and http://localhost/blog/westlfie westlife i get from databse ex http://localhost/blog/abba http://localhost/blog/backstreetboy.... ............
[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 ... }
[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'; |
Welcome Guest, Not a member yet? Register Sign In |