2011-02-23 32 views
0

我有通過視圖傳遞變量的問題。但是,第一部分代碼Kohana - 視圖內的視圖

// i enter the url http://localhost/my_projects/blog/index/index 
// classes/controller/index.php 
class Controller_Index extends Controller 
{ 
    protected $rendered_view; 

    public function before() 
    { 
     $this->rendered_view = View::factory('index') 
       ->set('head', View::factory('subpages/head') 
           ->set('title', 'Site title') 
        ) 
       ->set('nav', View::factory('subpages/nav') 
           ->set('title', 'Site title') 
        ) 
       ->set('header', View::factory('subpages/header') 
           ->set('h1', 'Header H1') 
        ) 
       ->set('sidebar', View::factory('subpages/sidebar') 
           ->set('h1', 'Header H1') 
        ) 
       ->set('content', View::factory('subpages/content') 
           ->set('h2', 'Header H2') 
           ->set('content', 'some content') 
        ) 
       ->set('footer', View::factory('subpages/footer') 
           ->set('footer', 'some footer') 
        ); 
    } 

    public function action_index() 
    { 
     $this->response->body($this->rendered_view); 
    } 
} 

,並鑑於指數我傳遞變量的默認視圖:

// views/index.php 
echo View::factory('default')->set('head', $head); 
echo View::factory('default')->set('nav', $nav); 
echo View::factory('default')->set('header', $header); 
echo View::factory('default')->set('sidebar', $sidebar); 
echo View::factory('default')->set('content', $content); 
echo View::factory('default')->set('footer', $footer); 

和我顯示視圖嘗試我嘗試「回聲」變量:

// views/default.php 
echo $head; 
echo $nav; 
echo $header; 
echo $sidebar; 
echo $content; 
echo $footer; 

它拋出錯誤:

ErrorException [ 2 ]: file_put_contents(/some_path/application/logs/2011/02/23.php): failed to open stream: Permission denied ~ SYSPATH/classes/kohana/log/file.php [ 81 ] 

如果我寫這樣的東西:

// views/default.php 
include Kohana::find_file('views', 'default'); 

它顯示有效;

+1

只是注意 - 你'before'的代碼應該被移到'action_index()'和'action_index() ()'之後。並且不要忘記'parent :: before()'/'parent :: after()'調用! – biakaveron 2011-02-23 18:36:03

+0

但我想爲視圖設置默認值,如果它應該改變其他方法,那麼它將被改變,我不必爲其他方法設置其他值。 – PaulP 2011-02-24 08:19:54

回答

1

搭配chmod 777 /some_path/application/logs/2011/02/23.php文件和所有目錄/some_path/application/logs/遞歸

UPD:

也許

// views/index.php 
echo View::factory('default') 
->set('head', $head) 
->set('nav', $nav) 
->set('header', $header) 
->set('sidebar', $sidebar) 
->set('content', $content) 
->set('footer', $footer); 
+0

現在很奇怪它不能在默認視圖中看到變量:ErrorException [注意]:未定義的變量:nav | ErrorException [注意]:未定義變量:頭 – PaulP 2011-02-23 17:30:39

+0

@paulp,更新了帖子 – delphist 2011-02-23 17:36:11

+0

謝謝。我仍然在學習:D。 – PaulP 2011-02-23 17:38:42

0

發生了什麼事是Kohana的是拋出一個異常,並試圖記錄錯誤,但能不保存日誌文件。

確保/應用/日誌是寫(755,或777在某些服務器上)

+0

我已經做到了,但是會拋出一些錯誤:ErrorException [Notice]:Undefined variable:nav | ErrorException [注意]:未定義變量:頭 – PaulP 2011-02-23 17:33:53