Reputation: 4059
I am new to Kohana. I am using the default route in Kohana 3.2 which is
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'admin',
'action' => 'login',
));
My controller is as follows :
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Admin extends Controller{
public function __construct($request, $response) {
parent::__construct($request, $response);
}
public function action_login(){
$session = Session::instance();
if($session->get('admin_id')){
//Session is set / Logged in
$this->request->redirect('users/list');
exit();
}
if($_POST){
$user = ORM::factory('admin');
$post = Validation::factory($_POST)
->rule('username', 'not_empty')
->rule('password', 'not_empty');
if(!$post->check()){
Message::error($post->errors('admin'));
}
else{
$objUserDetails = $user->checkCredentials($_POST);
if($objUserDetails->id){
//Valid username and password
$session->set('admin_id', $objUserDetails->id);
$this->request->redirect('users/list');
exit();
}
else{
Message::error("Invalid username or password");
$this->request->redirect('admin/login');
exit();
}
}
}
$this->response->body(new View(
'login',
array('title'=>'Administrator login')
));
}
public function action_logout(){
$session = Session::instance();
$session->delete('admin_id');
$session->destroy();
$this->request->redirect('admin/login');
}
}
My .htaccess is as follows :
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
When I type http://localhost
it is working properly. But when I type http://localhost/admin/login
or http://localhost/admin/logout
it is showing a 404 error.
Please help.
Upvotes: 0
Views: 1073
Reputation: 254886
You have your .htaccess
disabled, so you need to find AllowOverride
and set it as All
in your httpd.conf
Upvotes: 3