繁体   English   中英

正在开发中的Kohana中的路由

[英]Routing in Kohana in development

我正在使用Kohana框架设置新的Web应用程序。

我正在使用MAMP,因此该应用程序位于htdocs文件夹中,具有以下结构:

---htdocs
 --foo
  -application

查看http://localhost:8888/foo/时出现此错误

Kohana_HTTP_Exception[ 404 ]: The requested URL foo was not found on this server.

bootstrap.php ,路由是默认的Kohana一

Route::set('default', '(<controller>(/<action>(/<id>)))')->defaults(
array(
    'controller' => 'welcome',
    'action'     => 'index',
));

检查您的application/bootstrap.php文件是否包含:

Kohana::init(array(
    'base_url'   => '/foo/',
));

这是Kohana理解它在/foo/文件夹中所必需的。

UPD如果在Controller中未找到action_<action>方法, action_<action> The requested URL foo was not found on this server异常消息The requested URL foo was not found on this server

如果未找到任何路由Unable to find a route to match the URI:异常消息。

不能保证“路由”按预期工作,但可以工作;)。

因此,请检查您的Controller文件以获取适当的操作方法。

对于/foo下的Kohana应用程序,这是我首选的文件夹结构:

├─┬─ htdocs
│ └─┬─ foo
│   ├─── .htaccess
│   └─── index.php
└─┬─ kohana
  ├─┬─ application
  │ ├─── bootstrap.php
  │ └─── etc...
  ├─┬─ modules
  │ └─── etc...
  ├─┬─ system
  │ └─── etc...
  ├─── index.php
  ├─── install.php
  └─── etc...

htdocs中/富/ index.php文件:

<?php

require '../../kohana/index.php';

htdocs中/富/的.htaccess:

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /foo/

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# 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]

在kohana / application / bootsrap.php中,将“ base_url”设置为foo:

Kohana::init(array(
        'base_url' => '/foo/',
        'index_file' => NULL,
));

如果要运行kohana / install.php,请创建htdocs / foo / install.php并要求输入“ ../../kohana/install.php”;

这样,您可以保持htdocs干净。 如果您的活动服务器由于某种原因停止处理PHP文件,那么人们唯一会看到的就是对Kohana的index.php的要求。

不需要applicationmodulessystem文件夹的RewriteCond。

打开维护模式非常容易。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM