Hi so how do you do it in kohana 3.3 and kostache?
Form
<form method="POST" action="user/login">
<input type="text" name="email" />
<input type="passowrd" name="password" />
</form>
Controller
public function action_login()
{
$user = Auth::instance()->login($this->request->post('email'),$this->request->post('password'));
if($user)
{
$view = Kostache_Layout::factory()
$layout = new View_Pages_User_Info();
$this->response->body($this->view->render($layout));
}
else
{
$this->show_error_page();
}
}
Class View
class View_Pages_User_Info
{
public $title= "Profile";
}
Mustache Template
<p> This is the Profile Page</p>
So far so good, I'm now in the profile page but the url is
localhost/kohana_app/user/login
instead of
localhost/kohana_app/user/profile
I know I can change the action_login
to action_profile
to match the url and the title of the page but is there any other way to do this?
Forget about a body for the response if the login was succesful and redirect to the profile page.
HTTP::redirect(Route::get('route that routes to the profile page')->uri(/* Just guessing */'action' => 'profile'));
Read up on Post/Redirect/Get .
Route::set('home', '')
->defaults(array(
'controller' => 'Home',
));
Route::set('auth', 'user/<action>', array('action' => 'login|logout'))
->defaults(array(
'controller' => 'User',
));
Route::set('user/profile/edit', 'user/profile/edit(/<user>)')
->defaults(array(
'controller' => 'User_Profile', // Controller_User_Profile
'action' => 'edit',
));
Route::set('user/profile/view', 'user/profile(/<action>(/<user>))', array('action' => 'edit'))
->defaults(array(
'controller' => 'User_Profile',
));
############
class Controller_User_Profile {
public function action_index()
{
// ...
$this->action_view($user->username());
}
public function action_view($user = NULL)
{
if ($user === NULL)
{
$user = $this->request->param('user');
}
// ...
}
}
Personally I like to send my users to a dashboard, which can be(come) different from viewing your own profile.
This is just A way of doing it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.