문제

나는 일하고있다 실용적인 웹 2.0 appications 현재 그리고 약간의 장애물을 쳤다. PHP, MySQL, Apache, Smarty 및 Zend 프레임 워크가 모두 올바르게 작동하여 응용 프로그램을 구축 할 수 있습니다. 여기에 표시된 Zend Working을위한 부트 스트랩 파일을 받았습니다.

<?php
    require_once('Zend/Loader.php');
    Zend_Loader::registerAutoload();

    // load the application configuration
    $config = new Zend_Config_Ini('../settings.ini', 'development');
    Zend_Registry::set('config', $config);


    // create the application logger
    $logger = new Zend_Log(new Zend_Log_Writer_Stream($config->logging->file));
    Zend_Registry::set('logger', $logger);


    // connect to the database
    $params = array('host'     => $config->database->hostname,
                    'username' => $config->database->username,
                    'password' => $config->database->password,
                    'dbname'   => $config->database->database);

    $db = Zend_Db::factory($config->database->type, $params);
    Zend_Registry::set('db', $db);


    // handle the user request
    $controller = Zend_Controller_Front::getInstance();
    $controller->setControllerDirectory($config->paths->base .
                                        '/include/Controllers');

    // setup the view renderer
    $vr = new Zend_Controller_Action_Helper_ViewRenderer();
    $vr->setView(new Templater());
    $vr->setViewSuffix('tpl');
    Zend_Controller_Action_HelperBroker::addHelper($vr);

    $controller->dispatch();
?>

인덱스 콘트롤러를 호출합니다. 오류는이 templater.php를 사용하여 Zend를 사용하여 Smarty를 구현합니다.

<?php
    class Templater extends Zend_View_Abstract
    {
        protected $_path;
        protected $_engine;

        public function __construct()
        {
            $config = Zend_Registry::get('config');

            require_once('Smarty/Smarty.class.php');

            $this->_engine = new Smarty();
            $this->_engine->template_dir = $config->paths->templates;
            $this->_engine->compile_dir = sprintf('%s/tmp/templates_c',
                                                  $config->paths->data);

            $this->_engine->plugins_dir = array($config->paths->base .
                                                '/include/Templater/plugins',
                                                'plugins');
        }

        public function getEngine()
        {
            return $this->_engine;
        }

        public function __set($key, $val)
        {
            $this->_engine->assign($key, $val);
        }

        public function __get($key)
        {
            return $this->_engine->get_template_vars($key);
        }

        public function __isset($key)
        {
            return $this->_engine->get_template_vars($key) !== null;
        }

        public function __unset($key)
        {
            $this->_engine->clear_assign($key);
        }

        public function assign($spec, $value = null)
        {
            if (is_array($spec)) {
                $this->_engine->assign($spec);
                return;
            }

            $this->_engine->assign($spec, $value);
        }

        public function clearVars()
        {
            $this->_engine->clear_all_assign();
        }

        public function render($name)
        {
            return $this->_engine->fetch(strtolower($name));
        }

        public function _run()
        { }
    }
?>

페이지를로드 할 때 얻는 오류는 다음과 같습니다.

Fatal error: Call to a member function fetch() on a non-object in /var/www/phpweb20/include/Templater.php on line 60

나는 그것이 $ 이름을 객체로 보지 않는다는 것을 이해하지만, 이것을 고치는 방법을 모르겠습니다. 컨트롤러가 index.tpl을 참조해야합니까? $ 이름 변수가 무엇을 나타내는 지 알 수 없었고 재단이 작동하도록이를 해결하는 방법을 발견 할 수 없었습니다.

당신이 가진 모든 도움은 대단히 감사합니다!

도움이 되었습니까?

해결책

문제는 $ 이름 변수가 아니라 $ _engine 변수와 관련이 있습니다. 현재 비어 있습니다. smarty.class.php에 대한 경로 사양이 올바른지 확인해야합니다.

디버깅을 시작하려면 다음을 시도 할 수 있습니다.

$this->_engine = new Smarty();
print_r($this->_engine);

해당 단계에서 $ _engine이 올바른 것으로 밝혀지면 Render () 함수 내에서 여전히 올바르게 채워 졌는지 확인하십시오.

다른 팁

Zend는 Zend_view_interface를 구현하는 템플릿 시스템을 만드는 예를 가지고 있습니다. http://framework.zend.com/manual/nend.view.scripts.html#zend.view.scripts.templates.interface

이는 사용자 정의 솔루션을 디버깅하는 데 시간을 절약 할 수 있습니다.

수업에서 __construct 방법을 제거하면 내가 직면 한 유사한 문제를 해결했습니다.

이름 변경 __construct() 에게 Tempater() 나를 위해 일했습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top