CodeIgniter – Page Redirection

CodeIgniter – Page Redirection ”; Previous Next While building web application, we often need to redirect the user from one page to another page. CodeIgniter makes this job easy for us. The redirect() function is used for this purpose. Syntax redirect($uri = ””, $method = ”auto”, $code = NULL) Parameters $uri (string) − URI string $method (string) − Redirect method (‘auto’, ‘location’ or ‘refresh’) $code (string) − HTTP Response code (usually 302 or 303) Return type void The first argument can have two types of URI. We can pass full site URL or URI segments to the controller you want to direct. The second optional parameter can have any of the three values from auto, location or refresh. The default is auto. The third optional parameter is only available with location redirects and it allows you to send specific HTTP response code. Example Create a controller called Redirect_controller.php and save it in application/controller/Redirect_controller.php <?php class Redirect_controller extends CI_Controller { public function index() { /*Load the URL helper*/ $this->load->helper(”url”); /*Redirect the user to some site*/ redirect(”https://www.tutorialspoint.com”); } public function computer_graphics() { /*Load the URL helper*/ $this->load->helper(”url”); redirect(”https://www.tutorialspoint.com/computer_graphics/index.htm”); } public function version2() { /*Load the URL helper*/ $this->load->helper(”url”); /*Redirect the user to some internal controller’s method*/ redirect(”redirect/computer_graphics”); } } ?> Change the routes.php file in application/config/routes.php to add route for the above controller and add the following line at the end of the file. $route[”redirect”] = ”Redirect_controller”; $route[”redirect/version2”] = ”Redirect_controller/version2”; $route[”redirect/computer_graphics”] = ”Redirect_controller/computer_graphics”; Type the following URL in the browser, to execute the example. http://yoursite.com/index.php/redirect The above URL will redirect you to the tutorialspoint.com website and if you visit the following URL, then it will redirect you to the computer graphics tutorial at tutorialspoint.com. http://yoursite.com/index.php/redirect/computer_graphics Print Page Previous Next Advertisements ”;

CodeIgniter – Tempdata

CodeIgniter – Tempdata ”; Previous Next In some situations, where you want to remove data stored in session after some specific time-period, this can be done using tempdata functionality in CodeIgniter. Add Tempdata To add data as tempdata, we have to use mark_as_tempdata() function. This function takes two argument items or items to be stored as tempdata and the expiration time for those items are as shown below. // ”item” will be erased after 300 seconds(5 minutes) $this->session->mark_as_temp(”item”,300); You can also pass an array to store multiple data. All the items stored below will be expired after 300 seconds. $this->session->mark_as_temp(array(”item”,”item2”),300); You can also set different expiration time for each item as shown below. // ”item” will be erased after 300 seconds, while ”item2” // will do so after only 240 seconds $this->session->mark_as_temp(array( ”item”=>300, ”item2”=>240 )); Retrieve Tempdata We can retrieve the tempdata using tempdata() function. This function assures that you are getting only tempdata and not any other data. Look at the example given below to see how to retrieve tempdata. tempdata() function will take one argument of the item to be fetched. $this->session->tempdata(”item”); If you omit the argument, then you can retrieve all the existing tempdata. Remove Tempdata Tempdata is removed automatically after its expiration time but if you want to remove tempdata before that, then you can do as shown below using the unset_tempdata() function, which takes one argument of the item to be removed. $this->session->unset_tempdata(”item”); Example Create a class called Tempdata_controller.php and save it in application/controller/Tempdata_controller.php. <?php class Tempdata_controller extends CI_Controller { public function index() { $this->load->library(”session”); $this->load->view(”tempdata_view”); } public function add() { $this->load->library(”session”); $this->load->helper(”url”); //tempdata will be removed after 5 seconds $this->session->set_tempdata(”item”,”item-value”,5); redirect(”tempdata”); } } ?> Create a file called tempdata_view.php and save it in application/views/tempdata_view.php <!DOCTYPE html> <html lang = “en”> <head> <meta charset = “utf-8″> <title>CodeIgniter Tempdata Example</title> </head> <body> Temp Data Example <h2><?php echo $this->session->tempdata(”item”); ?></h2> <a href = ”tempdata/add”>Click Here</a> to add temp data. </body> </html> Make the changes in the routes.php file in application/config/routes.php and add the following line at the end of the file. $route[”tempdata”] = “Tempdata_controller”; $route[”tempdata/add”] = “Tempdata_controller/add”; Execute the above example by visiting the following link. Replace the yoursite.com with the URL of your site. http://yoursite.com/index.php/tempdata After visiting the above URL, you will see a screen as shown below. Click on “Click Here” link and you will see a screen as shown below. Here, in this screen you will see a value of temp data variable. Refresh the same page after five seconds again as we have set the temp data for five seconds and you will see a screen like above and temp data variable will be removed automatically after five seconds. If you refresh the same page before 5 seconds, then the temp data will not be removed, as the time period is not over. Destroying a Session In PHP, we are using the session_destroy() function to destroy the session and in CodeIgniter we can destroy the function as shown below. $this->session->sess_destroy(); After calling this function, all the session data including the flashdata and tempdata will be deleted permanently and cannot be retrieved back. Print Page Previous Next Advertisements ”;

CodeIgniter – Common Functions

CodeIgniter – Common Functions ”; Previous Next CodeIgniter library functions and helper functions need to be initialized before they are used but there are some common functions, which do not need to be initialized. These common functions and their descriptions are given below. Syntax is_php($version) Parameters $version (string) − Version number Return TRUE if the running PHP version is at least the one specified or FALSE if not Return Type void Description Determines if the PHP version being used is greater than the supplied version number. Syntax is_really_writable($file) Parameters $file (string) − File path Return TRUE if the path is writable, FALSE if not Return Type bool Description checks to see if file is writable or not. Syntax config_item($key) Parameters $key (string) − Config item key Return Configuration key value or NULL if not found Return Type mixed Description This function is used to get the configuration item Syntax set_status_header($code[, $text = ””]) Parameters $code (int) − HTTP Response status code $text (string) − A custom message to set with the status code Return Return Type void Description This function permits you to manually set a server status header. Syntax remove_invisible_characters($str[, $url_encoded = TRUE]) Parameters $str (string) − Input string $url_encoded (bool) − Whether to remove URLencoded characters as well Return Sanitized string Return Type string Description This function prevents inserting NULL characters between ASCII characters Syntax html_escape($var) Parameters $var (mixed) − Variable to escape (string or array) Return HTML escaped string(s) Return Type mixed Description This function acts as a native PHP htmlspecialchars() function. Syntax get_mimes() Return An associative array of file types Return Type array Description This function returns a reference to the MIMEs array from application/config/mimes.php. Syntax is_https() Return TRUE if currently using HTTP-over-SSL, FALSE if not Return Type bool Description Returns TRUE if a secure (HTTPS) connection is used and FALSE in any other case (including non-HTTP requests). Syntax is_cli() Return TRUE if currently running under CLI, FALSE otherwise Return Type bool Description Returns TRUE if the application is run through the command line and FALSE if not. Syntax function_usable($function_name) Parameters $function_name (string) − Function name Return Type bool Description Returns TRUE if a function exists and is usable, FALSE otherwise. Given below is an example, which demonstrates all of the above functions. Example Here we have created only one controller in which we will use the above functions. Copy the below given code and save it at application/controller/CommonFun_Controller.php. <?php class CommonFun_Controller extends CI_Controller { public function index() { set_status_header(200); echo is_php(”5.3”).”<br>”; var_dump(is_really_writable(”./Form.php”)); echo config_item(”language”).”<br>”; echo remove_invisible_characters(”This is a ‌test”,”UTF8”).”<br>”; $str = ”< This > is ” a ” test & string”; echo html_escape($str).”<br>”; echo “is_https():”.var_dump(is_https()).”<br>”; echo “is_cli():”.var_dump(is_cli()).”<br>”; var_dump(function_usable(”test”)).”<br>”; echo “get_mimes():”.print_r(get_mimes()).”<br>”; } public function test() { echo “Test function”; } } ?> Change the routes.php file at application/config/routes.php to add route for the above controller and add the following line at the end of the file. $route[”commonfunctions”] = ”CommonFun_Controller”; Type the following URL in the address bar of your browser to execute the example. http://yoursite.com/index.php/commonfunctions Print Page Previous Next Advertisements ”;

CodeIgniter – File Uploading

CodeIgniter – File Uploading ”; Previous Next Using File Uploading class, we can upload files and we can also, restrict the type and size of the file to be uploaded. Follow the steps shown in the given example to understand the file uploading process in CodeIgniter. Example Copy the following code and store it at application/view/Upload_form.php. <html> <head> <title>Upload Form</title> </head> <body> <?php echo $error;?> <?php echo form_open_multipart(”upload/do_upload”);?> <form action = “” method = “”> <input type = “file” name = “userfile” size = “20” /> <br /><br /> <input type = “submit” value = “upload” /> </form> </body> </html> Copy the code given below and store it at application/view/Upload_success.php <html> <head> <title>Upload Form</title> </head> <body> <h3>Your file was successfully uploaded!</h3> <ul> <?phpforeach ($upload_data as $item => $value):?> <li><?php echo $item;?>: <?php echo $value;?></li> <?phpendforeach; ?> </ul> <p><?php echo anchor(”upload”, ”Upload Another File!”); ?></p> </body> </html> Copy the code given below and store it at application/controllers/Upload.php. Create “uploads” folder at the root of CodeIgniter i.e. at the parent directory of application folder. <?php class Upload extends CI_Controller { public function __construct() { parent::__construct(); $this->load->helper(array(”form”, ”url”)); } public function index() { $this->load->view(”upload_form”, array(”error” => ” ” )); } public function do_upload() { $config[”upload_path”] = ”./uploads/”; $config[”allowed_types”] = ”gif|jpg|png”; $config[”max_size”] = 100; $config[”max_width”] = 1024; $config[”max_height”] = 768; $this->load->library(”upload”, $config); if ( ! $this->upload->do_upload(”userfile”)) { $error = array(”error” => $this->upload->display_errors()); $this->load->view(”upload_form”, $error); } else { $data = array(”upload_data” => $this->upload->data()); $this->load->view(”upload_success”, $data); } } } ?> Make the following change in the route file in application/config/routes.php and add the following line at the end of file. $route[”upload”] = ”Upload”; Now let us execute this example by visiting the following URL in the browser. Replace the yoursite.com with your URL. http://yoursite.com/index.php/upload It will produce the following screen − After successfully uploading a file, you will see the following screen − Print Page Previous Next Advertisements ”;

CodeIgniter – Error Handling

CodeIgniter – Error Handling ”; Previous Next Many times, while using application, we come across errors. It is very annoying for the users if the errors are not handled properly. CodeIgniter provides an easy error handling mechanism. You would like the messages to be displayed, when the application is in developing mode rather than in production mode as the error messages can be solved easily at the developing stage. The environment of your application can be changed, by changing the line given below from index.php file. This can be set to anything but normally there are three values (development, test, production) used for this purpose. define(”ENVIRONMENT”, isset($_SERVER[”CI_ENV”]) ? $_SERVER[”CI_ENV”] : ”development”); Different environment will require different levels of error reporting. By default, development mode will display errors and testing and live mode will hide them. CodeIgniter provides three functions as shown below to handle errors. show_error() function displays errors in HTML format at the top of the screen. Syntax show_error($message, $status_code, $heading = ”An Error Was Encountered”) Parameters $message (mixed) − Error message $status_code (int) − HTTP Response status code $heading (string) − Error page heading Return Type mixed show_404() function displays error if you are trying to access a page which does not exist. Syntax show_404($page = ””, $log_error = TRUE) Parameters $page (string) – URI string $log_error (bool) – Whether to log the error Return Type void log_message() function is used to write log messages. This is useful when you want to write custom messages. Syntax log_message($level, $message, $php_error = FALSE) Parameters $level (string) − Log level: ‘error’, ‘debug’ or ‘info’ $message (string) − Message to log $php_error (bool) − Whether we’re logging a native PHP error message Return Type void Logging can be enabled in application/config/config.php file. Given below is the screenshot of config.php file, where you can set threshold value. /* |——————————————————————————– | Error Logging Threshold |——————————————————————————– | You can enable error logging by setting a threshold over zero. The | threshold determines what gets logged. Threshold options are: | | 0 = Disable logging, Error logging TURNED OFF | 1 = Error Message (including PHP errors) | 2 = Debug Message | 3 = Informational Messages | 4 = All Messages | | You can also pass an array with threshold levels to show individual error types | | array(2) = Debug Message, without Error Messages | For a live site you”ll usually only enable Errors (1) to be logged otherwise | your log files will fill up very fast. | */ $config[”log_threshold”] = 0; You can find the log messages in application/log/. Make sure that this directory is writable before you enable log files. Various templates for error messages can be found in application/views/errors/cli or application/views/errors/html. Print Page Previous Next Advertisements ”;

CodeIgniter – Page Caching

CodeIgniter – Page Caching ”; Previous Next Caching a page will improve the page load speed. If the page is cached, then it will be stored in its fully rendered state. Next time, when the server gets a request for the cached page, it will be directly sent to the requested browser. Cached files are stored in application/cache folder. Caching can be enabled on per page basis. While enabling the cache, we need to set the time, until which it needs to remain in cached folder and after that period, it will be deleted automatically. Enable Caching Caching can be enabled by executing the following line in any of the controller’s method. $this->output->cache($n); Where $n is the number of minutes, you wish the page to remain cached between refreshes. Disable Caching Cache file gets deleted when it expires but when you want to delete it manually, then you have to disable it. You can disable the caching by executing the following line. // Deletes cache for the currently requested URI $this->output->delete_cache(); // Deletes cache for /foo/bar $this->output->delete_cache(”/foo/bar”); Example Create a controller called Cache_controller.php and save it in application/controller/Cache_controller.php <?php class Cache_controller extends CI_Controller { public function index() { $this->output->cache(1); $this->load->view(”test”); } public function delete_file_cache() { $this->output->delete_cache(”cachecontroller”); } } ?> Create a view file called test.php and save it in application/views/test.php <!DOCTYPE html> <html lang = “en”> <head> <meta charset = “utf-8″> <title>CodeIgniter View Example</title> </head> <body> CodeIgniter View Example </body> </html> Change the routes.php file in application/config/routes.php to add route for the above controller and add the following line at the end of the file. $route[”cachecontroller”] = ”Cache_controller”; $route[”cachecontroller/delete”] = ”Cache_controller/delete_file_cache”; Type the following URL in the browser to execute the example. http://yoursite.com/index.php/cachecontroller After visiting the above URL, you will see that a cache file for this will be created in application/cache folder. To delete the file, visit the following URL. http://yoursite.com/index.php/cachecontroller/delete Print Page Previous Next Advertisements ”;

CodeIgniter – Home

CodeIgniter Tutorial PDF Version Quick Guide Resources Job Search Discussion CodeIgniter is a powerful PHP framework with a very small footprint, built for developers who need a simple and elegant toolkit to create full-featured web applications. CodeIgniter was created by EllisLab, and is now a project of the British Columbia Institute of Technology. Audience This tutorial has been prepared for developers who would like to learn the art of developing websites using CodeIgniter. It provides a complete understanding of this framework. Prerequisites Before you start proceeding with this tutorial, we assume that you are already exposed to HTML, Core PHP, and Advance PHP. We have used CodeIgniter version 3.0.1 in all the examples. Print Page Previous Next Advertisements ”;

CodeIgniter – Working with Database

CodeIgniter – Working with Database ”; Previous Next Like any other framework, we need to interact with the database very often and CodeIgniter makes this job easy for us. It provides rich set of functionalities to interact with database. In this section, we will understand how the CRUD (Create, Read, Update, Delete) functions work with CodeIgniter. We will use stud table to select, update, delete, and insert the data in stud table. Table Name: stud roll_no int(11) name varchar(30) Connecting to a Database We can connect to database in the following two way − Automatic Connecting − Automatic connection can be done by using the file application/config/autoload.php. Automatic connection will load the database for each and every page. We just need to add the database library as shown below − $autoload[”libraries”] = array(‘database’); Manual Connecting − If you want database connectivity for only some of the pages, then we can go for manual connecting. We can connect to database manually by adding the following line in any class. $this->load->database(); Here, we are not passing any argument because everything is set in the database config file application/config/database.php Inserting a Record To insert a record in the database, the insert() function is used as shown in the following table − Syntax insert([$table = ””[, $set = NULL[, $escape = NULL]]]) Parameters $table (string) − Table name $set (array) − An associative array of field/value pairs $escape (bool) − Whether to escape values and identifiers Returns TRUE on success, FALSE on failure Return Type bool The following example shows how to insert a record in stud table. The $data is an array in which we have set the data and to insert this data to the table stud, we just need to pass this array to the insert function in the 2nd argument. $data = array( ”roll_no” => ‘1’, ”name” => ‘Virat’ ); $this->db->insert(“stud”, $data); Updating a Record To update a record in the database, the update() function is used along with set() and where() functions as shown in the tables below. The set() function will set the data to be updated. Syntax set($key[, $value = ””[, $escape = NULL]]) Parameters $key (mixed) − Field name, or an array of field/value pairs $value (string) − Field value, if $key is a single field $escape (bool) − Whether to escape values and identifiers Returns CI_DB_query_builder instance (method chaining) Return Type CI_DB_query_builder The where() function will decide which record to update. Syntax where($key[, $value = NULL[, $escape = NULL]]) Parameters $key (mixed) − Name of field to compare, or associative array $value (mixed) − If a single key, compared to this value $escape (bool) − Whether to escape values and identifiers Returns DB_query_builder instance Return Type object Finally, the update() function will update data in the database. Syntax update([$table = ””[, $set = NULL[, $where = NULL[, $limit = NULL]]]]) Parameters $table (string) − Table name $set (array) − An associative array of field/value pairs $where (string) − The WHERE clause $limit (int) − The LIMIT clause Returns TRUE on success, FALSE on failure Return Type bool $data = array( ”roll_no” => ‘1’, ”name” => ‘Virat’ ); $this->db->set($data); $this->db->where(“roll_no”, ‘1’); $this->db->update(“stud”, $data); Deleting a Record To delete a record in the database, the delete() function is used as shown in the following table − Syntax delete([$table = ””[, $where = ””[, $limit = NULL[, $reset_data = TRUE]]]]) Parameters $table (mixed) − The table(s) to delete from; string or array $where (string) − The WHERE clause $limit (int) − The LIMIT clause $reset_data (bool) − TRUE to reset the query “write” clause Returns CI_DB_query_builder instance (method chaining) or FALSE on failure Return Type mixed Use the following code to to delete a record in the stud table. The first argument indicates the name of the table to delete record and the second argument decides which record to delete. $this->db->delete(“stud”, “roll_no = 1″); Selecting a Record To select a record in the database, the get function is used, as shown in the following table − Syntax get([$table = ””[, $limit = NULL[, $offset = NULL]]]) Parameters $table (string) − The table to query array $limit (int) − The LIMIT clause $offset (int) − The OFFSET clause Returns CI_DB_result instance (method chaining) Return Type CI_DB_result Use the following code to get all the records from the database. The first statement fetches all the records from “stud” table and returns the object, which will be stored in $query object. The second statement calls the result() function with $query object to get all the records as array. $query = $this->db->get(“stud”); $data[”records”] = $query->result(); Closing a Connection Database connection can be closed manually, by executing the following code − $this->db->close(); Example Create a controller class called Stud_controller.php and save it at application/controller/Stud_controller.php Here is a complete example, wherein all of the above-mentioned operations are performed. Before executing the following example, create a database and table as instructed at the starting of this chapter and make necessary changes in the database config file stored at application/config/database.php <?php class Stud_controller extends CI_Controller { function __construct() { parent::__construct(); $this->load->helper(”url”); $this->load->database(); } public function index() { $query = $this->db->get(“stud”); $data[”records”] = $query->result(); $this->load->helper(”url”); $this->load->view(”Stud_view”,$data); } public function add_student_view() { $this->load->helper(”form”); $this->load->view(”Stud_add”); } public function add_student() { $this->load->model(”Stud_Model”); $data = array( ”roll_no” => $this->input->post(”roll_no”), ”name” => $this->input->post(”name”) ); $this->Stud_Model->insert($data); $query = $this->db->get(“stud”); $data[”records”] = $query->result(); $this->load->view(”Stud_view”,$data); } public function update_student_view() { $this->load->helper(”form”); $roll_no = $this->uri->segment(”3”); $query = $this->db->get_where(“stud”,array(“roll_no”=>$roll_no)); $data[”records”] = $query->result(); $data[”old_roll_no”] = $roll_no; $this->load->view(”Stud_edit”,$data); } public function update_student(){ $this->load->model(”Stud_Model”); $data = array( ”roll_no” => $this->input->post(”roll_no”), ”name” => $this->input->post(”name”) ); $old_roll_no = $this->input->post(”old_roll_no”); $this->Stud_Model->update($data,$old_roll_no); $query = $this->db->get(“stud”); $data[”records”] = $query->result(); $this->load->view(”Stud_view”,$data); } public function delete_student() { $this->load->model(”Stud_Model”); $roll_no = $this->uri->segment(”3”); $this->Stud_Model->delete($roll_no); $query = $this->db->get(“stud”); $data[”records”] = $query->result(); $this->load->view(”Stud_view”,$data); } } ?> Create a model class called Stud_Model.php and save it in application/models/Stud_Model.php <?php class Stud_Model extends CI_Model { function __construct() { parent::__construct(); } public function insert($data) { if ($this->db->insert(“stud”, $data)) { return true; } } public function delete($roll_no) { if ($this->db->delete(“stud”, “roll_no

CodeIgniter – Libraries

CodeIgniter – Libraries ”; Previous Next The essential part of a CodeIgniter framework is its libraries. It provides a rich set of libraries, which indirectly increase the speed of developing an application. The system library is located at system/libraries. All we need to do is to load the library that we want to use. The library can be loaded as shown below − $this->load->library(”class name”); Where class name is the name of the library that we want to load. If we want to load multiple libraries, then we can simply pass an array as argument to library() function as shown below − $this->load->library(array(”email”, ”table”)); Library Classes The library classes are located in system/libraries. Each class has various functions to simplify the developing work. Following table shows the names of the library class and its description. Given below are the most commonly used Library Classes. S.N. Library Class & Description 1 Benchmarking Class Benchmarking class is always active, enabling the time difference between any two marked points to be calculated. 2 Caching Class This class will cache the pages, to quickly access the page speed. 3 Calendaring Class Using this class, you can dynamically create calendars. 4 Shopping Cart Class Using this class, you can add or remove item from Shopping Cart. The items are saved in session and will remain active until the user is browsing the site. 5 Config Class Configuration preferences can be retrieved, using this class. This class is initialized automatically. 6 Email Class This class provides email related functionality, like send or reply to email. 7 Encryption Class This class provides two-way data encryption functionality. 8 File Uploading Class This class provides functionalities related to file uploading. You can set various preferences like type of file to be uploaded, size of the files etc. 9 Form Validation Class This class provides various functions to validate form. 10 FTP Class This class provides various FTP related functions like transferring files to remove server, moving, renaming or deleting files on server. 11 Image Manipulation Class Manipulation of image like resize, thumbnail creation, cropping, rotating, watermarking can be done with the help of this class. 12 Input Class This class pre-processes the input data for security reason. 13 Language Class This class is used for internationalization. 14 Loader Class This class loads elements like View files, Drivers, Helpers, Models etc. 15 Migrations Class This class provides functionalities related to database migrations. 16 Output Class This class sends the output to browser and also, caches that webpage. 17 Pagination Class This class adds pagination functionalities to web page. 18 Template Parser Class The Template Parser Class can perform simple text substitution for pseudo-variables contained within your view files. It can parse simple variables or variable tag pairs. 19 Security Class This class contains security related functions like XSS Filtering, CSRF etc. 20 Session Library This class provides functionalities to maintain session of your application. 21 HTML Table This class is used to auto-generate HTML tables from array or database results. 22 Trackback Class The Trackback Class provides functions that enable you to send and receive Trackback data. 23 Typography Class The Typography Class provides methods that help to format text. 24 Unit Testing Class This class provides functionalities to unit test your application and generate the result. 25 URI Class The URI Class provides methods that help you retrieve information from your URI strings. If you use URI routing, you can also retrieve information about the rerouted segments. 26 User Agent Class The User Agent Class provides functions that help identify information about the browser, mobile device, or robot visiting your site. In addition, you can get referrer information as well as language and supported character-set information. 27 XML-RPC and XML-RPC Server Classes CodeIgniter’s XML-RPC classes permit you to send requests to another server, or set up your own XML-RPC server to receive requests. 28 Zip Encoding Class This class is used to create zip archives of your data. Creating Libraries CodeIgniter has rich set of libraries, which you can find in system/libraries folder but CodeIgniter is not just limited to system libraries, you can create your own libraries too, which can be stored in application/libraries folder. You can create libraries in three ways. Create new library Extend the native library Replace the native library Create New Library While creating new library one should keep in mind, the following things − The name of the file must start with a capital letter e.g. Mylibrary.php The class name must start with a capital letter e.g. class Mylibrary The name of the class and name of the file must match. Mylibrary.php <?php if ( ! defined(”BASEPATH”)) exit(”No direct script access allowed”); class Mylibrary { public function some_function() { } } /* End of file Mylibrary.php */ Loading the Custom Library The above library can be loaded by simply executing the following line in your controller. $this->load->library(‘mylibrary’); mylibrary is the name of your library and you can write it in lowercase as well as uppercase letters. Use the name of the library without “.php” extension. After loading the library, you can also call the function of that class as shown below. $this->mylibrary->some_function(); Extend the Native Library Sometimes, you may need to add your own functionality to the library provided by CodeIgniter. CodeIgniter provides facility by which you can extend the native library and add your own functions. To achieve this, you must extend the class of native library class. For example if you want to extend the Email library then it can be done as shown below − Class MY_Email extends CI_Email { } Here, in the above example, MY_Email class is extending the native library’s email class CI_Email. This library can be loaded by the standard way of loading email library. Save the above code in file My_Email.php Replace the Native Library In some situations, you do not want to use the native library the way it works and want to replace it with your own way. This

CodeIgniter – Installing CodeIgniter

CodeIgniter – Installing ”; Previous Next It is very easy to install CodeIgniter. Just follow the steps given below − Step-1 − Download the CodeIgniter from the link CodeIgniter There are two different options legacy and latest. The names itself are self descriptive. legacy has version less than 2.x and latest has 3.0 version. We can also go with GitHub and get all of the latest scripts.. Step-2 − Unzip the folder. Step-3 − Upload all files and folders to your server. Step-4 − After uploading all the files to your server, visit the URL of your server, e.g., www.domain-name.com. On visiting the URL, you will see the following screen − Print Page Previous Next Advertisements ”;