سؤال

وأعمل من خلال الويب العملي 2.0 Appications حاليا، وقد بلغت قليلا من حاجز. أنا أحاول الحصول على PHP و MySQL، اباتشي، هندى وإطار زند عن العمل بشكل صحيح حتى أتمكن من البدء في بناء التطبيق. لقد حصلت على ملف التمهيد لعمل زند، كما هو موضح هنا:

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

وهذا يدعو IndexController. ويأتي هذا الخطأ مع استخدام هذا Templater.php لتنفيذ هندى مع زند:

<?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 هو الصحيح في تلك المرحلة ثم تحقق من أنه لا يزال بشكل صحيح بالسكان داخل الدالة على تقديم ().

نصائح أخرى

وزند ديه مثال على إنشاء نظام النموذجيه التي تنفذ Zend_View_Interface هنا: <لأ href = "http://framework.zend.com/manual/en/zend.view.scripts.html#zend.view.scripts .templates.interface "يختلط =" نوفولو noreferrer "> http://framework.zend.com/manual/en/zend.view.scripts.html#zend.view.scripts.templates.interface

وهذا قد يوفر لك بعض الوقت من محاولة تصحيح الحلول مخصصة.

وإزالة طريقة __construct، من الطبقة، حل مشكلة مشابهة كنت تواجهها.

وإعادة تسمية __construct() إلى Tempater() عملت بالنسبة لي.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top