Bookmark web page using Codeigniter and jQuery

This tutorial shows how to bookmark a current URL. We have already built-in functionality in most of the browsers and we can bookmark a URL there but it’s also like you have to go to the menu option. The below code do the same thing just in one click on the web page. User is given a link to bookmark the current URL on any web page. This application logic is written in Codeigniter PHP framework but it’s very easy to understand the logic of the code and you can use the logic in simple PHP also. If you have any doubt or query then let me know.

Model

The below model class saves the bookmark info to the database table.

 

Controller

The below controller class holds the action method and gets executed when a user triggers click on the Bookmark link on a view.

 

View

In the view we need to place a link for allowing user click on the link to bookmark the URL. Generally the bookmark link should be placed on the template page but if you don’t use template page then don’t worry, you have to place bookmark link on every page wherever you want to place.

Step 1. include jQuery libraries in the header

 

Step 2. place the Bookmark link generally in the header section so that people can easily find the link.

The below line

 

In the above code snippets we have a hidden input field with security token value. This is needed only when we have changed the default value(FALSE) for csrf_protection to TRUE at location application/config/config.php

jQuery

This jquery part where actually the URL gets bookmarked and data gets saved to the database. We need the below jquery code when a user clicks on the Bookmark link to bookmark the URL.

 

In the above code everything is very easy to understand so I will not explain everything but a few.

 

In the above variable we don’t have index.php because index.php has been removed using htaccess file. For more information click on how to remove index.php.
We have blog segment in the above URL, it means it is the root directory of the project. We have bookmark segment in the URL, it means it is the controller name and after the controller name there is no more segment, so it means that the controller bookmark executes default action method index.

 

In the above code snippets we are fetching security token value. This is needed only when we have changed the default value(FALSE) for csrf_protection to TRUE for below line at location application/config/config.php

 

Thanks for your reading. Please do not forget to leave a comment.

Soumitra

Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.