Phân trang và tìm kiếm CodeIgniter 3
1.Cài đặt:
Download CodeIgniter 3 ở đây
Sau đó giải nén và đổi tên folder root là paging_ci
Cấu hình config/config.php
$config['base_url'] = 'http://localhost/paging_ci/'; $config['index_page'] = '';
Xem cách remove index.php ở đây
Cấu hình database
$db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'root', 'password' => '', 'database' => 'paging_ci', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => (ENVIRONMENT !== 'production'), 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE );
Tạo data demo:
Tạo table users
CREATE TABLE `users` ( `user_id` INT(11) NOT NULL AUTO_INCREMENT, `user_name` VARCHAR(256) NOT NULL COLLATE 'latin1_swedish_ci', `user_email` VARCHAR(256) NOT NULL COLLATE 'latin1_swedish_ci', `create_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`user_id`) USING BTREE )
Insert data users
INSERT INTO `users` (`user_id`, `user_name`, `user_email`, `create_date`) VALUES (1, 'John', 'john@gmail.com', '2017-07-20 16:22:27'), (2, 'Doe', 'doe@gmail.com', '2017-07-20 16:22:27'), (3, 'Sam', 'sam@gmail.com', '2017-07-20 16:25:35'), (4, 'Sara', 'sara@gmail.com', '2017-07-20 16:25:35'), (5, 'Sam', 'sam@gmail.com', '2017-07-20 16:25:35'), (6, 'Sara', 'sara@gmail.com', '2017-07-20 16:25:35'), (7, 'Adam', 'adam@gmail.com', '2017-07-20 16:25:35'), (8, 'Smith', 'smith@gmail.com', '2017-07-20 16:25:35'), (9, 'Ram', 'ram@gmail.com', '2017-07-20 16:25:35'), (10, 'Mohan', 'mohan@gmail.com', '2017-07-20 16:25:35'), (11, 'John', 'john@gmail.com', '2017-07-20 16:25:35'), (12, 'Ahmad', 'ahmad@gmail.com', '2017-07-20 16:25:35'), (13, 'Jorge', 'jorge@gmail.com', '2017-07-20 16:25:35'), (14, 'Ke', 'Ke@gmail.com', '2017-07-20 16:25:35'), (15, 'Xui', 'xui@gmail.com', '2017-07-20 16:25:35');
Tạo model M_welcome.php
Tạo controller Welcome.php
Tạo fontend welcome_message.php
Truy cập link demo:http://localhost/paging_ci/welcome/search
Source code demo ở đây
Leave a Reply