How to use routing in codeigniter

in #utopian-io7 years ago (edited)

What Will I Learn?

  • You will learn Basic Routing
  • You will learn Create Routing
  • You will learn Use Routing

Requirements

  • Xampp
  • Sublime
  • Codeigniter

Difficulty

  • Basic

Tutorial How to run and create routing in codeigniter

A. Basic Route

  1. routing directory is on application/config/routes.php .
  2. the section of code $route['default_controller'] = 'welcome'; that shows on the default controller or controller that is first read by CI, default is there on the controller welcome . welcome is page.
  3. the section of code $route['404_override'] = '';are used to notify the CI if default controller can not be found or if there is a controller of others or other pages that are not found
  4. the section of code $route['translate_uri_dashes'] = FALSE; is working if you change the value TRUE, then you are allowed in a URL the browser you are writing a mark dash (-).

B. Create Route

Here are a few create routing :

$route['code'] = 'example';

A URL containing the word “code” in the first segment will be remapped to the “example” class.

$route['example/iwaydi'] = 'example/users/22';

A URL containing the segments example/iwaydi will be remapped to the “example” class and the “users” method. The ID will be set to “22”.

$route['product/(:any)'] = 'blogs/content';

A URL with “product” as the first segment, and anything in the second will be remapped to the “blogs” class and the “content” method.

$route['product/(:num)'] = 'blogs/content_id/$1';

A URL with “product” as the first segment, and a number in the second will be remapped to the “blogs” class and the “content_id” method passing in the match as a variable to the method.

Important

Do not use leading/trailing slashes.

C. Use Routing

  1. Open application/config/routes.php with sublime
    pic1.JPG

  2. You can edit welcome with your controller who want first show in website. I want first show is mypage
    pic2.JPG

  3. You can looking result my page here
    pic3.JPG

  4. If you want to display your own controller page of error. you can type your controller in the second code
    Pic4.JPG

  5. You can looking result notfound here
    image

Curriculum

** This is the first tutorial i'm contributing using Codeigniter.**



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Nice post man!
Just posted a similar php routing solution using Flight PHP, check out on my profile!

Your contribution cannot be approved because it is not as informative as other contributions. See the Utopian Rules. Contributions need to be informative and descriptive in order to help readers and developers understand them.

  • One tutorial must contain must contain more content then this. Only three functions have been explained ( description for which is already available in the docs.) Please make the tutorial moredescriptive and include must more steps and functionalities.

You can contact us on Discord.
[utopian-moderator]

I wonder what you are saying now. You will not talk about intigers in a routing tutorial. I liked what has been explained here.

Coin Marketplace

STEEM 0.23
TRX 0.22
JST 0.037
BTC 98709.14
ETH 3447.96
USDT 1.00
SBD 3.20