<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Thijs Lensselink&#039;s Blog &#187; Zend Framework</title>
	<atom:link href="http://lenss.nl/tag/zend-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://lenss.nl</link>
	<description>Webdevelopment and stuff...</description>
	<lastBuildDate>Mon, 06 Feb 2012 20:37:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Zend Framework Bootstrapping Modules</title>
		<link>http://lenss.nl/2010/02/zend-framework-bootstrapping-modules/</link>
		<comments>http://lenss.nl/2010/02/zend-framework-bootstrapping-modules/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 20:04:38 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Bootstrap]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=692</guid>
		<description><![CDATA[I am working on a small API for bluesignal and i wanted a modular architecture. I have done this before using the Zend Framework. But this time i wanted a bit more control while loading the modules. And adding a Bootstrap class would seem like a good option. The only example i could find involved [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on a small API for <a href="http://bluesignal.nl">bluesignal</a> and i wanted a modular architecture. I have done this before using the Zend Framework. But this time i wanted a bit more control while loading the modules. And adding a <a href="http://0x.vc/k">Bootstrap</a> class would seem like a good option. The only example i could find involved loading all bootstraps on every request. Which doesn&#8217;t seem like a good idea. So after reading through the Manual and some blog posts. I decided to give it s shot my self.</p>
<p>The structure i want looks like this.</p>
<p><a href="http://lenss.nl/wp-content/uploads/2010/02/module-based.jpg"><img src="http://lenss.nl/wp-content/uploads/2010/02/module-based.jpg" alt="" title="module-based" width="318" height="327" class="aligncenter size-full wp-image-701" /></a></p>
<p>The application.ini file has the following contents:</p>
<blockquote><p>includePaths.library = APPLICATION_PATH &#8220;/../library&#8221;<br />
bootstrap.path = APPLICATION_PATH &#8220;/Bootstrap.php&#8221;<br />
bootstrap.class = &#8220;Bootstrap&#8221;<br />
resources.frontController.moduleDirectory = APPLICATION_PATH &#8220;/modules&#8221;<br />
resources.modules[] = &#8220;default&#8221;<br />
resources.modules[] = &#8220;admin&#8221;</p></blockquote>
<p><strong>includePaths</strong><br />
This sets the applications local library location. Any shared code for this application goes here.</p>
<p><strong>bootstrap.path &#038; class</strong><br />
Define the location and type of the Bootstrap class.</p>
<p><strong>resources</strong><br />
Define the modules location and create a list of modules.</p>
<p>The main Bootstrap class</p>
<p><strong>application/Bootstrap.php</strong></p>
<pre name="code" class="php">
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
</pre>
<p>Load the config parameters for this application and set some debugging settings if needed.</p>
<pre name="code" class="php">
    protected function _initConfiguration()
    {
    	$app = $this->getApplication();
    	$config = $app->getOptions();

    	if (APPLICATION_ENV == 'development') {
	    	    error_reporting(E_ALL &#038; E_STRICT);
	    	    if (isset($config['phpsettings'])) {
		    	        foreach ($config['phpsettings'] as $setting => $value) {
		    		        ini_set($setting, $value);
		    	        }
	    	    }
    	}
    }
</pre>
<p>We need autoloading here because we are using a class from the application library. Right now this causes a problem. A notice is thrown </p>
<blockquote><p>Warning: include_once(FrontController.php) [function.include-once]: failed to open stream: No such file or directory in Zend/Loader.php  on line 147</p></blockquote>
<p>The application responds fine. And this problem seems to be a recurring issue (<a href="http://0x.vc/l">ZF-7224</a>, <a href="http://0x.vc/m">ZF-7550</a>) for the framework. Until now i have not find a graceful fix for this. besides a small <a href="http://0x.vc/n">patch</a> reversion.</p>
<pre name="code" class="php">
    protected function _initAutoload()
    {
		    $autoloader = Zend_Loader_Autoloader::getInstance();
		    $autoloader->setFallbackAutoloader(true);

		    return $autoloader;
    }
</pre>
<p>Setup the controller to register the <strong>Bluess_Modules_Loader</strong> plug-in. And set the <strong>prefixDefaultModule</strong> parameter so we can prefix the default module controllers as well. Just for the sake of consistency. The <strong>Bluess_</strong> namespace is part of my API. And can be changed at will.</p>
<pre name="code" class="php">
   protected function _initController()
    {
    	$this->bootstrap('FrontController');
    	$controller = $this->getResource('FrontController');
       $modules = $controller->getControllerDirectory();
       $controller->setParam('prefixDefaultModule', true);

        $controller->registerPlugin(
               new Bluess_Modules_Loader($modules)
        );

        return $controller;
    }
</pre>
<p>Now the last method. which is a bit weird. And i am probably missing a key factor here. But if this method <strong>resource</strong> is not declared only the default module functions. When declared empty all modules function as they should. This would indicate that this method could be used to load the modules. But i haven&#8217;t found a way to achieve this yet. Except for loading all modules in a row. Which makes no sense for this purpose. So we leave it empty.</p>
<pre name="code" class="php">
protected function _initModules()
    {
		// Call to prevent ZF from loading all modules
    }
</pre>
<p>The most important part here is the controller plug-in. This will be the place where module bootstraps are called from.</p>
<p><strong>application/../library/Bluess/Modules/Loader.php</strong></p>
<pre name="code" class="php">
class Bluess_Modules_Loader extends Zend_Controller_Plugin_Abstract
{
	protected $_modules;
</pre>
<p>Setup the plug-in by passing the applications module list.</p>
<pre name="code" class="php">
	public function __construct(array $modulesList)
	{
		$this->_modules = $modulesList;
	}
</pre>
<p>The <strong>dispatchLoopStartup</strong> method will be called on every request and will do the magic. Based on the current module name we create a new <strong>Zend_Application</strong> with the current modules config file <strong>module.ini</strong>. And we bootstrap it.</p>
<pre name="code" class="php">
	public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
	{
		$module = $request->getModuleName();

		if (!isset($this->_modules[$module])) {
			throw new Exception("Module does not exist!");
		}

		$bootstrapPath = $this->_modules[$module];

		$bootstrapFile = dirname($bootstrapPath) . '/Bootstrap.php';
        $class         = ucfirst($module) . '_Bootstrap';
        $application   = new Zend_Application(
        	APPLICATION_ENV,
    		APPLICATION_PATH . '/modules/' . $module . '/configs/module.ini'
		);  

        if (Zend_Loader::loadFile('Bootstrap.php', dirname($bootstrapPath))
        	&#038;&#038; class_exists($class)) {
            $bootstrap = new $class($application);
            $bootstrap->bootstrap();
        }
	}
}
</pre>
<p>Now setup the default module. Once this is done it&#8217;s a nice example for further modules. Make sure the module has it&#8217;s own layout set. </p>
<p><strong>application/modules/default/configs/module.ini</strong></p>
<blockquote><p>default.resources.layout.layout = &#8220;default&#8221;<br />
default.resources.layout.layoutPath = APPLICATION_PATH &#8220;/modules/default/layout&#8221;</p></blockquote>
<p>Setup the modules bootstrap and use it to set the modules model location.</p>
<p><strong>application/modules/default/Bootstrap.php</strong></p>
<pre name="code" class="php">
class Default_Bootstrap extends Zend_Application_Module_Bootstrap
{
	protected $_moduleName = 'default';

	protected function _initConfiguration()
    {
		$options = $this->getApplication()->getOptions();

    	set_include_path(implode(PATH_SEPARATOR, array(
		    realpath(APPLICATION_PATH . '/modules/' . $this->_moduleName . '/models'),
		    get_include_path(),
		)));

		return $options;
    }
}
</pre>
<p>That&#8217;s all. Now make sure your layout is set correctly and the controllers are prefixed</p>
<p><strong>application/modules/default/layout/default.phtml</strong></p>
<pre name="code" class="php">
echo $this->layout()->content;
</pre>
<p><strong>application/modules/default/controllers/IndexController.php</strong></p>
<pre name="code" class="php">
class Default_IndexController extends Zend_Controller_Action
{
</pre>
<p>It took me a while to get this working like i had it in my mind. But it&#8217;s going the right way. If your interested in a working copy. You can download one <a href="http://0x.vc/j">here</a>.</p>
<p><strong>UPDATE</strong></p>
<p>Matthew has a nice <a href="http://weierophinney.net/matthew/archives/234-Module-Bootstraps-in-Zend-Framework-Dos-and-Donts.html#extended">post </a>about some do&#8217;s and don&#8217;ts concerning module based applications</p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2010/02/zend-framework-bootstrapping-modules/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Cache data with Zend Framework and Memcached</title>
		<link>http://lenss.nl/2010/01/cache-data-with-zend-framework-and-memcached/</link>
		<comments>http://lenss.nl/2010/01/cache-data-with-zend-framework-and-memcached/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 11:26:19 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[Memcached]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=665</guid>
		<description><![CDATA[Last week i had the chance to work with memcache. Something i hadn&#8217;t done before. For caching i mostly rely on APC for bytecode. And file based caching for content. Using memecache extension for PHP and de memcached service gives a whole range of features for caching data. And an easy way to manage all [...]]]></description>
			<content:encoded><![CDATA[<p>Last week i had the chance to work with memcache. Something i hadn&#8217;t done before. For caching i mostly rely on APC for bytecode. And file based caching for content. Using memecache extension for PHP and de memcached service gives a whole range of features for caching data. And an easy way to manage all this cached data.</p>
<p>The project i am working on is based on Zend Framework. And there for this post will reflect working with memcache in ZF only. With ZF and memcache it&#8217;s possible to do frontend and backend caching. I will focuse on the backend side for now. But will setup the frontend as well.</p>
<p>If you don&#8217;t have memcache installed do it now. It&#8217;s not that hard. On my debian box it went somethign like this:</p>
<blockquote><p>$ aptitude install memcached<br />
$ aptitude install php5-memcache</p></blockquote>
<p>Now a days evrything seems to go automatic. So no need to edit the php.ini or anyhting. To check if PHP loaded the memcache extension you can do:</p>
<blockquote><p>$ php -m | grep memcache<br />
memcache</p></blockquote>
<p>Memached is automatically started after install. So let&#8217;s check if everything went ok.</p>
<blockquote><p>$ ps -aux | grep memcached<br />
nobody   20965  0.0  0.5  42900 23072 ?        S    Jan28   0:01 /usr/bin/memcached -m 64 -p 11211 -u nobody -l 127.0.0.1<br />
root     22393  0.0  0.0  87940   776 pts/0    R+   12:06   0:00 grep memcached</p></blockquote>
<blockquote><p>
$ netstat -an | grep 11211<br />
tcp        0      0 127.0.0.1:11211         0.0.0.0:*               LISTEN</p></blockquote>
<p>Looking good. Now it&#8217;s time to do some configuration in ZF.</p>
<p>First of the frontend settings. With &#8216;type&#8217; we set the cache method for the frontend. We chose the standard Core class for this. With &#8216;lifetime&#8217; we set the time for which a cached entity is valid. The &#8216;cache_id_prefix&#8217; is a nice way to group for instnace cache data by controller. So just give it a name.</p>
<blockquote><p>cache.frontend.type = Core<br />
cache.frontend.options.lifetime = 600<br />
cache.frontend.options.automatic_serialization = true<br />
cache.frontend.options.cache_id_prefix = [some string]<br />
cache.frontend.options.cache = true</p></blockquote>
<p>Now it&#8217;s the backends turn to get configured. For &#8216;type&#8217; we choose Memcached. More types are available. For more info read the ZF manual. The rest of the settings are basic memcached settings like host, port and persitance.</p>
<blockquote><p>cache.backend.type = Memcached<br />
cache.backend.options.servers.1.host = 127.0.0.1<br />
cache.backend.options.servers.1.port = 11211<br />
cache.backend.options.servers.1.persistent = true<br />
cache.backend.options.servers.1.weight = 1<br />
cache.backend.options.servers.1.timeout = 5<br />
cache.backend.options.servers.1.retry_interval = 15</p></blockquote>
<p>Finally we can do some PHP code. To get the cache instance setup we add a _initCache() method to the bootstrap class. Inside this method we retrieve the config options by calling getOptions(). And setup the cache object. Which is then stored in the Registry for later use.</p>
<pre name="code" class="php">
protected function _initCache()
{
        $options = $this->getOptions();

        if (isset($options['cache'])) {
            $cache = Zend_Cache::factory(
                $options['cache']['frontend']['type'],
                $options['cache']['backend']['type'],
                $options['cache']['frontend']['options'],
                $options['cache']['backend']['options']
            );

            Zend_Registry::set('cache', $cache);
            return $cache;
        }
}
</pre>
<p>That&#8217;s all set. I used the caching for some REST service responses. So i will stick to that in this post as well. The class has a method for adding a cache object.</p>
<pre name="code" class="php">
public function setCache(Zend_Cache_Core $cache) {
    $this->cache = $cache;
}
</pre>
<p>So fetching the cache instance and passing it to the REST client will look something like this:</p>
<pre name="code" class="php">
$cache = Zend_Registry::get('cache');
$cache->setLifetime(86400);

$client = new Client();
$client->setCache($cache);
</pre>
<p>The first thing we do inside the calling method is set a unique key for the cache entry.</p>
<pre name="code" class="php">
$cache_id = 'getPage_' . $this->getDomain()
            . $this->getPageName()
            . $this->getCountry();
</pre>
<p>Then we check if the cache object is set. If that&#8217;s the case we check to see if the unique key is already available in the cache.</p>
<pre name="code" class="php">
if (!isset($this->cache) || !($ret = $this->cache->load($cache_id))) {
</pre>
<p>If a value is returned from the cahce we will return it. If not then we will do the webservice call and store the return data in cache.</p>
<pre name="code" class="php">
 $ret = $this->restClient->call('getPage', array());

if (isset($this->cache)) {
    $this->cache->save($ret, $cache_id);
}
</pre>
<p>The complete method looks something like this.</p>
<pre name="code" class="php">
protected function getPageFromWebservice()
{
        $cache_id = 'getPage_' . $this->getDomain()
            . $this->getPageName()
            . $this->getCountry();

        if (!isset($this->cache) || !($ret = $this->cache->load($cache_id))) {
            $ret = $this->restClient->call('getPage', array());

            if (isset($this->cache)) {
                $this->cache->save($ret, $cache_id);
            }
        }
        return $ret;
}
</pre>
<p>That&#8217;s all. It&#8217;s pretty basic stuff. But so cool!</p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2010/01/cache-data-with-zend-framework-and-memcached/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mayflower&#8217;s Zend Framework Poster</title>
		<link>http://lenss.nl/2009/07/mayflowers-zend-framework-poster/</link>
		<comments>http://lenss.nl/2009/07/mayflowers-zend-framework-poster/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 19:48:11 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Poster]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=511</guid>
		<description><![CDATA[Two or three weeks ago i was reading post from Bjoern Schotte. That the guys at Mayflower created a poster for Zend Framework. Seems they really love it there. And since i am a big fan myself. I send Bjoern an email to ask for an English version. If available. So some time passed. And [...]]]></description>
			<content:encoded><![CDATA[<p>Two or three weeks ago i was <a href="http://blog.thinkphp.de/archives/399-Mayflower-loves-Zend-Framework.html">reading post</a> from <a href="http://blog.thinkphp.de/">Bjoern Schotte</a>. That the guys at <a href="http://www.mayflower.de">Mayflower</a> created a poster for Zend Framework. Seems they really love it there. And since i am a big fan myself. I send Bjoern an email to ask for an English version. If available. So some time passed. And i completely forgot about it. Until i came home yesterday and found my own personal copy of the Mayflower Zend Framework poster in the mail.</p>
<p><a href="http://lenss.nl/wp-content/uploads/2009/07/mayflower-zf-map.jpg"><img src="http://lenss.nl/wp-content/uploads/2009/07/mayflower-zf-map-300x205.jpg" alt="mayflower-zf-map" title="mayflower-zf-map" width="300" height="205" class="aligncenter size-medium wp-image-513" /></a></p>
<p>It&#8217;s a cool poster. All the most common used components are there. A nice reference to have. And a great piece of promotion material for the <a href="http://framework.zend.com/">framework</a> it self. Now i just need to find a good spot for it. It will be the second A0 poster hanging here. And probably not the last one. Since mister PHP security himself Stefan Esser from <a href="http://www.sektioneins.de/">SektionEins</a> is working on a PHP security poster. If you would like your own copy. Send Bjoern an email.</p>
<p>Thanks guys.</p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2009/07/mayflowers-zend-framework-poster/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Zend Framework v1.8x Zend_Loader replacement</title>
		<link>http://lenss.nl/2009/06/zend-framework-v1-8x-zend_loader-replacement/</link>
		<comments>http://lenss.nl/2009/06/zend-framework-v1-8x-zend_loader-replacement/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 08:39:14 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[AutoLoader]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Zend_Loader]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=488</guid>
		<description><![CDATA[Last night i was trying to push a application to my staging environment. When i noticed an error i didn&#8217;t had on my local box. Notice: Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead in /path/to/Zend/Loader.php on line 207 A quick check revealed that i had a newer [...]]]></description>
			<content:encoded><![CDATA[<p>Last night i was trying to push a application to my <a href="http://en.wikipedia.org/wiki/Staging_(websites)">staging</a> environment. When i noticed an error i didn&#8217;t had on my local box.</p>
<blockquote><p>Notice: Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead in /path/to/Zend/Loader.php on line 207</p></blockquote>
<p>A quick check revealed that i had a newer version of the <a href="http://framework.zend.com/">Zend Framework</a> loaded on my staging environment. Locally i have 1.7x and on the staging environment i have 1.8x. And according to the documentation the old Zend_Loader is being deprecated in favor of <a href="http://framework.zend.com/manual/en/zend.loader.autoloader.html">Zend_Loader_Autoloader</a>.</p>
<p>So in ZF projects prior to version 1.8x when enabling <a href="http://nl2.php.net/manual/en/language.oop5.autoload.php">autoloading</a> we would do something like this:</p>
<pre name="code" class="php">
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
</pre>
<p>With the new Zend_Loader_AutoLoader this will look something like this:</p>
<pre name="code" class="php">
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('Namespace_');
</pre>
<p>Notice the call to &#8216;registerNamespace&#8217;. This is where you set the namespacing for the classes or application libraries. By default the AutoLoader picks up Zend_ and ZendX_ namespacing. And we can extend this to use our own classes and libraries.</p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2009/06/zend-framework-v1-8x-zend_loader-replacement/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Zend_Db connects to wrong mysql socket</title>
		<link>http://lenss.nl/2009/06/zend_db-connects-to-wrong-mysql-socket/</link>
		<comments>http://lenss.nl/2009/06/zend_db-connects-to-wrong-mysql-socket/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 09:12:19 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[PDO]]></category>
		<category><![CDATA[Socket]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Zend_Db]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=484</guid>
		<description><![CDATA[While working on a small project today. I was confronted with a Zend_Db exception that i have seen before. But it still had me searching for a solution. So this time i will write it done for future reference. I&#8217;m working on a small ZF project which uses the MVC structure. And in the Initializer [...]]]></description>
			<content:encoded><![CDATA[<p>While working on a small project today. I was confronted with a Zend_Db exception that i have seen before. But it still had me searching for a solution. So this time i will write it done for future reference.</p>
<p>I&#8217;m working on a small ZF project which uses the MVC structure. And in the Initializer the database connection is setup like this:</p>
<pre name="code" class="php">
public function initDb()
    {
    	$pdoParams = array(
            PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
        );

        $params = array(
            'host'     => 'localhost',
            'username' => '***********',
            'password' => '***********',
            'dbname'   => '***********',
            'driver_options' => $pdoParams,
        );

        $db = Zend_Db::factory('Pdo_Mysql', $params);
        Zend_Db_Table_Abstract::setDefaultAdapter($db);
        Zend_Registry::set('DB', $db);
    }
</pre>
<p>So when i first instantiated a connection to the database i was presented a nice error on screen. The stack trace is quiet long. But this is the most relevant part.</p>
<blockquote><p>exception &#8216;Zend_Db_Adapter_Exception&#8217; with message &#8216;SQLSTATE[HY000] [2002] Can&#8217;t connect to local MySQL server through socket &#8216;/tmp/mysql.sock&#8217; (2)&#8217;</p></blockquote>
<p>The php bug tracker revealed a nice <a href="http://bugs.php.net/bug.php?id=34988">solution</a>. For some strange reason the PDO extension can&#8217;t determine the correct socket while the mysql, mysqli extensions can. This is easily solved in the bootstrap of the project by adding an extra parameter to the config array passed when calling Zend_Db::factory();</p>
<pre name="code" class="php">
$params = array(
            'host'     => 'localhost',
            'username' => '***********',
            'password' => '***********',
            'dbname'   => '***********',
            'driver_options' => $pdoParams,
            'unix_socket' => '/var/run/mysqld/mysqld.sock'
        );

        $db = Zend_Db::factory('Pdo_Mysql', $params);
        Zend_Db_Table_Abstract::setDefaultAdapter($db);
        Zend_Registry::set('DB', $db);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2009/06/zend_db-connects-to-wrong-mysql-socket/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Zend Framework BaseUrl Helper</title>
		<link>http://lenss.nl/2008/07/zend-framework-baseurl-helper/</link>
		<comments>http://lenss.nl/2008/07/zend-framework-baseurl-helper/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 14:42:36 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[BaseUrl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://we.designandco.de/?p=19</guid>
		<description><![CDATA[Today i was working with the Zend Framework. And needed the baseUrl to set the correct path for stylesheets and external javascript files. To include stylesheets and javascript files there are methods available in ZF. In your controller you can set: $this-&#62;view-&#62;headLink()-&#62;appendStylesheet('/css/tester.css'); In your view or layout you can then call $this-&#62;headLink(); This works great. [...]]]></description>
			<content:encoded><![CDATA[<p>Today i was working with the <a href="http://framework.zend.com" target="_blank">Zend Framework</a>. And needed the baseUrl to set the correct path for stylesheets and external javascript files. To include stylesheets and javascript files there are methods available in ZF. In your controller you can set:</p>
<pre name="code" class="php">$this-&gt;view-&gt;headLink()-&gt;appendStylesheet('/css/tester.css');</pre>
<p>In your view or layout you can then call</p>
<pre lang="php">$this-&gt;headLink();</pre>
<p>This works great. But the current development structure lacks some good rewrite rules. And having the baseUrl is always a good thing. So i did some searching on Google. To figure out if somebody already has a solution for this problem. After a few minutes i found a post written by <a href="http://www.spotsec.com/blog/archive/2007/12/14/zend-framework-baseurl-view-helper/" target="_blank">Yusak Setiawan</a> from <a href="http://www.zendindonesia.com/" target="_blank">zendindonesia</a> (which is defaced by the way) explaining how to add a placeholder in the bootstrap file. Now this is a good solution. But i like to keep my bootstrap file as clean as possible. So i decided to add a Helper that would do the trick.</p>
<p>Create a file called &#8216;BaseUrl.php&#8217; inside the Helper directory. And fill it with the following code.</p>
<pre name="code" class="php">class Zend_View_Helper_BaseUrl
{
    function baseUrl()
    {
        $base_url = substr($_SERVER['PHP_SELF'], 0, -9);
        return $base_url;
    }
}</pre>
<p>After that it&#8217;s extremly easy to get the baseUrl in your views, layouts or controllers.</p>
<p>Inside the view or layout you can call:</p>
<pre name="code" class="php">$this-&gt;baseUrl();</pre>
<p>And inside the controller you can call it like this.</p>
<pre name="code" class="php">$this-&gt;view-&gt;baseUrl();</pre>
<p><a href="http://blog.motane.lu/2009/01/31/zend-framework-base-url/">Tudor Barbu</a> wrote a great article on this subject.</p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2008/07/zend-framework-baseurl-helper/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Zend Framework is confused</title>
		<link>http://lenss.nl/2008/06/zend-framework-is-confused/</link>
		<comments>http://lenss.nl/2008/06/zend-framework-is-confused/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 14:46:41 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://we.designandco.de/?p=15</guid>
		<description><![CDATA[I decided to give the Zend Framework a try. The first attempt to create a simple SOAP based login. In the first few hours i had absolutely now problems building my small application. But for some strange reason after a few hours ZF started to throw error&#8217;s. Mainly for files it was trying to include. [...]]]></description>
			<content:encoded><![CDATA[<p>I decided to give the <a href="http://framework.zend.com/" target="_blank">Zend Framework</a> a try. The first attempt to create a simple SOAP based login.</p>
<p>In the first few hours i had absolutely now problems building my small application. But for some strange reason after a few hours ZF started to throw error&#8217;s. Mainly for files it was trying to include. These files were in the correct location. Nothing changed. The include path was still set correctly. I found a few bug reports with similar problems. Although there were some solutions. I was not satisfied with them. And had the feeling the problems were caused by something else.</p>
<p>So after i read threw all code. I notice a few lines i copied from <a href="http://www.calevans.com/" target="_blank">Cal Evans</a> <a href="http://phparch.com/c/books/id/9780973862157" target="_blank">book</a>. These lines mainly set the include_path for the current application. And it looked something like this:</p>
<pre name="code" class="php">$lib_paths = array();
$lib_paths[] = "/path/to/application";
$lib_paths[] = "/path/to/library";
$inc_path = implode(PATH_SEPARATOR, $lib_paths);
set_include_path($inc_path);</pre>
<p>I noticed the application directory was added first. So this is also the first part where PHP starts looking for it&#8217;s include files. So i decided to switch them. So the code looks like this now:</p>
<pre name="code" class="php">$lib_paths = array();
$lib_paths[] = "/path/to/library";
$lib_paths[] = "/path/to/application";
$inc_path = implode(PATH_SEPARATOR, $lib_paths);
set_include_path($inc_path);</pre>
<p>After this change the problem seems to have been resolved. I still would like to figure out why ZF has problems with finding it&#8217;s own include files. Maybe it&#8217;s a combination of the wrong include order and the .htaccess file not working well together.</p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2008/06/zend-framework-is-confused/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
