class ProfileController extends \Phalcon\Mvc\Controller
{
// route GET /profile
public function indexAction()
{
$user = $this->_getUser();
$this->view->pick('registered/profile'); // <form action="/profile/edit" method="post"><input type="text" name="username" value="{{ user.fullname }}" /> ... </form>
$this->view->setVar('user', $user);
}
// route POST /profile/edit
public function editAction()
{
$validator = new Validation();
$fullName = $this->request->getPost('username', 'string');
$validator->rules('username', array(
new Validator\PresenceOf(array('message' => 'Please input username')),
//...
));
$validator->validate($this->request->getPost());
$validationResult = $validator->getMessages();
if (count($validationResult))
{
// *****************************************
// here I need redirect user to indexAction, i.e. /profile, not render the same in /profile/edit
// How can I pass all validation messages to indexAction?
// *****************************************
return;
}
$user = $this->_getUser();
$user->fullname = $fullName;
$user->save();
$this->response->redirect('/profile');
}
/**
* @return User
*/
private function _getUser()
{
$userId = $this->session->get(User::SESSION_ID);
$user = User::findFirst(array("id = ?0", "bind" => array($userId)));
return $user;
}
}