Codeigniter Tutorials
- What is codeigniter?
- Application_Architecture
- MVC Architecture
- HMVC Architecture
- Codeigniter Configuration
- Remove index.php from url in codeigniter
- MVC Concept
- View
- Alternate PHP Syntax for View Files
- Routing
- Codeigniter URL
- Get Current URL
- Previous page URL get
- Seo Friendly URL
- Slug Create in codeigniter
- What is _remap() function
- Remove controller name from url in codeigniter
- Codeigniter Controller Class
- Class Constructor
- GET $ POST method in Codeigniter
- Models
- Basepath, Apppath, FCPATH
- URI Segment
- Page Redirect
- Helper class
- Custom Helper class
- Form Helper
- Common Helper Functions
- Common Function
- Array Problems
- Call controller in Helper
- Add active class to menu using Helper class
- Custom Library
- Custom Library Example
- when to use get_instance()
- Codeigniter Hook
- how to work inline css in codeigniter
- Custom 404 page
- 404 custom error page
- Create custom config file in codeigniter
- How to set and get config item value
- How to Speed Up CodeIgniter App?
- Codeigniter Functions
- Session
- cookies
- How to Set & Get Tempdata in Codeigniter
- flash messages in Codeigniter
- Flashdata
- Encryption and Decryption In CodeIgniter
- Codeigniter security
- csrf token form security
- Password Hashing
- Form Validation
- Custom Validation
- Registration Form with validation
- Server Side Form Validation
- Validate Select Option Field
- Date Format Validation
- Date Format change in codeigniter
- Date Functions
- DOB Validation
- CI CRUD
- User SignUp
- User Login
- User Logout
- Login Account
- Login form with RememberMe
- Login Form with session
- User change password
- Change Password with Callback Validation to Check Old Password
- Forgot password
- Reset password
- Insert data in database
- Fetch data from database
- Update data in database
- Delete data in database
- File Upload
- Image Upload with resize Image
- Upload Multiple file and images
- Upload Multiple images with CRUD
- File and image update
- Upload Image Using Ajax.
- Email Send
- Email Send Using Email library
- Email Send Using SMTP Gmail
- Notification send
- store data in json format in DB
- Json parse
- Fetch data Using Ajax with Json data
- How to Show data Using Ajax with Json parse
- Get JSON Data from PHP Script using jQuery Ajax
- Insert data Using Ajax
- Submit data Using Ajax with form validation
- How to show data Using Ajax in codeigniter
- Insert & Update Using Ajax
- Registration Form With Validation Using Ajax in codeigniter
- Delete data Using Ajax Confirmation
- Delete All data Using checkbox selection
- Ajax CSRF Token
- Ajax Post
- Ajax serverside form validation
- Contact form using AJAX with form validation
- DataTable Using Ajax dynamically
- DataTables pagination using AJAX with Custom filter
- DataTables AJAX Pagination with Search and Sort in codeigniter
- DataTables in Codeigniter using Ajax
- Ajax Custom Serarch
- Ajax Live Data Search using Jquery PHP MySql
- Ajax Custom Serarch and sorting in datatable
- Dynamic Search Using Ajax
- Autocomplete using jquery ajax
- Jquery Ajax Autocomplete Search using Typeahead
- Dynamic Dependent Dropdown Using Ajax
- Dynamic Dependent Dropdown list Using Ajax
- Dynamic Dependent Dropdown in codeigniter using Ajax
- ajax username/email availability check using JQuery
- Check Email Availability Using Ajax
- Data Load on mouse scroll
- Ajax CI Pagination
- Pagination in codeigniter
- Ajax Codeigniter Pagination
- email exists or not using ajax with json
- CRUD using AJAX With Modal popup in CI
- Add / Show Data on modal popup using Ajax
- Modal popup Validation using Ajax
- Data show on Modal popup Using Ajax
- Add / Remove text field dynamically using jquery ajax
- How to Add/Delete Multiple HTML Rows using JavaScript
- Delete Multiple Rows using Checkbox
- Multiple Checkbox value
- Form submit using jquery Example
- REST & SOAP API
- Multi-Language implementation in CodeIgniter
- How to pass multiple array in view
- Captcha
- create zip file and download
- PhpOffice PhpSpreadsheet Library (Export data in excel sheet)
- data export in excel sheet
- Excel File generate in Codeigniter using PHPExcel
- Dompdf library
- tcpdf library
- Html table to Excel & docs download
- CI Database Query
- Database Query
- SQL Injection Prevention
- Auth Model
- Join Mysql
- Tree View in dropdown option list
- OTP Integration in codeigniter
- curl post
- download file using curl
- Sweet Alert
- Sweet alert Delete & Success
- Log Message in Codeigniter
- Menu & Submenu show dynamically
- Set Default value in input box
- Cron Jobs
- Stored Procedure
- Display Loading Image when AJAX call is in Progress
- Send SMS
- IP Address
- Codeigniter Tutorialspoint
- Website Link
- How To Create Dynamic Xml Sitemap In Codeigniter
- Paypal Payment Integration
- Get Latitude and Longitude From Address in Codeigniter Using google map API
- How To Create Simple Bar Chart In Codeigniter Using AmCharts?
- dynamic Highcharts in Codeigniter
- Barcode in Codeigniter
- Codeigniter Interview Questions
- Project
What is Codeigniter URL?
By default, URLs in CodeIgniter are designed to be search-engine and human friendly. CodeIgniter uses a segment-based approach: http://itechtuto.com/news/article/my_article
Note : Query string URLs can be optionally enabled, as described below.
URI Segments
The segments in the URL, in following with the Model-View-Controller approach, usually represent: http://itechtuto.com/class-name/function-name/ID
The URI Library and the URL Helper contain functions that make it easy to work with your URI data. In addition, your URLs can be remapped using the URI Routing feature for more flexibility.
Removing the index.php file
By default, the index.php file will be included in your URLs: http://itechtuto.com/index.php/news/article/my_article
If your Apache server has mod_rewrite enabled, you can easily remove this file by using a .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
OR
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /bindaasraho
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
This code should be written in .htaccess file in Application directory.
Note : These specific rules might not work for all server configurations.
Adding a URL Suffix
In your config/config.php file you can specify a suffix that will be added to all URLs generated by CodeIgniter. Ex:
https://itechtuto.com/user_guide/general/urls
You can optionally add a suffix, like .html, making the page appear to be of a certain type:
https://itechtuto.com/user_guide/general/urls.html
$config['url_suffix'] = '';
Enabling Query Strings
In some cases you might prefer to use query strings URLs:
index.php?c=products&m=view&id=345
CodeIgniter optionally supports this capability, which can be enabled in your application/config.php file. If you open your config file you’ll see these items:
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
If you change “enable_query_strings” to TRUE this feature will become active. Your controllers and functions will then be accessible using the “trigger” words you’ve set to invoke your controllers and methods:
index.php?c=controller&m=method
Note :
If you are using query strings you will have to build your own URLs, rather than utilizing the URL helpers (and other helpers that generate URLs, like some of the form helpers) as these are designed to work with segment based URLs.
Basic URL structure
http://itechtuto.com/class_name/function_name/id
What is site_url();
You can pass a string or an array in a site_url() function. In this example we'll pass a string,
echo site_url('book/novel/fiction');
The above function will return something like this
http://abc.com/index.php/book/novel/fiction
In this example we'll pass an array,
$data = array('book', 'novel', 'fiction');
echo site_url($data);
What is base_url();
It returns your site base URL, if mentioned any, in the config file. On passing base_url(), it also returns the same thing as site_url() with eliminating index.php. This is useful because here you can also pass images or text files. Here also you can pass a string or an array.
In this example we'll pass a string,
echo base_url("book/novel/fiction");
The above function will return something like this http://abc.com/ book/novel/fiction
In order to use base_url(), you must first have the URL Helper loaded. This can be done either in application/config/autoload.php
$autoload['helper'] = array('url');
Or, manually:
$this->load->helper('url');
Once it's loaded, be sure to keep in mind that base_url() doesn't implicitly print or echo out anything, rather it returns the value to be printed:
echo base_url();
Remember also that the value returned is the site's base url as provided in the config file. CodeIgniter will accomodate an empty value in the config file as well:
If this (base_url) is not set then CodeIgniter will guess the protocol, domain and path to your installation.
application/config/config.php, line 13
If you want to use base_url(), so we need to load url helper.
By using autoload $autoload['helper'] = array('url');
Or by manually load in controller or in view $this->load->helper('url');
Then you can user base_url() anywhere in controller or view.
what is difference between site_url() and base_url().
echo base_url(); // http://example.com/website
echo site_url(); // http://example.com/website/index.php
if you want a URL access to a resource (such as css, js, image), use base_url(), otherwise, site_url() is better.
The purpose of site_url is that your pages become more portable in the event your URL changes.The site_url appears with the index.php file.
Segments can be optionally passed to the function as a string or an array.
echo site_url("news/local/123");
it will give: http://ci.com/index.php/news/local/123
you can even pass segments as an array:
$segments = array('news', 'local', '123');
echo site_url($segments);
base_url is without the index_page or url_suffix being appended. like site_url, you can supply segments as a string or an array.
If you want a URL access to a resource use base_url you can supply a string to a file, such as an image or stylesheet else site_url is enough.
echo base_url("/images/icons/image.png");
What is uri_string();
It returns the URI segment of a page. For example, if your URL is,
http://abc.com/book/novel/fiction
Then, uri_string() will return
Book/novel/fiction
What is current_url();
Calling this function means, it will return the full URL of the page currently viewed.
Please note -> calling this function is same as calling uri_string() in site_url().
current_url() = site_url(uri_string());
What is index_page();
It will return your site's index_page which you have mentioned in your config file. By default, it is always index.php file.
You can change it with the help of .htaccess file.
what is anchor() method.
It creates a standard HTML link based on your local site URL. For example,
Echo anchor('book/novel/fiction', 'my itechtuto', 'title="book name");
It will give the following result,
echo anchor('controller/function/parameter', 'Link Text');
// Link Text
anchor tag with additional attributes.
echo anchor('controller/function/parameter', 'Link with Title attribute',array('title'=>'Link Title'));
// <a href="http://example.com/index.php/controller/function/parameter" title="Link Title">Link with Title attribute</a>
anchor_popup()
It is identical to anchor() but it opens the URL in a new window.
Below examples show links with site_url() function
<a href="<?php echo site_url('controller/function/parameter'); ?>">Link Title</a>
//<a href="http://example.com/index.php/controller/function/parameter">Link Title</a>
<a href="<?php echo site_url('controller/function/parameter1'); ?>/parameter2">Link Title</a>
//<a href="http://example.com/index.php/controller/function/parameter1/parameter2">Link Title</a>
<a href="<?php echo site_url('controller/function/parameter'); ?>" title="title attributes ">Link Title</a>
// <a href="http://example.com/index.php/controller/function/parameter" title="title attributes">Link with Title attribute</a>
mailto()
It creates a HTML email link. For example,
Echo mailto('info@itechtuto.com', 'To contact me click here')
url_title()
It takes a string as an input and creates a human friendly environment. For example,
$title = "CodeIgniter's examples"
$url_title() = url_title($title);
Output will be "CodeIgniters-examples"
If you'll pass a second parameter, it defines word delimiter.
$title = "CodeIgniter's examples"
$url_title() = url_title($title, '_');
Output will be "CodeIgniters_examples"
If you'll pass a third parameter, it defines uppercase and lowercase. You have Boolean options for this, TRUE/FALSE.
$title = "CodeIgniter's examples"
$url_title() = url_title($title, '_', TRUE);
Output will be "codeigniters_examples"
NOTE :-
site_url() : Returns your site URL, as specified in your config file. The index.php file (or whatever you have set as your site index_page in your config file) will be added to the URL, as will any URI segments you pass to the function, and the url_suffix as set in your config file.
base_url() : Returns your site base URL, as specified in your config file,This function returns the same thing as site_url, without the index_page or url_suffix being appended.This method is suitable for creating Style Sheet links , Script links and image links.
anchor() : anchor() function create the links,[anchor(uri segments, text, attributes)] If you are building links that are internal to your application do not include the base URL (http://…). This will be added automatically from the information specified in your config file. Include only the URI segments you wish appended to the URL.