我无法打开“会员”页面。我收到错误:语法错误,意外的T_IF。 我正在尝试“验证”,但我得到的错误就像上面那样。有谁知道如何解决这个问题?此外,此文件位于APPATH / classes / controller / member.php
中<?php
class Controller_Member extends Controller_Template {
public $template = 'member/template';
public $is_admin = false;
public function before(){
parent::before
// below is the reason I got error for
if (!Auth::check() and Request::active()->action != 'login') {
Response::redirect('member/login');
}
if (Auth::member(100)){
$this->is_admin = true;
}
View::set_global('is_admin', $this->is_admin);
}
public function action_login(){
Auth::check() and Response::redirect('member');
if (Input::post('username') and Input::post('password')){
$username = Input::post('username');
$password = Input::post('password');
$auth = Auth::instance();
}
}
//ログインフォームの表示
$this->template->title = 'ギアらはここ';
$this->template->content = View::forge('member/form');
}
public function action_logout(){
//ログアウト
$auth = Auth::instance();
$auth->logout();
//'member'にリダイレクト
Response::redirect('member');
}
}
答案 0 :(得分:1)
您在();
- 来电中错过了parent::before
。你得到的这个错误让初学者感到困惑。它实际上意味着:
&#34;在这段代码之前出现了错误,因为我不希望在这里遇到Auth
这个词。&amp; #34;
基本上,当您收到语法错误时,首先检查您收到错误的地方之前的代码。
但是,你也会有更多的错误。
<?php
class Controller_Member extends Controller_Template
{
public $template = 'member/template';
public $is_admin = false;
public function before()
{
parent::before();
// ^^^ Here, you missed the call ( () ) and semicolon ( ; )
// ...
}
public function action_login()
{
Auth::check() and Response::redirect('member');
// ^^ This line does not make sense without an if statement ^^
// Except if it throws exceptions.
}
//...
}
这部分不在任何方法内部,而是直接在类中,因此也没有意义(你必须把它放在一个函数中):
//ログインフォームの表示
$this->template->title = 'ギアらはここ';
$this->template->content = View::forge('member/form');
在此之后,您还有另一个结束括号}
,这也会产生语法错误。目前还不清楚你指的是那两行;在我看来,他们不属于你的任何一种方法,但似乎你只需要在上面两行之前删除右括号。
总而言之,请确保正确缩进代码,然后您将抓住大部分错误。