Problem Passing Parameter directly to index |
[eluser]Unknown[/eluser]
Hi everyone, I'm new to CI Community I reviewed some codes provided in CI and like it very much. and started using CI in my projects. I have a little problem Code: class Projects extends Controller { so in address bar i receive http://example.com/projects/ everything ok here. now i just want to get something like this http://example.com/projects/project_name1 http://example.com/projects/project_name2 http://example.com/projects/project_name3 and so on i don't want to create another functions for every project that will be in my portfolio. I just want to pass parameter to index function Code: function index($id) but http://example.com/projects/project_name1 but it doesn't work this way it works with "index" in uri http://example.com/projects/index/project_name1 this way "project_name1" becomes parameter for this function I don't want "index" to be in URL how to solve this problem ? there is another way if i add another function for example "viewproject" and there i can recieve anything in parameter for this function but i don't like this style. Sincerely Yours Nodar.
[eluser]CoolGoose[/eluser]
Write a custom route in routes.php like $route['projects/:any'] = "projects/index/$1";
[eluser]Unknown[/eluser]
Thanks for the answer Routes are great thing i just looked to it. But, $route['projects/:any'] = "projects/index/$1"; this still doesn't work yes the parameter is passed but instead of parameter $1 < this is shown oh yes, i understood just after looking through routes article in user_guide thank you very much $route['projects/(:any)'] = "projects/viewproject/$1"; it's the correct way you just missed "()" this slashes
|
Welcome Guest, Not a member yet? Register Sign In |