使用Codeigniter快速设置CRUD的方法?

时间:2011-10-31 20:18:39

标签: codeigniter crud

我想知道Code Igniter是否具有与我构建的小型框架相同的东西,以及它可能被称为什么。我构建了一个小框架,为每个mysql数据库表创建一个列表视图和编辑视图。下面显示了我如何设置CMS来操作数据库表的代码示例:

// CODE FOR LIST VIEW - http://mysite.com/admin/user.php
// This code will output an html table of records from db table t_user.
// The html table will have controls that allow user to search, delete, and paginate
// You can click on each record to edit the record
<?php
include('class/framework.php');
$template = new ListView();
$template->data_object = new DB($mysql_table_name = 't_user');
$template->setCol($col = 'user_name', $label = 'User Name');
$template->setCol($col = 'email', $label = 'Email'); 
$template->setCol($col = 'last_login', $label = 'Last Time Logged In', $format='Y-m-d H:i:s');
$tempate->run();
?>

// CODE FOR EDIT VIEW - http://mysite.com/admin/user.edit.php
// This code will output an html form that adds, edits, deletes
// and validates a record from t_user
<?php
include('class/framework.php');
$template = new EditView();
$template->data_object = new DB($mysql_table_name = 't_user'):

$f = new Field($col = 'user_id', $type = 'hidden');
$template->field[] = $f;

$f = new Field($col = 'email', $type = 'text');
$f->arr_validate = array('is_email', 'is_required');
$template->field[] = $f;

$f = new Field($col = 'phone', $type = 'text');
$f->arr_validate = array('is_phone', 'is_required');
$template->field[] = $f;

$f = new Field($col = 'password', $type = 'password');
$template->field[] = $f;

$f = new Field($col = 'bio', $type = 'wysiwyg');
$template->field[] = $f;

$f = new Field($col = 'pic', $type = 'image');
$template->field[] = $f;


$template->run();
?>

就是这样......我不必写一行html,css或javascript代码。只要我填充$f->arr_validate,所有验证都是为我完成的。搜索,排序,分页,编辑,删除等等的能力都只需要上面的代码即可完成。

Code Igniter中是否有类似的功能?如果没有开箱即用的东西,就这么说吧。

2 个答案:

答案 0 :(得分:5)

您所寻找的内容被称为CRUD,而不是CMS。

C - 创建 R - 阅读 你 - 更新 D - 删除

为此,我强烈建议Grocery Crud。设置非常棒,非常容易。包含您正在寻找的功能,例如分页和搜索等。

答案 1 :(得分:0)

最受欢迎的CI CMS(至少据我所知)是PyroCMS