我目前正在使用Practical Web 2.0 Appications,并且遇到了一些障碍.我正在尝试让PHP,MySQL,Apache,Smarty和Zend Framework都正常工作,这样我就可以开始构建应用程序了.我已经获得了Zend工作的bootstrap文件,如下所示:
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与Zend实现Smarty时出现错误:
_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
我知道它没有看到$ name作为对象,但我不知道如何解决这个问题.是不是控制器应该引用index.tpl?我无法发现$ name变量代表什么以及如何解决这个问题以使基础工作.
非常感谢您提供的任何帮助!
问题不在于$ name变量,而在于$ _engine变量.它目前是空的.您需要验证Smarty.class.php的路径规范是否正确.
您可以尝试这个来开始调试:
$this->_engine = new Smarty(); print_r($this->_engine);
如果事实证明$ _engine在该阶段是正确的,那么验证它仍然在render()函数中正确填充.