2013-11-02 116 views
1

我正在使用Kohana框架设置我的新Web应用程序。在Kohana中开发路由

我使用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 one

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

你在bootstrap.php(和.htaccess中的'RewriteBase')中设置了base_url吗? – kero

+0

你能告诉我这些应该是什么吗? –

回答

2

检查application/bootstrap.php文件:

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

为Kohana的了解它在/foo/文件夹这是必需的。如果没有action_<action>方法是在控制器中发现产生

UPD The requested URL foo was not found on this server异常消息。

如果没有找到路由Unable to find a route to match the URI:异常消息生成。

不舒服路由按预期工作,但它工作;)。

因此请检查您的Controller文件是否有适当的操作方法。

0

这将是一个Kohana的应用程序下/foo我首选的文件夹结构:

├─┬─ 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

RewriteCond为application,modulessystem文件夹是不需要的。

打开维护模式非常简单。

+0

不应该'应用程序'目录也在'foo'里面吗?里面的文件不应该与其他使用相同kohana的系统共享,它们应该如何? – kero

+0

如果你只有一个Kohana应用程序,那么这工作正常。如果你有多个运行相同的版本,你可以把'kohana/application /'移动到'applications/foo'。如果你可以避免的话,你不需要'application /'(或者你命名它)在webroot下。 – Darsstar