Kohana - 风景中的风景

发布于 2024-10-19 01:09:08 字数 2338 浏览 1 评论 0原文

我在通过视图传递变量时遇到问题。但是,首先是一些代码

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

它显示有效;

I have problem with passing variables through views. But, first some code

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

And in view index i pass variables to the default 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);

And i try in display view i try "echo" variables:

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

And it throw error:

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 ]

If i write something like that:

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

it display valid;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゝ杯具 2024-10-26 01:09:08

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

chmod 777 /some_path/application/logs/2011/02/23.php file and all directory /some_path/application/logs/ recursively

UPD:

maybe

// 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);
寒江雪… 2024-10-26 01:09:08

发生的情况是 Kohana 抛出异常并尝试记录错误,但无法保存日志文件。

确保 /application/logs 可写(某些服务器上为 755 或 777)

What's happening is Kohana is throwing an exception and trying to log the error, but can't save the log file.

Make sure /application/logs is writable (755, or 777 on some servers)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文