Note that there are some explanatory texts on larger screens.

plurals
  1. POCall to a member function on a non-object
    text
    copied!<p>I'm working through <a href="http://rads.stackoverflow.com/amzn/click/1590599063" rel="nofollow noreferrer">Practical Web 2.0 Appications</a> currently and have hit a bit of a roadblock. I'm trying to get PHP, MySQL, Apache, Smarty and the Zend Framework all working correctly so I can begin to build the application. I have gotten the bootstrap file for Zend working, shown here:</p> <pre><code>&lt;?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-&gt;logging-&gt;file)); Zend_Registry::set('logger', $logger); // connect to the database $params = array('host' =&gt; $config-&gt;database-&gt;hostname, 'username' =&gt; $config-&gt;database-&gt;username, 'password' =&gt; $config-&gt;database-&gt;password, 'dbname' =&gt; $config-&gt;database-&gt;database); $db = Zend_Db::factory($config-&gt;database-&gt;type, $params); Zend_Registry::set('db', $db); // handle the user request $controller = Zend_Controller_Front::getInstance(); $controller-&gt;setControllerDirectory($config-&gt;paths-&gt;base . '/include/Controllers'); // setup the view renderer $vr = new Zend_Controller_Action_Helper_ViewRenderer(); $vr-&gt;setView(new Templater()); $vr-&gt;setViewSuffix('tpl'); Zend_Controller_Action_HelperBroker::addHelper($vr); $controller-&gt;dispatch(); ?&gt; </code></pre> <p>This calls the IndexController. The error comes with the use of this Templater.php to implement Smarty with Zend:</p> <pre><code>&lt;?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-&gt;_engine = new Smarty(); $this-&gt;_engine-&gt;template_dir = $config-&gt;paths-&gt;templates; $this-&gt;_engine-&gt;compile_dir = sprintf('%s/tmp/templates_c', $config-&gt;paths-&gt;data); $this-&gt;_engine-&gt;plugins_dir = array($config-&gt;paths-&gt;base . '/include/Templater/plugins', 'plugins'); } public function getEngine() { return $this-&gt;_engine; } public function __set($key, $val) { $this-&gt;_engine-&gt;assign($key, $val); } public function __get($key) { return $this-&gt;_engine-&gt;get_template_vars($key); } public function __isset($key) { return $this-&gt;_engine-&gt;get_template_vars($key) !== null; } public function __unset($key) { $this-&gt;_engine-&gt;clear_assign($key); } public function assign($spec, $value = null) { if (is_array($spec)) { $this-&gt;_engine-&gt;assign($spec); return; } $this-&gt;_engine-&gt;assign($spec, $value); } public function clearVars() { $this-&gt;_engine-&gt;clear_all_assign(); } public function render($name) { return $this-&gt;_engine-&gt;fetch(strtolower($name)); } public function _run() { } } ?&gt; </code></pre> <p>The error I am getting when I load the page is this:</p> <p><code>Fatal error: Call to a member function fetch() on a non-object in /var/www/phpweb20/include/Templater.php on line 60</code></p> <p>I understand it doesn't see $name as an object, but I don't know how to go about fixing this. Isn't the controller supposed to refer to the index.tpl? I haven't been able to discover what the $name variable represents and how to fix this to get the foundation working.</p> <p>Any help you have is much appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload