当格式控制器/动作时,Kohana 3路由不正常

时间:2022-10-13 13:14:38

I am new to Kohana. I am using the default route in Kohana 3.2 which is

我是Kohana的新手。我在Kohana 3.2中使用默认路由

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 :

我的.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]

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.

当我键入http:// localhost时,它正常工作。但是当我键入http:// localhost / admin / login或http:// localhost / admin / logout时,它显示404错误。

Please help.

请帮忙。

1 个解决方案

#1


3  

You have your .htaccess disabled, so you need to find AllowOverride and set it as All in your httpd.conf

您已禁用.htaccess,因此需要在httpd.conf中找到AllowOverride并将其设置为All

#1


3  

You have your .htaccess disabled, so you need to find AllowOverride and set it as All in your httpd.conf

您已禁用.htaccess,因此需要在httpd.conf中找到AllowOverride并将其设置为All