[英]MVC PHP - Displaying error message
嗨,我是使用MVC模式的新手。
在登錄控制器中,我有
function run() {
$result = $this->model->run();
if ($result) {
header('location: '. URL .'myaccount/index');
} else {
$this->view->msg = '<h2>User or password are not valid! Please try again!</h2>';
$this->view->render('login/index');
}
}
在我的登錄視圖中,我有
<div class="container">
<?php echo $this->msg; ?>
<form class="form-signin" action="<?php echo URL; ?>login/run" method="post">
<h2 class="form-signin-heading">Please sign in</h2>
<input type="text" class="form-control" name="email" placeholder="Email address" autofocus required>
<input type="password" class="form-control" name="password" placeholder="Password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
</form>
</div>
在我看來,這應該是這樣的。 用戶嘗試登錄,如果用戶名或密碼無效,將再次顯示登錄表單,並在其上方顯示以下消息:用戶名或密碼無效! 請再試一次!
我遇到以下錯誤通知:未定義的屬性:第2行的C:\\ xampp \\ htdocs \\ w \\ views \\ login \\ index.php中的View :: $ msg
我做錯了什么?
在這種情況下,您可以像這樣的header('location: '. URL .'myaccount/index?error');
進行重定向header('location: '. URL .'myaccount/index?error');
並檢查視圖中是否設置了$_GET['error']
回顯錯誤。
:D愚蠢的方法,但我認為它將起作用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.