Workflow of Codeigniter URLS

Posted By : Babbandeep Singh | 28-Apr-2018

URLs in CodeIgniter are created to be search-engine and human-friendly. Rather than adopting the standard “query string” method to URLs that are similar to dynamic methods, CodeIgniter applies a segment-based access.

 

EXAMPLE:
app.com/blogs/article/article_1

 

URI Segments
The segments in the URL, in supporting with the MVC procedure, normally describe:
app.com/class/function/ID

a. The first segment describes the controller class that should be requested.
b. The second segment describes the class function, or method, that should be requested.
c. The third and any further segments describe the ID and any variables that will be given to the controller.

 

The URI Helper and the URL Library include functions that make it simple to work with your URI data.

 

Here is an example of segments passed as an array using URL helper functions site_url():

$segments = array('blog', 'article', '1');
echo site_url($segments);
 
Output :
 http://app.com/index.php/blog/article/1

The URI Library gives methods that help in getting data from URI strings.
Like segment(); which allow getting a particular segment. Where n is the segment number you want to retrieve. Segments are counted from left to right. For example, if full URL is like this:
http://app.com/index.php/blog/article/codeigniter/example

 

The segment numbers would be this:
1. blog
2. article
3. CodeIgniter
4. example

 

The optional second parameter by defaults is NULL and lets you insert the return value of the method if missing the requested URI segment. For example, this would indicate the method to return the number 0 in the case of missing:

$product_id = $this->uri->segment(3, 0);

About Author

Author Image
Babbandeep Singh

Babbandeep has experience in web development focusing on HTML, CSS, Bootstrap, JavaScript, Jquery, WordPress, Codeigniter, Magento, PHP, and MySQL. In his free time, he likes to listen music.

Request for Proposal

Name is required

Comment is required

Sending message..