<?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>quick start &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/quick-start/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>Zend Framework &#8211; quick tutorial (part 3) &#8211; front controller plugins</title>
		<link>/2009/06/19/zend-framework-quick-tutorial-part-3-front-controller-plugins/</link>
		<comments>/2009/06/19/zend-framework-quick-tutorial-part-3-front-controller-plugins/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 13:01:02 +0000</pubDate>
		<dc:creator><![CDATA[stoimen]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[front_controller]]></category>
		<category><![CDATA[front_controller_plugin]]></category>
		<category><![CDATA[quick start]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">/?p=67</guid>
		<description><![CDATA[Why writing a front controller plugin? Almost every application uses a database connection and acl module. Why doing this in the bootstrap and to mantain many lines of code there, instead of making it clear and mantainable. Of course you can have all these lines of code in your bootstrap, but you know for serious &#8230; <a href="/2009/06/19/zend-framework-quick-tutorial-part-3-front-controller-plugins/" class="more-link">Continue reading <span class="screen-reader-text">Zend Framework &#8211; quick tutorial (part 3) &#8211; front controller plugins</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/07/06/zend-framework-simple-acl-front-controller-plugin/" rel="bookmark" title="Zend Framework: Simple Acl Front Controller Plugin">Zend Framework: Simple Acl Front Controller Plugin </a></li>
<li><a href="/2008/08/11/zend-framework-quick-tutorial-part-2-directory-layout-and-bootstrapping/" rel="bookmark" title="Zend Framework &#8211; quick tutorial (part 2)">Zend Framework &#8211; quick tutorial (part 2) </a></li>
<li><a href="/2008/08/05/zend-framework-quick-tutorial-part-1-introduction/" rel="bookmark" title="Zend Framework &#8211; quick tutorial (part 1)">Zend Framework &#8211; quick tutorial (part 1) </a></li>
<li><a href="/2009/10/27/zend-framework-custom-urls/" rel="bookmark" title="Zend Framework custom URLs">Zend Framework custom URLs </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Why writing a front controller plugin?</h2>
<p>Almost every application uses a database connection and acl module. Why doing this in the bootstrap and to mantain many lines of code there, instead of making it clear and mantainable. Of course you can have all these lines of code in your bootstrap, but you know for serious applications that recently will become an obstacle. That&#8217;s why Zend Framework allows you to use Front_Controller plugin.</p>
<h2>First in you bootstrap add those lines of code</h2>
<pre lang="php" escaped="true">
/*
 * add a simple plugin to the controller
 */

$front-&gt;registerPlugin(new Zend_Controller_Plugin_Init())
      -&gt;registerPlugin(new Zend_Controller_Plugin_Acl());
</pre>
<p>These two classes (Zend_Controller_Plugin_Init and Zend_Controller_Plugin_Acl) should be placed in two different files with the same names in Controller/Plugins directory under Zend folder, and garantee you that both classes will be instanciated before starting the front controller.<span id="more-67"></span></p>
<p>There is the example of Zend_Controller_Plugin_Init:</p>
<pre lang="php" escaped="true">&lt;?php

/** Zend_Acl */
require_once 'Zend/Acl.php';

/** Zend_Controller_Plugin_Abstract */
require_once 'Zend/Controller/Plugin/Abstract.php';

/**
 * Front Controller Plugin
 */
final class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{

/**
 * @var Zend_Acl
 **/
protected $_acl;

/**
 * @var string
 **/
protected $_roleName;

/**
 * @var array
 **/
protected $_errorPage;

/**
 * Constructor
 *
 * @param mixed $aclData
 * @param $roleName
 * @return void
 **/
public function __construct()
{

// define the error controller
$this-&gt;_errorPage = array('module' =&gt; 'default', 'controller' =&gt; 'error',
    'action' =&gt; 'denied');

$this-&gt;_roleName = 'defaultRole';
// if (null !== $this-&gt;_acl) {
$this-&gt;_initAcl();
// }

}

/**
 * Returns the ACL object
 *
 * @return Zend_Acl
 **/
public function getAcl()
{
    return $this-&gt;_acl;
}

/**
 * Sets the ACL role to use
 *
 * @param string $roleName
 * @return void
 **/
public function setRoleName($roleName)
{
    $this-&gt;_roleName = $roleName;
}

/**
 * Returns the ACL role used
 *
 * @return string
 * @author
 **/
public function getRoleName()
{
    return $this-&gt;_roleName;
}

/**
 * Sets the error page
 *
 * @param string $action
 * @param string $controller
 * @param string $module
 * @return void
 **/
public function setErrorPage($action, $controller = 'error', $module = null)
{
$this-&gt;_errorPage = array('module' =&gt; $module,
    'controller' =&gt; $controller,
    'action' =&gt; $action);
}

/**
 * Returns the error page
 *
 * @return array
 **/
public function getErrorPage()
{
    return $this-&gt;_errorPage;
}

/**
 * Predispatch
 * Checks if the current user identified by roleName has rights to the requested url (module/controller/action)
 * If not, it will call denyAccess to be redirected to errorPage
 *
 * @return void
 **/

public function preDispatch(Zend_Controller_Request_Abstract $request)
{
    $resourceName = '';
    if ($request-&gt;getModuleName() != 'default') {
    $resourceName .= $request-&gt;getModuleName() . ':';
}

$resourceName .= $request-&gt;getControllerName();

/** Check if the controller/action can be accessed by the current user */
if (!$this-&gt;getAcl()-&gt;isAllowed($this-&gt;_roleName, $resourceName, $request-&gt;getActionName())) {

/** Redirect to access denied page */
$this-&gt;denyAccess();

}

}

/**
 * Deny Access Function
 * Redirects to errorPage, this can be called from an action using the action helper
 *
 * @return void
 **/
public function denyAccess()
{
   $this-&gt;_request-&gt;setModuleName($this-&gt;_errorPage['module']);
   $this-&gt;_request-&gt;setControllerName($this-&gt;_errorPage['controller']);
   $this-&gt;_request-&gt;setActionName($this-&gt;_errorPage['action']);
}

/**
 * initialize the acl object and resources
 * for the roles used in the application
 *
 */
private function _initAcl()
{
   /*
    * define access control list
    */
   $this-&gt;_acl = new Zend_Acl();

   /**
    * define acl for default role
    */
   $this-&gt;_acl-&gt;addRole(new Zend_Acl_Role('defaultRole'))
        -&gt;add(new Zend_Acl_Resource('index'))
        -&gt;add(new Zend_Acl_Resource('portfolio'))
        -&gt;add(new Zend_Acl_Resource('user'))
        -&gt;allow('defaultRole');

   /**
    * define acl for administrator
    */
   $this-&gt;_acl-&gt;addRole(new Zend_Acl_Role('admin'))
        -&gt;add(new Zend_Acl_Resource('admin:index'))
        -&gt;add(new Zend_Acl_Resource('admin:cpanel'))
        -&gt;add(new Zend_Acl_Resource('admin:user'))
        -&gt;add(new Zend_Acl_Resource('admin:page'))
        -&gt;addRole(new Zend_Acl_Role('default'))
        -&gt;allow('admin');

   }

}

Init.php
&lt;?php

require_once 'Zend/Controller/Plugin/Abstract.php';
class Zend_Controller_Plugin_Init extends Zend_Controller_Plugin_Abstract
{
    public function __construct()
    {
        // require configuration
        require_once 'Zend/Config.php';

        // get configuration from ini file
        $config = new Zend_Config_Ini('../application/config.ini', 'dev');

        // connect to the database
        $db = new Zend_Db_Adapter_Pdo_Mysql($config-&gt;database-&gt;params);

        // assign the db adapter to be default for our models
        Zend_Db_Table::setDefaultAdapter($db);

        // register configuration at the registry
        Zend_Registry::set('config', $config);

        Zend_Registry::set('db', $db);

        // start layout mvc
        Zend_Layout::startMvc(array(
            'layoutPath' =&gt; '../application/layouts',
            'layout' =&gt; 'main'
        ));
    }

}</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/07/06/zend-framework-simple-acl-front-controller-plugin/" rel="bookmark" title="Zend Framework: Simple Acl Front Controller Plugin">Zend Framework: Simple Acl Front Controller Plugin </a></li>
<li><a href="/2008/08/11/zend-framework-quick-tutorial-part-2-directory-layout-and-bootstrapping/" rel="bookmark" title="Zend Framework &#8211; quick tutorial (part 2)">Zend Framework &#8211; quick tutorial (part 2) </a></li>
<li><a href="/2008/08/05/zend-framework-quick-tutorial-part-1-introduction/" rel="bookmark" title="Zend Framework &#8211; quick tutorial (part 1)">Zend Framework &#8211; quick tutorial (part 1) </a></li>
<li><a href="/2009/10/27/zend-framework-custom-urls/" rel="bookmark" title="Zend Framework custom URLs">Zend Framework custom URLs </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2009/06/19/zend-framework-quick-tutorial-part-3-front-controller-plugins/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to create a PHP Framework?</title>
		<link>/2008/09/17/how-to-create-a-php-framework/</link>
		<comments>/2008/09/17/how-to-create-a-php-framework/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 07:33:01 +0000</pubDate>
		<dc:creator><![CDATA[stoimen]]></dc:creator>
				<category><![CDATA[featured]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[quick start]]></category>

		<guid isPermaLink="false">/?p=119</guid>
		<description><![CDATA[A very good post on how a PHP framework can be build I found here. Everyone should be familiar with the basic principles described in the article, so don&#8217;t hesitate to read it carefully.<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2008/08/04/why-you-should-learn-a-framework/" rel="bookmark" title="Why should we learn a framework?">Why should we learn a framework? </a></li>
<li><a href="/2009/02/12/choosing-a-php-ide/" rel="bookmark" title="Choosing a PHP IDE">Choosing a PHP IDE </a></li>
<li><a href="/2008/08/11/zend-framework-quick-tutorial-part-2-directory-layout-and-bootstrapping/" rel="bookmark" title="Zend Framework &#8211; quick tutorial (part 2)">Zend Framework &#8211; quick tutorial (part 2) </a></li>
<li><a href="/2010/04/09/secure-forms-with-zend-framework/" rel="bookmark" title="Secure Forms with Zend Framework">Secure Forms with Zend Framework </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>A very good post on how a PHP framework can be build I found <a href="http://nettuts.com/php/creating-a-php5-framework-part-1/">here</a>. Everyone should be familiar with the basic principles described in the article, so don&#8217;t hesitate to read it carefully.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2008/08/04/why-you-should-learn-a-framework/" rel="bookmark" title="Why should we learn a framework?">Why should we learn a framework? </a></li>
<li><a href="/2009/02/12/choosing-a-php-ide/" rel="bookmark" title="Choosing a PHP IDE">Choosing a PHP IDE </a></li>
<li><a href="/2008/08/11/zend-framework-quick-tutorial-part-2-directory-layout-and-bootstrapping/" rel="bookmark" title="Zend Framework &#8211; quick tutorial (part 2)">Zend Framework &#8211; quick tutorial (part 2) </a></li>
<li><a href="/2010/04/09/secure-forms-with-zend-framework/" rel="bookmark" title="Secure Forms with Zend Framework">Secure Forms with Zend Framework </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2008/09/17/how-to-create-a-php-framework/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Zend Framework &#8211; quick tutorial (part 2)</title>
		<link>/2008/08/11/zend-framework-quick-tutorial-part-2-directory-layout-and-bootstrapping/</link>
		<comments>/2008/08/11/zend-framework-quick-tutorial-part-2-directory-layout-and-bootstrapping/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 10:25:38 +0000</pubDate>
		<dc:creator><![CDATA[stoimen]]></dc:creator>
				<category><![CDATA[featured]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[__autoload]]></category>
		<category><![CDATA[bootstrap.php]]></category>
		<category><![CDATA[directory layout]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[front controller]]></category>
		<category><![CDATA[quick start]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">/?p=55</guid>
		<description><![CDATA[Directory Layout and Bootstrapping. When someone starts with the learning of a framework, first he begins to read various articles to understand the basic rules to work with. There are a lot of tutorials how exactly to start, and there is also an official quick start guide, but beside this there are too much advices &#8230; <a href="/2008/08/11/zend-framework-quick-tutorial-part-2-directory-layout-and-bootstrapping/" class="more-link">Continue reading <span class="screen-reader-text">Zend Framework &#8211; quick tutorial (part 2)</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/06/19/zend-framework-quick-tutorial-part-3-front-controller-plugins/" rel="bookmark" title="Zend Framework &#8211; quick tutorial (part 3) &#8211; front controller plugins">Zend Framework &#8211; quick tutorial (part 3) &#8211; front controller plugins </a></li>
<li><a href="/2008/08/05/zend-framework-quick-tutorial-part-1-introduction/" rel="bookmark" title="Zend Framework &#8211; quick tutorial (part 1)">Zend Framework &#8211; quick tutorial (part 1) </a></li>
<li><a href="/2010/08/06/setting-up-zend-framework-with-modules/" rel="bookmark" title="Setting Up Zend Framework with Modules">Setting Up Zend Framework with Modules </a></li>
<li><a href="/2010/07/21/setting-up-global-cache-in-zend-framework/" rel="bookmark" title="Setting Up Global Cache in Zend Framework">Setting Up Global Cache in Zend Framework </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Directory Layout and Bootstrapping.<br />
<a title="part 1 - introduction" href="/2008/08/05/zend-framework-quick-tutorial-part-1-introduction/"></a></h2>
<p>When someone starts with the learning of a framework, first he begins to read various articles to understand the basic rules to work with.</p>
<p>There are a lot of tutorials how exactly to start, and there is also an official quick start guide, but beside this there are too much advices how should you directory layout look like.</p>
<p>For me the following directory layout is working well. I don&#8217;t remember exactly where I&#8217;ve found it, but I think many people use it.</p>
<ul>
<li>application
<ul>
<li>admin</li>
<li>controllers</li>
<li>models</li>
<li>views</li>
</ul>
</li>
<li>content
<ul>
<li>controllers</li>
<li>models</li>
<li>views</li>
</ul>
</li>
<li>layouts</li>
<li>bootstrap.php</li>
<li>config.ini</li>
<li>library</li>
<li>Zend</li>
<li>public</li>
<li>index.php</li>
</ul>
<p>Almost half of the sources &#8220;how to start&#8221; recommend all of the initialization should be in index.php in the public folder. In fact all the logic of the public/private folders is that we don&#8217;t like to show anything on the web, and that&#8217;s why index.php contains only the following peace of code (it&#8217;s recommended to leave the file open from the ?&gt; closing tag):<br />
<code>&lt;?php<br />
require '../application/bootstrap.php';</code></p>
<p>Anything else, all the initialization is in bootstrap.php:</p>
<p>error_reporting (E_ALL | E_STRICT);</p>
<p>ini_set (&#8216;display_startup_errors&#8217;, 1);<br />
ini_set (&#8216;display_errors&#8217;, 1);</p>
<p>set_include_path (&#8216;../library&#8217; . PATH_SEPARATOR . get_include_path());</p>
<p>require_once &#8220;Zend/Loader.php&#8221;;<br />
Zend_Loader::registerAutoload();</p>
<p>$front = Zend_Controller_Front::getInstance();</p>
<p>$front-&gt;throwExceptions(true);</p>
<p>$front-&gt;setControllerDirectory(array(&#8216;default&#8217; =&gt; &#8216;../application/content/controllers&#8217;,<br />
&#8216;admin&#8217;   =&gt; &#8216;../application/admin/controllers&#8217;));</p>
<p>$front-&gt;dispatch();<br />
We set the error reporting to be ON, which si good when you develop any application and to collect all error messages. Than add the <em>library </em>folder in the include path with that line of code:</p>
<blockquote><p>set_include_path(&#8216;../library&#8217; . PATH_SEPARATOR . get_include_path());</p></blockquote>
<p>Next step is to start the __autoload functionality built in Zend Framework:</p>
<blockquote><p>require_once &#8220;Zend/Loader.php&#8221;;<br />
Zend_Loader::registerAutoload();</p></blockquote>
<p>Finally start the front controller which implements the singleton pattern and point to the two main directories &#8211; admin and content. I used them for administration panel and front end, but you can used as many as you application needs:<br />
<code>$front-&gt;setControllerDirectory(array('default' =&gt; '../application/content/controllers',<br />
'admin'   =&gt; '../application/admin/controllers'));</code></p>
<h3><span style="color: #800000;"><span style="text-decoration: underline;">Related Links</span></span></h3>
<p><a title="Zend_Db tutorial" href="/2009/03/19/zend-framework-zend-db-tutorial/" target="_self"><strong>Zend_Db tutorial</strong></a></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/06/19/zend-framework-quick-tutorial-part-3-front-controller-plugins/" rel="bookmark" title="Zend Framework &#8211; quick tutorial (part 3) &#8211; front controller plugins">Zend Framework &#8211; quick tutorial (part 3) &#8211; front controller plugins </a></li>
<li><a href="/2008/08/05/zend-framework-quick-tutorial-part-1-introduction/" rel="bookmark" title="Zend Framework &#8211; quick tutorial (part 1)">Zend Framework &#8211; quick tutorial (part 1) </a></li>
<li><a href="/2010/08/06/setting-up-zend-framework-with-modules/" rel="bookmark" title="Setting Up Zend Framework with Modules">Setting Up Zend Framework with Modules </a></li>
<li><a href="/2010/07/21/setting-up-global-cache-in-zend-framework/" rel="bookmark" title="Setting Up Global Cache in Zend Framework">Setting Up Global Cache in Zend Framework </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2008/08/11/zend-framework-quick-tutorial-part-2-directory-layout-and-bootstrapping/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
