Skip to content

How to create links in codeigniter?

This Post is About Creating Links in CodeIgniter, To Create Links in CodeIgniter you have to load CI URL Helper,

How to load CI’s URL Helper:
with very simple line of code, you can load CodeIgniter Helper , here is the example :

$this->load->helper('url');

How to Crate Links:
You can use fallowing codeingiter’s methods to create links : base_url() and site_url(), anchor()

below example shows how to make links with anchor method:

 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')); 
// Link with Title attribute

Below examples show links with site_url() function

Link Title 
//Link Title 
 
Link Title 
//Link Title
 
Link Title 
// Link with Title attribute

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.

If you have any queries you can mail me.

0 0 votes
Article Rating
Subscribe
Notify of
guest

9 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments