0

この投稿を読んで、同様のソリューションを使用したいのですが、db.

私のサイトコントローラ after():

$theme = $page->get_theme_name(); //Orange
Kohana::set_module_path('themes', Kohana::get_module_path('themes').'/'.$theme);
$this->template = View::factory('layout')

私はfirebugでチェックしました:

fire::log(Kohana::get_module_path('themes')); // D:\tools\xampp\htdocs\kohana\themes/Orange

そのパスが存在すると確信しています。私は、layout.phpファイルを含む「オレンジ」フォルダー「ビュー」フォルダーに直接持っています。

しかし、私は得ています:要求されたビューレイアウトが見つかりませんでした

拡張された Kohana_Core は次のとおりです。

public static function get_module_path($module_key) {
return self::$_modules[$module_key];
}

public static function set_module_path($module_key, $path) {
self::$_modules[$module_key] = $path;
}

誰かがその問題を解決するのを手伝ってくれますか?

多分それは .htaccess の問題です:

# Turn on URL rewriting
RewriteEngine On

# Put your installation directory here:
# If your URL is www.example.com/kohana/, use /kohana/
# If your URL is www.example.com/, use /
RewriteBase /kohana/

# Protect application and system files from being viewed
RewriteCond $1 ^(application|system|modules)

# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ / [PT,L]
RewriteRule ^(media) - [PT,L]
RewriteRule ^(themes) - [PT,L]

# Allow these directories and files to be displayed directly:
# - index.php (DO NOT FORGET THIS!)
# - robots.txt
# - favicon.ico
# - Any file inside of the images/, js/, or css/ directories
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|static)

# No rewriting
RewriteRule ^(.*)$ - [PT,L]

# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]

誰か助けてくれませんか?私が間違っていることは何ですか?

よろしく

[編集]

私のコントローラーコード:

class Controller_Site extends Controller_Fly {

   public static $meta_names = array('keywords', 'descriptions', 'author');


   public function action_main() {
        $this->m('page')->get_main_page();
   }

   public function action_page($page_title) {
       $this->m('page')->get_by_link($page_title);
   }

   public function after() {
        $page = $this->m('page');
        $metas = '';
        foreach(self::$meta_names as $meta) {
           if (! empty($page->$meta)) {
              $metas .= html::meta($page->$meta, $meta).PHP_EOL;
           }
        }
        $theme = $page->get_theme_name();
        Kohana::set_module_path('themes', Kohana::get_module_path('themes').'/'.$theme);
        $menus = $page->get_menus();
        $this->template = View::factory('layout')
                           ->set('theme', $theme)
                           ->set('metas', $metas)
                           ->set('menus', $menus['content'])
                           ->set('sections', $page->get_sections())
                           ->set_global('page', $page);
        if ($page->header_on) {
            $settings = $this->m('setting');
            $this->template->header = View::factory('/header')
                                              ->set('title', $settings->title)
                                              ->set('subtitle', $settings->subtitle)
                                              ->set('menus', $menus['header']);
        }
        if ($page->sidebar_on) {
            $this->template->sidebar = View::factory('sidebar', array('menus' => $menus['sidebar']));
        }
        if ($page->footer_on) {
            $this->template->footer = View::factory('footer');
        }
        parent::after();
   }

}

および親コントローラー:

abstract class Controller_Fly extends Controller_Template {

        protected function m($model_name, $id = NULL) {
            if (! isset($this->$model_name)) {
                   $this->$model_name = ORM::factory($model_name, $id);
            }
            return $this->$model_name;
        }

        protected function mf($model_name, $id = NULL) {
            return ORM::factory($model_name, $id);
        }

}

[編集 2] 投稿への以前のリンクは無効でした。リンクは次のとおりです: http://forum.kohanaframework.org/comments.php?DiscussionID=5744&page=1#Item_0

4

2 に答える 2

0

すべてのモジュールをもう一度初期化する必要があることに気付きました。

    $theme = $page->get_theme_name();
    Kohana::set_module_path('themes', Kohana::get_module_path('themes').'/'.$theme);
    Kohana::modules(Kohana::get_modules());

今、私はエラーがありません。代わりに、死の白い画面が表示されます:

$this->template is null

:(

[編集]

今、私は知っています:

$this->template = View::factory('layout')
->set('theme', $theme)
->set('metas', $metas)
->set('menus', $menus['content'])
->set('sections', $page->get_sections())
->set_gobal('page', $page);

set_globalもちろん、それが返されないことを忘れていました$this:D

とにかくすべてが今働いています:)

効率性についてもう 1 つ質問があります。Kohana::modules()リクエスト フローで 2 回目の呼び出しを行っています。これは効率的には大したことですか?

よろしく

于 2010-05-24T21:26:45.723 に答える
0

私の推測では、コントローラーには__construct()メソッドがあり、呼び出していませんparent::__construct

実際、kohana V3 では、次のように __construct にも $request オブジェクトを渡す必要があると思います。

public function __construct(Request $request)
{
    parent::__construct($request);
}
于 2010-05-23T23:33:18.710 に答える