Php 有一个;编辑";控制器处理用户编辑?这个设计有意义吗?
以下是流程:Php 有一个;编辑";控制器处理用户编辑?这个设计有意义吗?,php,codeigniter,controller,editing,verification,Php,Codeigniter,Controller,Editing,Verification,以下是流程: 用户创建基于文本的帖子 用户编辑基于文本的帖子(显示包含帖子信息的编辑页面) 用户向post提交更改(发送到post控制器的请求) 现在,如果我有多种类型的帖子,我必须在第2步和第3步检查用户是否确实在更新正确类型的帖子,因为有人很可能会更改URL以编辑类型为a的帖子,而实际上它是类型为B的。这会导致大量冗余代码,例如 if(user is indeed the editor && the post type is correct) show the edit pa
if(user is indeed the editor && the post type is correct) show the edit page
我认为有一个编辑控制器来完成构造函数(或者可能是基类?)中所需的所有验证,然后调用该方法是很有意义的。您遇到过类似的问题吗?如果没有,这在设计上有意义吗 。这意味着您的控制器充当模型(数据)和视图(前端)之间的中介。“编辑”是对对象(如数据)执行的操作。数据对象应该组织在一个控制器中,该控制器从模型中调用实际的编辑函数
我假设你有一个邮政管理员。它的核心应该具有基本的CRUD功能,比如添加和编辑帖子。它应该是这样的:
class Post extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
// List all posts, perhaps?
}
function add()
{
// Add a post
}
function edit($post_id)
{
// Edit a post
}
function view($post_id)
{
// View a post
}
}
这将为您提供以下页面:
if ($this->tank_auth->is_logged_in()) {
// Do stuff
}
这应该在每个函数的开头,或者在\uu construct()
中,如果您想完全干燥它的话
祝你好运