This article describes the implementation method of thinkPHP general controller. Share it for your reference, as follows:
<?php namespace Table of contents\Controller; class TypeController extends Controller { public function add() { if(IS_POST) { $model = D('Type'); if($model->create()) { if($model->add()) { $this->success('Added successfully! ', U('lst')); exit; } else { $sql = $model->getLastSql(); $this->error('Insert the database failed! .<hr />SQL:'.$sql); } } else { $error = $model->getError(); $this->error($error); } } $this->display(); } public function lst() { $model = D('Type'); $data = $model->search(); $this->assign($data); $this->display(); } public function save($id) { $model = D('Type'); if(IS_POST) { if($model->create()) { if($model->save() !== FALSE) { $this->success('The modification was successful! ', U('lst')); exit; } else { $sql = $model->getLastSql(); $this->error('Failed to modify the database! .<hr />SQL:'.$sql); } } else { $error = $model->getError(); $this->error($error); } } $data = $model->find($id); $this->assign('data', $data); $this->display(); } public function del($id) { $model = D('Type'); $model->delete($id); $this->success('The operation was successful! ', U('lst')); } public function bdel() { $delid = I(''); if($delid) { $delid = implode(',', $delid); $model = D('Type'); $model->delete($delid); } else $this->error('Please select the record you want to delete!'); $this->success('The operation was successful! ', U('lst')); } }
For more information about thinkPHP related content, please check out the topic of this site:ThinkPHP Introduction Tutorial》、《Summary of the operation skills of thinkPHP templates》、《Summary of common methods of ThinkPHP》、《Codeigniter Introductory Tutorial》、《Advanced tutorial on CI (CodeIgniter) framework》、《Zend FrameWork Framework Introduction Tutorial"and"PHP template technical summary》。
I hope that the description in this article will be helpful to everyone's PHP programming based on the ThinkPHP framework.