المشاركات

عرض الرسائل ذات التصنيف CodeIgniter

How to Create Custom Library in CodeIgniter

صورة
Hi, today let's see how to create custom library in codeigniter . CodeIgniter offers a rich set of libraries and helpers for robust application development. In general, a library is a class file used to group similar functionalities into a single file. Now we can do the same with helper but the libraries have their own object to store relevant data. Below I'll show you how to create your own class libraries in CI. You must store these library files inside the 'application/libraries' folder. This will keep them separate from the native libraries of the framework. CodeIgniter - Create Custom Library: CodeIgniter is a flexible MVC framework and allows you to, Create new custom libraries. Extend existing libraries to include additional functionalities to them. Replace native libraries completely with your own version. I'm going to show you an example where I create a custom library to export the database table as a json string. STEP-1) Create a library named...

Generate PDF from View using DomPDF in CodeIgniter 3

صورة
Hi, in this post let's see how to generate pdf from view using dompdf in codeigniter 3 . When it comes to generating reports, the pdf format is the most popular in use. In addition, many websites offer downloadable documents, forms and files in pdf format by converting from html to pdf. There are several add-ons and libraries to aid with the process, such as DOMPDF, MPDF, FPDF, TCPDF, Html2Pdf etc. In this case, I will use the DomPDF library to generate PDF documents in code igniter. DomPDF renders the html layout to a PDF file and supports the loading of external style sheets and inline css styles when creating pdf. How to Generate PDF from CodeIgniter View? Here we are going to see how to generate pdf document from a codeigniter view file. Basically dompdf reads the html content, create pdf from html and writes it to the output stream. The following are the steps to implement PDF generation in code igniter. STEP-1) First download dompdf library, then extract and move th...

AJAX Pagination in CodeIgniter Tutorial

صورة
Hi! In this post, we will see how to make ajax pagination in codeigniter using codeigniter pagination library . The Pagination class offers feature rich functions to paginate the query results in view. Although the usage of pagination library is well-documented, paginating the results with jquery ajax is somewhat a mystery. The solutions available around the web are too complicated for beginners. Hence I decided to write a tutorial on the topic that is easy enough for anyone to implement codeigniter pagination with ajax. For this example, we'll need two libraries which are jQuery and Bootstrap . The jQuery.js is for making ajax call and bootstrap is for designing the user interface. CodeIgniter AJAX Pagination Example: To create ajax pagination, I'm going to use the default pagination library of the code igniter framework. Simply follow the below steps to implement the same. STEP-1) Create Database First create the required database, table and the records to use in our ...

Upload Multiple Images & Files in CodeIgniter Example

صورة
Hi! In this post, we'll see how to upload multiple images and files in codeigniter . Kodingmadesimple has a nice tutorial about codeigniter file upload process. Normal file uploading has a limitation which is you can only upload a single file/image at a time. What if you want to upload multiple files or images in codeigniter in one go? Is it possible to do that? The answer is YES! You can! Here I'll show you an example about multiple file upload in codeigniter. CodeIgniter Upload Multiple Files/Images: For this file uploading process you'll need a folder in the server to store all your uploaded files. Just create a folder named 'uploads' inside the application root and make sure to enable 'write' access to it. Next you need to create user interface to upload files. So create a code igniter view with a form and add file control & submit button to it. Set the name of the file field as array and add 'multiple' attribute to enable mult...

Simple Image and File Upload in CodeIgniter with Validations & Examples

صورة
Codeigniter provides a wide number of helper class and libraries for rapid application development. Upload library is one among them that makes file uploading process in Codeigniter a breeze. We'll see how to do file and image upload in codeigniter in this tutorial. File and Image uploading are similar since images are themselves files. But there are options for you to restrict the uploading process specific to images files alone and we'll see it below. File Upload in CodeIgniter First of all, we need a destination folder to store all the uploaded files. So create a folder named 'uploads' in the root folder. Make sure it is writable for the uploading process to work. Read Also: How to Create Login Page in CodeIgniter & MySQL How to Send Email in CodeIgniter using Gmail CodeIgniter Pagination System using Bootstrap Create Controller Create a controller file 'uploadfile.php' inside 'application\controllers' folder in codeigniter. ...

CodeIgniter Autocomplete Search from Database using AJAX Example

