【发布时间】:2012-03-11 04:16:38
【问题描述】:
我有
登录控制器、模型和视图
现在当我在http://mySite/controller 时,它会显示登录表单,然后当我提交表单时,会调用 run 方法,因此 url 会更改为 http://mySite/login/run
我怎样才能阻止这个:?
P.S // 我按照这个 tut 创建了自己的 MVC:http://www.youtube.com/watch?v=2Eu0Nkpo6vM
登录控制器
class Login extends Conroller {
function __construct() {
parent::__construct();
}
function index()
{
$this->view->render('authentication/enter');
}
function run()
{
$this->model->run();
}
}
登录模式
class Login_Model extends Model
{
public function __construct()
{
parent::__construct();
}
public function run()
{
$sth = $this->dbh->connect()->prepare("SELECT UserID FROM users WHERE
username = :login ");
$sth->execute(array(':login' => $_POST['login']));
$data = $sth->fetch();
$count = $sth->rowCount();
if ($count > 0) {
// login
Session::set('loggedIn', $_POST['login']);
header('location: ../dashboard');
} else {
echo 4;
}
}
}
使用 .htacces
网址是
http://mySite/index.php?url={控制器名称}
或
http://mySite/index.php?url={控制器名称}/{来自控制器的一些方法}
【问题讨论】:
-
请展示您的一些代码,以便我们找出重定向的位置。
-
总之,当你在 /index.php?url=login 加载登录控制器时,加载登录模型和视图。 Everthing 正在工作,但教程中显示了如何更改网址
标签: php model-view-controller oop