2008-10-31 15 views
6

पर किसी सदस्य फ़ंक्शन पर कॉल करें, मैं वर्तमान में Practical Web 2.0 Appications के माध्यम से काम कर रहा हूं और कुछ रोडब्लॉक मारा है। मैं PHP, MySQL, Apache, Smarty और Zend Framework को सही तरीके से काम करने की कोशिश कर रहा हूं, इसलिए मैं एप्लिकेशन बनाना शुरू कर सकता हूं।किसी गैर-ऑब्जेक्ट

<?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 कॉल: मैं Zend कार्य करने के लिए बूटस्ट्रैप फ़ाइल, यहाँ दिखाया गया है मिल गया है। त्रुटि Zend के साथ चतुर लागू करने के लिए इस Templater.php के उपयोग के साथ आता है:

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

मैं समझता हूँ कि यह नहीं करता है:

<?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() 
     { } 
    } 
?> 

त्रुटि जब मैं पृष्ठ लोड मैं हो रही है यह है ऑब्जेक्ट के रूप में $ नाम नहीं दिखता है, लेकिन मुझे नहीं पता कि इसे ठीक करने के बारे में कैसे जाना है। नियंत्रक को index.tpl को संदर्भित नहीं किया जाना चाहिए? मैं यह जानने में सक्षम नहीं हूं कि $ नाम परिवर्तक क्या दर्शाता है और नींव को काम करने के लिए इसे कैसे ठीक किया जाए।

आपकी कोई भी मदद बहुत सराहना की है!

+0

दरअसल, बग यह नहीं है कि $ नाम संदिग्ध है, यह है कि यह $ -> _ इंजन संदिग्ध है - यही वह है जो पार्सर किसी ऑब्जेक्ट के रूप में नहीं देखता है। –

उत्तर

5

समस्या $ नाम परिवर्तनीय के साथ नहीं बल्कि $ _engine चर के साथ है। यह वर्तमान में खाली है। आपको यह सत्यापित करने की आवश्यकता है कि Smarty.class.php पर पथ विनिर्देश सही है।

आप अपने डिबगिंग शुरू करने के लिए इस कोशिश कर सकते हैं:

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

यदि ऐसा पाया जाता है कि $ _engine फिर सत्यापित करें कि यह अभी भी सही ढंग से प्रस्तुत करना() फ़ंक्शन के भीतर से भर जाता है कि मंच पर सही है। http://framework.zend.com/manual/en/zend.view.scripts.html#zend.view.scripts.templates.interface

है कि आप एक कस्टम समाधान डिबग करने के लिए कोशिश कर रहा से कुछ समय बचाने हो सकता है:

0

Zend एक templating प्रणाली जो Zend_View_Interface यहाँ लागू करता है बनाने का एक उदाहरण है।

0

कक्षा से __construct विधि को हटाने, उसी समस्या को हल किया गया जिसका सामना करना पड़ रहा था।

0

__construct() से Tempater() नामकरण मेरे लिए काम किया।