Kohana 3.3你好世界不起作用

时间:2022-10-13 12:31:15

I keep getting the following error when i navigate to: http://localhost:81/framework/:

当我导航到:http:// localhost:81 / framework /时,我不断收到以下错误:

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

Kohana_HTTP_Exception [404]:在此服务器上找不到请求的URL框架。

Kohana 3.3你好世界不起作用

My Controller:

我的控制器:

<?php defined('SYSPATH') OR die('No Direct Script Access');

Class Controller_Welcome extends Controller_Template
{
    public $template = 'site';

    public function action_index()
    {
        $this->template->message = 'hello, world!';
    }
}

My bootstrap.php file looks like this:

我的bootstrap.php文件如下所示:

<?php defined('SYSPATH') or die('No direct script access.');

// -- Environment setup --------------------------------------------------------

/**
 * Initialize Kohana, setting the default options.
 *
 * The following options are available:
 *
 * - string   base_url    path, and optionally domain, of your application   NULL
 * - string   index_file  name of your index file, usually "index.php"       index.php
 * - string   charset     internal character set used for input and output   utf-8
 * - string   cache_dir   set the internal cache directory                   APPPATH/cache
 * - integer  cache_life  lifetime, in seconds, of items cached              60
 * - boolean  errors      enable or disable error handling                   TRUE
 * - boolean  profile     enable or disable internal profiling               TRUE
 * - boolean  caching     enable or disable internal caching                 FALSE
 * - boolean  expose      set the X-Powered-By header                        FALSE
 */
Kohana::init(array(
    'base_url'   => '/kohana/',
));

/**
 * Attach the file write to logging. Multiple writers are supported.
 */
Kohana::$log->attach(new Log_File(APPPATH.'logs'));

/**
 * Attach a file reader to config. Multiple readers are supported.
 */
Kohana::$config->attach(new Config_File);

/**
 * Enable modules. Modules are referenced by a relative or absolute path.
 */
Kohana::modules(array(
    // 'auth'       => MODPATH.'auth',       // Basic authentication
    // 'cache'      => MODPATH.'cache',      // Caching with multiple backends
    // 'codebench'  => MODPATH.'codebench',  // Benchmarking tool
    // 'database'   => MODPATH.'database',   // Database access
    // 'image'      => MODPATH.'image',      // Image manipulation
    // 'minion'     => MODPATH.'minion',     // CLI Tasks
    // 'orm'        => MODPATH.'orm',        // Object Relationship Mapping
    // 'unittest'   => MODPATH.'unittest',   // Unit testing
    // 'userguide'  => MODPATH.'userguide',  // User guide and API documentation
    ));

/**
 * Set the routes. Each route must have a minimum of a name, a URI and a set of
 * defaults for the URI.
 */
Route::set('default', '(<controller>(/<action>(/<id>)))')
    ->defaults(array(
        'controller' => 'welcome',
        'action'     => 'index',
    ));

I have also tried creating a view called site.php located in the following directory: http://localhost/framework/application/views/site.php

我还尝试创建一个名为site.php的视图,该视图位于以下目录中:http://localhost/framework/application/views/site.php

site.php

site.php

<html>
    <head>
        <title>We've got a message for you!</title>
        <style type="text/css">
            body {font-family: Georgia;}
            h1 {font-style: italic;}

        </style>
    </head>
    <body>
        <h1><?php echo $message; ?></h1>
        <p>We just wanted to say it! :)</p>
    </body>
</html>

I get the following error when i navigate to site.php:

当我导航到site.php时出现以下错误:

Kohana 3.3你好世界不起作用

2 个解决方案

#1


1  

You need to set proper path (which is /framework/) in your bootstrap.php ('base_url' => /framework/ in Kohana::init part) and .htaccess RewriteBase (RewriteBase /framework/)

你需要在bootstrap.php('base_url'=> / framework / in Kohana :: init part)和.htaccess RewriteBase(RewriteBase / framework /)中设置正确的路径(/ framework /)。

#2


1  

The problem was in the basestrap.php i didnt set the base URL:

问题出在basestrap.php我没有设置基本URL:

Before:

之前:

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

After:

后:

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

#1


1  

You need to set proper path (which is /framework/) in your bootstrap.php ('base_url' => /framework/ in Kohana::init part) and .htaccess RewriteBase (RewriteBase /framework/)

你需要在bootstrap.php('base_url'=> / framework / in Kohana :: init part)和.htaccess RewriteBase(RewriteBase / framework /)中设置正确的路径(/ framework /)。

#2


1  

The problem was in the basestrap.php i didnt set the base URL:

问题出在basestrap.php我没有设置基本URL:

Before:

之前:

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

After:

后:

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