【问题标题】:Kohana 3.3 hello world does not workKohana 3.3 hello world 不工作
【发布时间】:2013-12-21 13:49:57
【问题描述】:

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

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

我的控制者:

<?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!';
    }
}

我的 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',
    ));

我还尝试在以下目录中创建一个名为 site.phpviewhttp://localhost/framework/application/views/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>

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

【问题讨论】:

  • 我也在使用 WAMP 服务器。

标签: php kohana kohana-3 kohana-3.3


【解决方案1】:

您需要在 bootstrap.php(Kohana::init 部分中的'base_url' =&gt; /framework/)和 .htaccess RewriteBase(RewriteBase /framework/)中设置正确的路径(/framework/

【讨论】:

  • 有什么想法可以用视图调用我的控制器吗?我仍然收到未定义变量的错误。
  • 我不太明白这个问题。默认情况下,您现在应该可以像这样调用您的控制器操作:yoururl/controllername/actionname。如果跳过该操作,则使用索引一。您可以从那里创建和输出视图。
  • $view = View::factory('site'); $this->response->body($view);应该工作
  • 我也对 index.php 文件中的所有 if 语句感到困惑。我真的需要为我网站中的每个页面提供所有这些吗?
  • 你会习惯的,它会为你解决很多问题。基本上你是对的 - 视图是系统的可见部分,控制器是处理许多其他事情的操作集
【解决方案2】:

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

之前:

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

之后:

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

【讨论】:

    猜你喜欢
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 2017-10-11
    • 2013-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多