As its title suggests, in this post I will give an example of a simple tutorial CRUD using CodeIgniter. CRUD stands for Create Read Update Delete. Of course, this requires a CRUD database to hold the data that will be processed.
Before entering the program code, we first set the configuration in the file library and helper autoload.php. This configuration is useful so that libraries and helpers that we use to load automatically when the application is run. Here's library and helper used.
1. $autoload['libraries'] = array('database');
2. $autoload['helper'] = array('form', 'url');
Do not forget to also set in the database configuration file database.php. Here's an example of my database configuration. Oh yeah, I use CodeIgniter in this
example is codeigniter version 2.0.2.
1. $db['default']['hostname'] = 'localhost';
2. $db['default']['username'] = 'root';
3. $db['default']['password'] = '';
4. $db['default']['database'] = 'ci';
After that we create a database with the name "ci" and a table named "cd".
1. CREATE DATABASE ci;
2. USE ci;
3. CREATE TABLE `cd` (
4. `kode_cd` int(11) NOT NULL auto_increment,
5. `judul` varchar(50) default NULL,
6. `kategori` varchar(25) default NULL,
7. `stok` int(11) default '0',
8. `harga` int(11) default '0',
9. PRIMARY KEY (`kode_cd`)
10. ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
Type text or a website address or translate a document. Cancel Example usage of "": automatically translated by Google English Japanese Thai Alpha After all the configurations sorted out, we created a model with the name of the folder crud_model.php models.
Create a controller in the folder with the name crud.php controllers.
And finally create a view with the name crud_view.php in folder views.
To run the application in the browser type http://localhost/ci/index.php/crud. Then it will perform CRUD application page as below.
No comments:
Post a Comment