2010-05-23 96 views
0

我讀this post我想使用類似的解決方案,但與數據庫。主題外應用程序

在我的網站控制器後():

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

我用螢火檢查:

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

我相信路徑存在。我直接在'orange'文件夾'views'文件夾中使用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] Previous鏈接後死了,鏈接爲: http://forum.kohanaframework.org/comments.php?DiscussionID=5744&page=1#Item_0

回答

0

我的猜測是,你的控制器具有__construct()方法,你是不是叫parent::__construct

其實,我認爲Kohana的V3 __construct需要也可以通過$ request對象如下:

public function __construct(Request $request) 
{ 
    parent::__construct($request); 
} 
+0

感謝您的回答。我添加了控制器代碼。 – Marek 2010-05-24 00:58:49

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); 

Ofcourse我忘了set_global不返回$this:D

無論如何所有的工作現在:)

我還有一個關於效率的問題。我在請求流中第二次打電話Kohana::modules()。根據效率這是一個大問題嗎?

Regards

+0

@效率,不,它是一種非常有效的方法,經過測試 – Kemo 2011-03-13 00:28:21