<?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>Jon&#039;s Blog &#187; project</title>
	<atom:link href="http://bombdiggity.net/blog/tag/project/feed/" rel="self" type="application/rss+xml" />
	<link>http://bombdiggity.net/blog</link>
	<description>Ramblings of a php coder</description>
	<lastBuildDate>Fri, 14 May 2010 17:36:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Zend Studio for Eclipse &#8211; New Framework Project Problems</title>
		<link>http://bombdiggity.net/blog/2009/01/03/zend-studio-for-eclipse-new-framework-project-problems/</link>
		<comments>http://bombdiggity.net/blog/2009/01/03/zend-studio-for-eclipse-new-framework-project-problems/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 22:11:43 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://www.bombdiggity.net/blog/?p=64</guid>
		<description><![CDATA[While working on a new project where my base was Zend Framework I desided to give the default layout for new ZF projects in Zend Studio for Eclipse a chance. While it does start a good layout for a project by generating the default code which is a real time saver I did notice some [...]]]></description>
			<content:encoded><![CDATA[<p>While working on a new project where my base was Zend Framework I desided to give the default layout for new ZF projects in Zend Studio for Eclipse a chance. While it does start a good layout for a project by generating the default code which is a real time saver I did notice some problems.<br />
<span id="more-64"></span></p>
<ol>
<li>All of the class files have the closing php tag (?&gt;) on them followed by white space.</li>
<li>Lack of a modules directory in the default project</li>
<li>The Initializer Plug-in does not do some very basic things that should be done.</li>
</ol>
<h3>1. Closing php Tag</h3>
<p>According to the <a title="Zend Framework Wiki" href="http://framework.zend.com/wiki/display/ZFDEV/PHP+Coding+Standard+(draft)#PHPCodingStandard(draft)-PHPFileFormatting" target="_blank">PHP Coding Standard</a> that is on the Zend Framework Wiki:</p>
<p style="padding-left: 30px;">For files that contain only PHP code, the closing tag (&#8220;?&gt;&#8221;) is to be omitted. It is not required by PHP, and omitting it prevents trailing whitespace from being accidentally injected into the output.</p>
<h3>2. Lack of a modules direcory</h3>
<p>I know this is easy to add if you know what you are doing with ZF but someone who is new to the framework they might find it hard to understand how to add support for the modules directory. It&#8217;s part of the <a href="http://framework.zend.com/wiki/display/ZFPROP/Zend+Framework+Default+Project+Structure+-+Wil+Sinclair">proposed project structure</a> in the ZF wiki.</p>
<h3>3. Initializer Plug-in</h3>
<p>This is where I have the biggest problem with the default project that is generated.</p>
<ol>
<li>The basic layout of the file is fine except for all the init*() methods return void where they should return the class object so that you can chain requests together in the routeStartup() method.</li>
<li>It sets the controller directory last so if something throws an exception before before the controller path is set you end up seeing the exception about how ZF can not find the error controller instead of the actually exception thrown.</li>
</ol>
<p>Let me know in the comments if you have any suggestions or additions to this.</p>
<p>Here is my updated Initializer.php file</p>
<pre class="brush: php">&lt; ?php
&lt;?php
/**
 * My new Zend Framework project
 *
 * $LastChangedDate$
 * $LastChangedRevision$
 */

require_once &#039;Zend/Controller/Plugin/Abstract.php&#039;;
require_once &#039;Zend/Controller/Front.php&#039;;
require_once &#039;Zend/Controller/Request/Abstract.php&#039;;
require_once &#039;Zend/Controller/Action/HelperBroker.php&#039;;

/**
 *
 * Initializes configuration depndeing on the type of environment
 * (test, development, production, etc.)
 *
 * This can be used to configure environment variables, databases,
 * layouts, routers, helpers and more
 *
 */
class Initializer extends Zend_Controller_Plugin_Abstract
{
    /**
     * @var Zend_Config
     */
    protected static $_config;

    /**
     * @var string Current environment
     */
    protected $_env;

    /**
     * @var Zend_Controller_Front
     */
    protected $_front;

    /**
     * @var string Path to application root
     */
    protected $_root;

    /**
     * Constructor
     *
     * Initialize environment, root path, and configuration.
     *
     * @param  string $env
     * @param  string|null $root
     * @return void
     */
    public function __construct($env, $root = null)
    {
        $this-&gt;_setEnv($env);
        if (null === $root) {
            $root = realpath(dirname(__FILE__) . &#039;/../&#039;);
        }
        $this-&gt;_root = $root;

        $this-&gt;initPhpConfig();

        $this-&gt;_front = Zend_Controller_Front::getInstance();

        // set the test environment parameters
        if ($env == &#039;test&#039;) {
            // Enable all errors so we&#039;ll know when something goes wrong.
            error_reporting(E_ALL | E_STRICT);
            ini_set(&#039;display_startup_errors&#039;, 1);
            ini_set(&#039;display_errors&#039;, 1);

            $this-&gt;_front-&gt;throwExceptions(true);
        }
    }

    /**
     * Initialize environment
     *
     * @param  string $env
     * @return void
     */
    protected function _setEnv($env)
    {
        $this-&gt;_env = $env;
    }

    /**
     * Initialize Data bases
     *
     * @return Initializer
     */
    public function initPhpConfig()
    {

    }

    /**
     * Route startup
     *
     * @return Initializer
     */
    public function routeStartup(Zend_Controller_Request_Abstract $request)
    {
        $this-&gt;initControllers()
            -&gt;initHelpers()
            -&gt;initView()
            -&gt;initDb()
            -&gt;initPlugins()
            -&gt;initRoutes();

        return $this;
    }

    /**
     * Initialize data bases
     *
     * @return Initializer
     */
    public function initDb()
    {
        return $this;
    }

    /**
     * Initialize action helpers
     *
     * @return Initializer
     */
    public function initHelpers()
    {
        // register the default action helpers
        Zend_Controller_Action_HelperBroker::addPath( $this-&gt;_root . &#039;/application/default/helpers&#039;, &#039;Zend_Controller_Action_Helper&#039;);

        return $this;
    }

    /**
     * Initialize view
     *
     * @return Initializer
     */
    public function initView()
    {
        // Bootstrap layouts
        Zend_Layout::startMvc(array(
            &#039;layoutPath&#039; =&gt; $this-&gt;_root .  &#039;/application/default/layouts&#039;,
            &#039;layout&#039; =&gt; &#039;main&#039;
        ));

        return $this;

    }

    /**
     * Initialize plugins
     *
     * @return Initializer
     */
    public function initPlugins()
    {
        return $this;
    }

    /**
     * Initialize routes
     *
     * @return Initializer
     */
    public function initRoutes()
    {
        return $this;
    }

    /**
     * Initialize Controller and Modules paths
     *
     * @return Initializer
     */
    public function initControllers()
    {
        $this-&gt;_front-&gt;addControllerDirectory($this-&gt;_root . &#039;/application/default/controllers&#039;, &#039;default&#039;);
        $this-&gt;_front-&gt;addModuleDirectory($this-&gt;_root . &#039;/application/modules&#039;);

        return $this;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://bombdiggity.net/blog/2009/01/03/zend-studio-for-eclipse-new-framework-project-problems/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
