PHP Fatal error: Call to undefined method SessionController::forward()
|
Dec '14 |
4 |
4628 |
0 |
public function startAction()
{
//echo '<pre>'; print_r($this->request->getPost());exit;
if ($this->request->isPost()) {
$email_address = $this->request->getPost('email','email');
$password = $this->request->getPost('password');
$password = sha1($password);
$user = User::findFirst("email_address='$email_address' AND user_password='$password' AND status='1'");
if ($user != false) {
$this->_registerSession($user);
$this->flash->success('Welcome'." ".$user->user_name."".$user->last_name);
return $this->forward('index/index');
}
// $username = $this->request->getPost('email', 'alphanum');
// $user = Users::findFirst("username='$username' AND password='$password' AND active='Y'");
// if ($user != false) {
// $this->_registerSession($user);
// $this->flash->success('Welcome ' . $user->user_name);
// return $this->forward('invoices/index');
// }
$this->flash->error('Wrong email/password');
}
return $this->forward('session/index');
}
PHP Fatal error: Call to undefined method SessionController::forward() in /var/www/html/capturev1/app/controllers/SessionController.php on line 89, referer: https://192.168.3.57/capturev1/session/index
PHP Fatal error: Call to undefined method SessionController::forward() in /var/www/html/capturev1/app/controllers/SessionController.php on line 89, referer: https://192.168.3.57/capturev1/session/index
<?php
use Phalcon\Tag as Tag;
class SessionController extends ControllerBase
{
public function initialize()
{
//$this->view->setTemplateAfter('main');
Tag::setTitle('CaptureV1');
//parent::initialize();
}
public function indexAction()
{
// if (!$this->request->isPost()) {
// Tag::setDefault('email', '[email protected]');
// Tag::setDefault('password', 'phalcon');
// }
}
public function registerAction()
{
$request = $this->request;
if ($request->isPost()) {
$name = $request->getPost('name', array('string', 'striptags'));
$username = $request->getPost('username', 'alphanum');
$email = $request->getPost('email', 'email');
$password = $request->getPost('password');
$repeatPassword = $this->request->getPost('repeatPassword');
if ($password != $repeatPassword) {
$this->flash->error('Passwords are diferent');
return false;
}
$user = new Users();
$user->username = $username;
$user->password = sha1($password);
$user->name = $name;
$user->email = $email;
$user->created_at = new Phalcon\Db\RawValue('now()');
$user->active = 'Y';
if ($user->save() == false) {
foreach ($user->getMessages() as $message) {
$this->flash->error((string) $message);
}
} else {
Tag::setDefault('email', '');
Tag::setDefault('password', '');
$this->flash->success('Thanks for sign-up, please log-in to start generating invoices');
return $this->forward('session/index');
}
}
}
/**
* Register authenticated user into session data
*
* @param Users $user
*/
private function _registerSession($user)
{
$this->session->set('auth', array(
'id' => $user->id,
'user_name' => $user->user_name
));
}
/**
* This actions receive the input from the login form
*
*/
public function startAction()
{
//echo '<pre>'; print_r($this->request->getPost());exit;
if ($this->request->isPost()) {
$email_address = $this->request->getPost('email','email');
$password = $this->request->getPost('password');
$password = sha1($password);
$user = User::findFirst("email_address='$email_address' AND user_password='$password' AND status='1'");
if ($user != false) {
$this->_registerSession($user);
$this->flash->success('Welcome'." ".$user->user_name."".$user->last_name);
return $this->forward('index/index');
}
$this->flash->error('Wrong email/password');
}
return $this->forward('session/index');
}
/**
* Finishes the active session redirecting to the index
*
* @return unknown
*/
public function endAction()
{
$this->session->remove('auth');
$this->flash->success('Goodbye!');
return $this->forward('index/index');
}
}
Instead of return $this->forward("index/index");
$this->response->redirect('index/index');
//or
return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'index'))
If U want to use $this->forward('index/index')
Please paste these code in your base controller
<?php
protected function forward($uri)
{
$uriParts = explode('/', $uri);
$params = array_slice($uriParts, 2);
return $this->dispatcher->forward([
'controller' => $uriParts[0],
'action' => $uriParts[1],
'params' => $params
]);
}