【发布时间】:2012-05-31 13:30:27
【问题描述】:
我正在尝试将 POST 值发送到控制器,然后将其传递给 PHP 中的模型,但我不知道该怎么做。
控制器的这一部分是看用户是否请求像?action=game这样的视图。这行得通。
但我正在尝试修改它以允许将$_POST 发送给它,然后发送给模型。
function __construct()
{
if(isset($_GET['action']) && $_GET['action']!="" )
{
$url_view = str_replace("action/","",$_GET['action']);
if(file_exists("views/" . $url_view . ".php" ))
{
$viewname = $url_view;
$this->get_view($viewname . ".php");
}
else
{
$this->get_view('error.php');
}
}
else
{
$this->get_view('home.php');
}
}
这就是我得到的。在注册表单页面,表单的action是?process=register,但是不起作用。
if(isset($_POST['process']) == 'register)
{
$this->get_view('register.php')
}
Get_view 函数确定要与视图绑定的模型
function get_view($view_name)
{
$method_name = str_replace(".php","",$view_name);
if(method_exists($this->model,$method_name))
{
$data = $this->model->$method_name();
} else {
$data = $this->model->no_model();
}
$this->load->view($view_name,$data);
}
【问题讨论】:
-
你在 if(isset($_POST['process']) == 'register) 中缺少一个结束单引号
标签: php model-view-controller model