Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • routing in codeingiter

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 437
    Comment on it

    Hello Reader's, 

    If you are working on CodeIgniter Project and want to customize the pages URLs. Codeigniter offers you to do this by using it Routing function. The Routing the is method for hiding the controller and model functions from your url.

    Lets get started Routing in Codeigniter.

    Step 1:  Open the file routes.php. You can find this file at location Application-> Config->Routes.php

    Create a new route in this file which will go like this:-

    $route['myplace'] = 'User/myplace';

    In the code line above the User is your controller and myplace will be the function inside it. So if you have a place link target to this url then after making the route you just need to write 

    <a href = "<?php echo base_url().'myplace/';?>"> Myplace </a>

    while if you compare you old url which is like this:-

    <a href = "<?php echo base_url().'User/myplace';?>"> Myplace </a>

    You will notice that instead of writing full url of  Controller and Function you can just replace it with a single word. Both the link will open the same url but the new url will be more user and SEO friendly.

    Now lets say if you have any variable in the url segment then there is an another syntax that you need to specify.
    For example if your dynamic url is 

    yourdomain.com/User/city_id/1/
    Now here 3rd url is dynamically generated which is an int type. So for this type of url you need to create the route like this:-
    
    $route['city_id/:num'] = 'User/city_id';

    Similarly for multiple variables you can mention ( :num )multiple times and it will go like this:-

    $route['city_id/:num/:num/:num'] = 'User/city_id';

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: