コハナは初めてです。コハナ3.2のデフォルトルートを使用しています。
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'admin',
'action' => 'login',
));
私のコントローラーは次のとおりです:
<?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');
}
}
私の.htaccessは次のとおりです:
# 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]
私がタイプするときhttp://localhost
、それはきちんと働いています。しかし、入力http://localhost/admin/login
するかhttp://localhost/admin/logout
、404エラーが表示されます。
助けてください。