我是编程并尝试在php中构建自己的MVC项目的新手。
我的文件夹结构:
我的路由器看起来像这样:
class App
{
protected $controller = 'index'; // Default controller
protected $method = 'index'; // Default method
protected $params = []; // Default parameters are an empty array
public function __construct()
{
Sessions::start_session(); // Start a session, logged in or not?
$url = $this->parseUrl();
if (file_exists('controllers/controller.' . $url[0] . '.php'))
{
$this->controller = $url[0];
unset($url[0]);
}
require_once 'controllers/controller.' . $this->controller . '.php';
$this->controller = new $this->controller;
if(isset($url[1]))
{
if(method_exists($this->controller, $url[1]))
{
$this->method = $url[1];
unset($url[1]);
}
}
$this->params = $url ? array_values($url) : [];
call_user_func_array([$this->controller, $this->method], $this->params);
}
public function parseUrl()
{
if(isset($_GET['url']))
{
return $url = explode('/',filter_var(rtrim($_GET['url'], '/'), FILTER_SANITIZE_URL));
}
}
}
我的登录控制器如下所示:
class login extends Controller
{
public function index()
{
$this->render('login/index');
}
public function login_user()
{
$this->model('login');
$this->model->log_user($_POST['email'], md5($_POST['password']));
}
}
我的登录视图如下所示:
<form action='????' method='post' id='loginForm' onSubmit='return false;'>
<div class='inputField'>
<input type='email' name='email' id='email' placeholder='Email' autofocus />
</div>
<div class='inputField'>
<input type='password' name='password' id='password' placeholder='Password' />
</div>
<div class='inputField'>
<input type='submit' name='submiter' value='Login' />
现在我的问题是如何从登录视图中表单的action属性调用Login类中的login_user方法?
帮助将非常感谢!如果我应该发布任何其他代码片段,请告诉我。