صورة
Hi! In this post, let's see how to autocomplete search from database using codeigniter and ajax . We are going to pull in live search thing something similar to Google search. As soon as you start typing in the textbox, the related suggestions will appear from the database. To implement this auto complete feature we need a jquery plugin called 'Select2'. Select2 is an excellent plug-in that supercharges the regular select box with search functionality . It's really inappropriate to make the end user to skim through hundreds of options to pick just one. With Select2 the entire process is a breeze. It adds up a search filter to the dropdown (select box), thus populating results on fly with the help of ajax. AJAX Autocomplete Search from Database in CodeIgniter: To implement the live autocomplete search in codeigniter, we need two JavaScript libraries, 1. jquery.js and 2. select2.js . Either download them or use from the cdn library just like I do in this demo. Jus...

How to Resize Image and Create Thumbnail in CodeIgniter

صورة
Hi! Today we will see how to resize image and create thumbnail in codeigniter . This comes handy when you want to resize user avatar or profile images. Generally, shopping sites employ this method. Although they upload large product images, they'll create a thumbnail version of them and lists them in several categories. This will not only save bandwidth but load the page faster and listing more items in a limited space. We are going to see how to do this in codeigniter. CI offers a very useful image manipulation class called image_lib which we are going to use for resizing the image. Using this library you can not only change the size but perform crop, rotate and watermark images. It is compatible with all major image libraries like GD/GD2, ImageMagick and NetPBM and we will use GD2 here. CodeIgniter - Image Resizing and Creating Thumbnail Image: Let's build a CI demo to implement image resizing and the process goes like this. The user uploads images using the upload for...

How to Export MySQL Table to JSON File in CodeIgniter

صورة
Hi! In this tutorial, we will see how to export mysql table to json file in codeigniter . Data portability has become more important than ever and a necessary requirement for modern applications. Almost all web services uses JSON format to migrate data from one location to another. So, as a Web Developer, you must know to handle json and various types of applications like Web, Mobile etc. Exporting mysql into json allows you to easily port data to different platforms. The whole process is quite simple. Just fetch the data from mysql database, covert the query result to json and then write it in a file. CodeIgniter - Export MySQL Table to JSON File: Let's create a demo for exporting the database as json. The steps are easy to follow and we possibly need two files, a model and a controller. Step-1) Create Database We need a dummy database to use in the example, a database, a table and some sample records. Run the below sql file in the mysql environment and create them. ...

PHP CodeIgniter Tutorials for Beginners Step By Step: Learn From Scratch

صورة
Hi, Welcome to our PHP CodeIgniter Tutorial Series. These step by step tutorials are intended for beginners who want to start learning php codeigniter from scratch. It will start right away from setting up the codeigniter framework working environment and move on to more advanced topics covering codeigniter framework libraries, helpers and active record class for database communication. Another nice perk with this series is you will get to know about the popular twitter bootstrap css framework while learning. Why You Should Learn CodeIgniter Framework? CodeIgniter Framework is developed by EllisLab and now it is taken by British Columbia Institute of Technology. It is the simplest and light-weight PHP framework which lets you create robust web applications in no time. It is greatly appreciated for its speedy performance and smaller learning curve and suitable for highly scalable applications. And even though php codeigniter framework loosely follows Model-View-Controller pat...

CodeIgniter | Remove index.php from URL using htaccess

صورة
Hi, we’ll see how to remove index.php from url in codeigniter . Even though codeigniter uses search engine friendly urls, nobody would have missed the awkward presence of 'index.php' in between those codeigniter's urls. Have you ever wondered how to get rid of it to get more clean urls in your codeigniter application ? Say your app has an url something like http://www.example.com/index.php/contact and you want it to look like http://www.example.com/contact . Yes, you can do it. In codeigniter removing index.php from url should be done by rewriting urls in htaccess file. How to Remove index.php from URL in CodeIgniter using .htaccess? Recommended Read: How to Create Login Form in CodeIgniter, MySQL and Twitter Bootstrap Recommended Read: CodeIgniter/MySQL Tutorial - Read and Display data with Twitter Bootstrap Step 1: Enable Mod Rewrite Option in your APACHE Server To rewrite urls in the htaccess file, the mod_rewrite option should be enabled in the apache serve...

PHP CodeIgniter Pagination with Twitter Bootstrap Styles - Example

صورة
PHP Codeigniter framework provides a good number of libraries required for building a website with codeigniter and pagination library is one among them. For those who are not familiar with the term pagination, this refers to the set of numbered links that allows you to navigate from page to page to view a large set of data. For example let's say you want to fetch and display some data from database and it contains several hundreds of records. In that case pagination will be very useful to display the database resultset in chunks and let the user to skim through several page links (similar to google search results). However the pagination links in codeigniter are plain looking in nature and a little customization to codeigniter pagination doesn't hurt. Here we'll see in this tutorial, how to style codeigniter pagination links with twitter bootstrap styles . Implement Twitter Bootstrap Styles in CodeIgniter Pagination We'll see an example below to fetch and displ...