我为所有用户操作创建一个Controller(logIn,logOut,register等)我在注册操作中使用了forward方法并且工作正常,但是,在index action中抛出未定义的方法,任何想法?我找不到问题:
use Phalcon\Tag as Tag;
class UserController extends ControllerBase
{
public function indexAction(){
Phalcon\Tag::appendTitle("Log In");
if ($this->request->isPost()) {
$email = $this->request->getPost('email', 'email');
$password = $this->request->getPost('password');
$user = Users::findFirst(
array(
"conditions" =>"email=:email: AND password=:password:",
"bind" => array(
"email"=>$this->request->getPost('email'),
"password"=>$this->request->getPost('password'),
)
)
);
if($user !== FALSE){
$this->flash->success('Welcome ' . $user->name);
return $this->forward('user/profile');//Throws undefined forward method
}else{
$this->flash->error('Incorrect email or password');
}
Tag::setDefault('password', '');
}
}
public function registerAction(){
$this->assets
->addJs("js/jquery.validate.js")
->addJs("js/users/register.js");
if($this->request->isPost()){
$email = $this->request->getPost("email");
$password = $this->request->getPost("password");
$rPassword = $this->request->getPost("rPassword");
if($password != $rPassword){
$this->flash->error("Las contraseñas no coinciden");
return FALSE;
}
$user = new Users();
$user->email = $email;
$user->password = $password;
if(!$user->save()){
foreach($user->getMessages() as $message){
$this->flash->error((string)$message);
}
}else{
$this->flash->success('Thanks for register');
Tag::setDefault('email', '');
Tag::setDefault('password', '');
Tag::setDefault('rPassword','');
return $this->forward('user/index');//Works fine
}
}
}
}
答案 0 :(得分:1)
forward()
是ControllerBase
class:
protected function forward($uri) {
return $this->response->redirect($uri);
}
答案 1 :(得分:0)
您似乎没有forward()
或其任何父级层次结构中可用的方法UserController
。
此外,您应该对Phalcon \ Tag与Tag的使用保持一致。