Welcome Guest, Not a member yet? Register   Sign In
Problem Passing Parameter directly to index
#1

[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 {

    function Projects()
    {
        parent::Controller();
        $this -> load -> scaffolding('projects');
        $this -> load -> helper('url');
    }
    
    function index()
    {
        $data['title'];
        $this->load->view('projects_page', $data);
    }
}
I have something like this, (code is cut here)
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)
    {
        $data['title'];
        $this->load->view('projects_page', $data);
    }
i Do this
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.
#2

[eluser]CoolGoose[/eluser]
Write a custom route in routes.php like

$route['projects/:any'] = "projects/index/$1";
#3

[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
#4

[eluser]chamil sanjeewa[/eluser]
try this
http://ellislab.com/forums/viewthread/94028/#477505




Theme © iAndrew 2016 - Forum software by © MyBB