Переменная $ Kohana template ничего не показывает - PullRequest
0 голосов
/ 27 января 2012

У меня есть контроллер Kohana, который расширяет класс шаблона Kohana.Шаблонный класс Kohana имеет

const CONTENT_KEY = 'content';

В этом контроллере я объявил использование шаблона:

public $template = 'homepage_template';

Также в этом контроллере у меня есть несколько методов и некоторые связанные представления.

Имея все это, когда я echo $content в представлении homepage_template , ничего не отображается (содержимое представлений, принадлежащих действиям этого контроллера, отсутствует).(У меня есть auto_render true в действиях).Что может быть причиной этого?

1 Ответ

1 голос
/ 05 февраля 2012

Вот как я использую Template Controller, надеюсь, это поможет:

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Template_Default extends Controller_Template
{
    public $template = 'templates/default';

    protected $auth;

    protected $user;

    public function before()
    {
        parent::before();

        Session::instance();

        $this->auth = Auth::instance();     

        if (($this->user = $this->auth->get_user()) === FALSE)
        {
            $this->user = ORM::factory('user');
        }

        if($this->auto_render)
        {
            $this->template->title            = '';
            $this->template->meta_keywords    = '';
            $this->template->meta_description = '';
            $this->template->meta_copywrite   = '';
            $this->template->header           = '';
            $this->template->content          = '';
            $this->template->footer           = '';
            $this->template->styles           = array();
            $this->template->scripts          = array();
            $this->template->bind_global('user', $this->user);
        }
    }

    public function after()
    {
        if($this->auto_render)
        {
                $styles                  = array('css/default.css' => 'screen', 'css/reset.css' => 'screen');
                $scripts                 = array('js/infieldlabel.js', 'js/menu.js', 'js/jquery.js');

                $this->template->styles  = array_reverse(array_merge($this->template->styles, $styles));
                $this->template->scripts = array_reverse(array_merge($this->template->scripts, $scripts));
            }

        parent::after();
    }
} // End Controller_Template_Default

PS вы не должны использовать константу для контента.Расширьте свой контроллер из Controller_TEemplate_Default и привяжите его как $ this-> template-> content = View :: factory ('path to the view');

...