<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>zend_framework &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/zend_framework/</link>
	<description>Feed of posts on WordPress.com tagged "zend_framework"</description>
	<pubDate>Tue, 01 Dec 2009 16:22:13 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[The Simple Cloud API has landed!]]></title>
<link>http://wllm.com/2009/09/26/the-simple-cloud-api-has-landed/</link>
<pubDate>Sat, 26 Sep 2009 16:47:51 +0000</pubDate>
<dc:creator>wllm</dc:creator>
<guid>http://wllm.com/2009/09/26/the-simple-cloud-api-has-landed/</guid>
<description><![CDATA[OK, a lot of you guys have noticed that I&#8217;ve been uncharacteristically silent for the past mon]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>OK, a lot of you guys have noticed that I&#8217;ve been uncharacteristically silent for the past month or so. Now I can finally start talking about it- the Simple Cloud API has launched at <a href="http://www.simplecloud.org">http://www.simplecloud.org</a>.</p>
<p>This API gives PHP developers one interface to code to for what we call &#8216;cloud application services&#8217;. These are runtime application services like <a href="http://en.wikipedia.org/wiki/Nosql">nosql</a> databases, storage, and simple queues. These services make it easier to write &#8216;cloud native&#8217; applications that can take full advantage of the cloud&#8217;s promises of scalability and high-availability. I&#8217;ve found myself saying this a lot lately: &#8220;What&#8217;s the point of an infinitely scaling compute cloud when your applications can&#8217;t scale with it?&#8221;</p>
<p>We expect to be adding more of these services to the API as vendors roll them out. Possible services include email, session management, single sign on, etc. I can go on and on, but why don&#8217;t we let the vendors figure out what their customers need and vote with adoption? In any case, once such a service hits critical mass, the Simple Cloud API will have you covered.</p>
<p>The Simple Cloud API will be delivered as a new <a href="http://framework.zend.com">Zend Framework</a> component called Zend_Cloud. The code will be available *very* soon.</p>
<p>So, why didn&#8217;t we do elastic compute cloud services in this first version of the API? That deserves a blog post of its own. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>,Wil</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Developing a Doctrine-backed ACL helper TDD-style, part 2]]></title>
<link>http://monzee.wordpress.com/2009/06/20/developing-a-doctrine-backed-acl-helper-tdd-style-part-2/</link>
<pubDate>Sat, 20 Jun 2009 14:17:06 +0000</pubDate>
<dc:creator>monzee</dc:creator>
<guid>http://monzee.wordpress.com/2009/06/20/developing-a-doctrine-backed-acl-helper-tdd-style-part-2/</guid>
<description><![CDATA[In this second part, we will integrate Doctrine into our AccessManager helper. The database will be ]]></description>
<content:encoded><![CDATA[In this second part, we will integrate Doctrine into our AccessManager helper. The database will be ]]></content:encoded>
</item>
<item>
<title><![CDATA[Using Zend Framework from the Command Line]]></title>
<link>http://webfractor.wordpress.com/2008/08/14/using-zend-framework-from-the-command-line/</link>
<pubDate>Thu, 14 Aug 2008 19:29:32 +0000</pubDate>
<dc:creator>Jed</dc:creator>
<guid>http://webfractor.wordpress.com/2008/08/14/using-zend-framework-from-the-command-line/</guid>
<description><![CDATA[I&#8217;ve been using the Zend Framework since roughly Beta 0.8 and have been thoroughly impressed w]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I&#8217;ve been using the Zend Framework since roughly Beta 0.8 and have been thoroughly impressed with its evolution.  Besides web sites I also like using php from the command line for things like cron jobs, shell scripts and the like.  While it isn&#8217;t always the best suited language for such tasks, my familiarity with php often lets me get the job done faster than with another less familiar language.  A few days ago I sat down and figured out how to get full access to the Zend Framework, including MVC, from the command line.  Here&#8217;s how I did it&#8230;</p>
<p>This project is solely for cli use, it will contain a number of scripts running in the same &#8220;framework.&#8221;  There is no web interface for this at all.  I&#8217;m going to use a modified modular conventional file system to allow me to easily addon more scripts as I need them and still share the same infrastructure.   My file system looks like this:</p>
<pre>
.-- project root
&#124;-- application
&#124;   &#124;-- apis
&#124;   &#124;-- config
&#124;   &#124;-- layouts
&#124;   &#124;-- library
&#124;   &#124;   &#124;-- Webf
&#124;   &#124;   `-- Zend
&#124;   &#124;-- models
&#124;   &#124;-- modules
&#124;   &#124;   &#124;-- default
&#124;   &#124;   &#124;   &#124;-- config
&#124;   &#124;   &#124;   &#124;-- controllers
&#124;   &#124;   &#124;   &#124;-- models
&#124;   &#124;   &#124;   `-- views
&#124;   &#124;   &#124;       &#124;-- filters
&#124;   &#124;   &#124;       &#124;-- helpers
&#124;   &#124;   &#124;       &#124;-- layouts
&#124;   &#124;   &#124;       `-- scripts
&#124;   &#124;   `-- moduleX
&#124;   &#124;       &#124;-- config
&#124;   &#124;       &#124;-- controllers
&#124;   &#124;       &#124;-- models
&#124;   &#124;       `-- views
&#124;   &#124;           &#124;-- filters
&#124;   &#124;           &#124;-- helpers
&#124;   &#124;           &#124;-- layouts
&#124;   &#124;           `-- scripts
&#124;   &#124;-- tests
&#124;   `bootstrap.php
&#124;-- data
&#124;   &#124;-- cache
&#124;   &#124;-- indexes
&#124;   &#124;-- locales
&#124;   &#124;-- logs
&#124;   &#124;-- sessions
&#124;   `-- uploads
&#124;-- docs
&#124;-- tmp
'zfcli.php
</pre>
<p><em>* Not all of these directory are needed for this application.</em></p>
<p>Typically you would have a public (htdocs, www, etc..) folder for the web root, however since this isn&#8217;t a web project I&#8217;m using zfcli.php as my &#8220;bootstrap&#8221; file, which is located in the project root.  This file will glue Zend_Console_Getopt together with Zend_Controller_Request_Simple to get arguments from the command line into the request object. This will allow us to use ZF to its full potential from the command line.</p>
<p>Lets go ahead an create a simple IndexController and view so we have something to shoot for:</p>
<p><em><strong>./application/modules/default/controllers/IndexController.php</strong></em></p>
<pre class="brush: php;">
class IndexController extends Zend_Controller_Action
{
    public function indexAction() {}
}
</pre>
<p><strong><em>./application/modules/default/views/scripts/index/index.phtml</em></strong></p>
<pre class="brush: php;">
echo &quot;default:index:index\n\n&quot;;
</pre>
<p>I&#8217;ll assume you understand the above, if not please check google for some getting started with Zend Framework tutorials.</p>
<p>Ok, we&#8217;re ready to get going.  First up we need the bootstrap file:</p>
<p><strong><em>./zfcli.php</em></strong></p>
<pre class="brush: php;">
error_reporting(E_ALL&amp;#124;E_STRICT);
ini_set('display_errors',true);
$pthRoot = dirname(__FILE__);
set_include_path('.' . PATH_SEPARATOR . $pthRoot . '/application/library'
    . PATH_SEPARATOR . $pthRoot . '/application/models'
    . PATH_SEPARATOR . get_include_path());
date_default_timezone_set('America/Chicago');

require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();

try {
    $opts = new Zend_Console_Getopt(
        array(
            'help&amp;#124;h' =&amp;#62; 'Displays usage information.',
            'action&amp;#124;a=s' =&amp;#62; 'Action to perform in format of module.controller.action',
            'verbose&amp;#124;v' =&amp;#62; 'Verbose messages will be dumped to the default output.',
            'development&amp;#124;d' =&amp;#62; 'Enables development mode.',
        )
    );
    $opts-&amp;#62;parse();
} catch (Zend_Console_Getopt_Exception $e) {
    exit($e-&amp;#62;getMessage() .&quot;\n\n&quot;. $e-&amp;#62;getUsageMessage());
}

if(isset($opts-&amp;#62;h)) {
    echo $opts-&amp;#62;getUsageMessage();
    exit;
}

if(isset($opts-&amp;#62;a)) {
    $reqRoute = array_reverse(explode('.',$opts-&amp;#62;a));
    @list($action,$controller,$module) = $reqRoute;
    $request = new Zend_Controller_Request_Simple($action,$controller,$module);
    $front = Zend_Controller_Front::getInstance();

    $front-&amp;#62;setRequest($request);
    $front-&amp;#62;setRouter(new Webf_Controller_Router_Cli());

    $front-&amp;#62;setResponse(new Zend_Controller_Response_Cli());

    $front-&amp;#62;throwExceptions(true);
    $front-&amp;#62;addModuleDirectory($pthRoot . '/application/modules/');

    $front-&amp;#62;dispatch();
}
</pre>
<p>Here we have setup Zend_Console_Getopt with several possible parameters, -a being the one we will use to get the module.controller.action route for the MVC.  After setting up Getopt, we parse() the command line options.  Should an exception be encountered we want to catch it, display the error message and then show the usage message.  Using -h will also show us the usage message.</p>
<p>Then last if{} block is where we get the unification going.  By exploding on &#8220;.&#8221; we get an array of the module, controller and action, reversing the order makes it easier to deal with missing modules.  Break this new array out into individual variables then plug them into Zend_Controller_Request_Simple. if you don&#8217;t use the @ in front of the list() statement you will get warnings when there is no module supplied, since I want to use default in these cases I just make it not report these errors, the router will automatically look for the &#8220;default&#8221; module.</p>
<p>Next we instantiate the front controller and tell it to use the request we just built.  Next up we need a router that can be used in the CLI environment.  Notice I&#8217;ve made a custom router, more on that in a bit. We also need to use the Zend_Controller_Response_Cli response object, tell it where the modules are, tell it to throw exceptions.  Finally we dispatch the controller and our scripts are off and running.</p>
<p><em><strong>./application/library/Webf/Controller/Router/Cli.php</strong></em></p>
<pre class="brush: php;">
require_once ('Zend/Controller/Router/Interface.php');
require_once ('Zend/Controller/Router/Abstract.php');

class Webf_Controller_Router_Cli extends Zend_Controller_Router_Abstract implements Zend_Controller_Router_Interface {

    public function assemble($userParams, $name = null, $reset = false, $encode = true) { }

    public function route(Zend_Controller_Request_Abstract $dispatcher) {}
}
</pre>
<p>The router is really very simple, though it took me a bit to figure this out.  In order to ensure compatibility we need to extend the Router_Abstract and implement the Router_Interface.  If, like me, you use a Zend IDE, like Zend Studio for Eclipse, and make use of the class wizards you can end up with a short list of methods to implement.  In fact you only need two and they can be stubs.</p>
<p>That&#8217;s it, you&#8217;re in business.  Try running <strong><em>php zfcli.php -a index.index</em></strong> and see what happens.  You should see default:index:index just above your prompt <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Zend_Db_Table with Normalized Tables]]></title>
<link>http://joshteam.wordpress.com/2008/05/13/zend_db_table-with-normalized-tables/</link>
<pubDate>Tue, 13 May 2008 15:18:13 +0000</pubDate>
<dc:creator>joshteam</dc:creator>
<guid>http://joshteam.wordpress.com/2008/05/13/zend_db_table-with-normalized-tables/</guid>
<description><![CDATA[So in my latest project I&#8217;ve been using Zend_Db_Table which is really nice for interfacing wit]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>So in my latest project I&#8217;ve been using Zend_Db_Table which is really nice for interfacing with a table, however it lends itself for a simple table structure which maps perfectly with your php/application model. I, however, do not have that luxury as I usually normalize my table structure. So one night, around 2am, I wrote an abstract class to allow me with minimum code do the following:</p>
<pre>$table1-&#62;joinedTable-&#62;joinedTableField</pre>
<p>Now, I am sure the code I wrote to do this is coupled, inefficient, etc. So as always, feel free to openly torment it <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>First Things First<br />
</strong>Let me lay out my file structure that I use. The file structure is not dependent on the class I wrote, but I use autoload so it will make sense why I name what I name what:</p>
<p>+ app<br />
&#160;&#160;+ Models<br />
&#160;&#160;&#160;&#160;+ DB<br />
<strong> &#8211; AbstractModel.php (<em>this is my class</em>)</strong></p>
<p>So I basically added another layer to the Model. In /app/Models/DB I put all my simple Zend_Db_Table classes that represent a table in my database. Then I put all my PHP Model Objects in the /app/Models directory. Before I get to far ahead of myself, it&#8217;s always best for me to learn by a live working example so without further adue:</p>
<p><strong>The Example<br />
</strong></p>
<p>I have about 16 tables so far in this project ( mid build ) but let&#8217;s take a table that joins a lot of other tables. That table is called <strong>establishments</strong>. Here is the DDL for the table establishments:</p>
<pre>CREATE TABLE `establishments` (
`id` bigint(20) unsigned zerofill NOT NULL auto_increment,
`name` varchar(255) default NULL,
`categoryID` mediumint(8) unsigned default NULL,
`longitude` double default NULL,
`lattitude` double default NULL,
`address` varchar(255) default NULL,
`cityID` tinyint(3) unsigned default NULL,
`stateID` int(10) unsigned default NULL,
`zip` varchar(6) default NULL,
`website` varchar(255) default NULL,
`mainPicID` int(10) unsigned default NULL,
`description` text,
`dressID` int(11) default NULL,
`vallet` tinyint(1) default NULL,
`isActive` tinyint(1) unsigned NOT NULL,
PRIMARY KEY  (`id`),
UNIQUE KEY `name` USING BTREE (`name`,`categoryID`),
UNIQUE KEY `address` (`longitude`,`lattitude`)
) ENGINE=MyISAM AUTO_INCREMENT=24 DEFAULT CHARSET=utf8</pre>
<p>The columns to note are:</p>
<ul>
<li>categoryID: categories Table ( id, name, isActive )</li>
<li>cityID: cities Table ( id, name, lattitude, longitude, isActive )</li>
<li>stateID: states Table ( id, name, longitude, lattitude, isActive )</li>
<li>mainPicID: photos Table ( id, categoryID, entityID, userID, location, description, timestamp, isActive )</li>
<li>dressID: dress Table ( id, name, description, isActive</li>
</ul>
<p><strong>The Objective</strong><br />
The goal is to be able to do the following very easily:</p>
<pre>
$establishment-&#62;name //returns establishments.name
$establishment-&#62;category-&#62;name //returns categories.name mapped to categoryID
$establishment-&#62;city-&#62;name //returns cities.name mapped to cityID
$establishment-&#62;state-&#62;name //returns states.name mapped to sateID
$establishment-&#62;photo-&#62;location // returns photos.location mapped to mainPicID
$establishment-&#62;dress-&#62;name // returns dress.name mapped to dressID
</pre>
<p>As you can see this gives us two things, easily mapping our normalized table out &#38; being able to keep naming in our application layer different then the naming in our database (e.g. as a property that represents a table is usually singular tense and the table is plural). Well, let&#8217;s as always, work backwards. We need to load $establishments:</p>
<pre>
//I actually do not do this, I use a factory! But here you go anyways
$establishments = new Models_Establishment();

//Grab the Active Record Where the Name Matches the var $estabNam
$establishment = $establishments-&#62;find('name', $estabName);
</pre>
<p><strong>The Establishments Class</strong><br />
Now we need to actually have our Models_Establishment class. Simply save the following in /app/Models/:</p>
<pre>
class Models_Establishment extends Models_AbstractModel {
  protected $_map = array(
    'self'=&#62;'Models_DB_Establishment',
    'category'=&#62;array('col'=&#62;'categoryID', 'class'=&#62;'Models_DB_Category'),
    'city'=&#62;array('col'=&#62;'cityID', 'class'=&#62;'Models_DB_City'),
    'state'=&#62;array('col'=&#62;'stateID', 'class'=&#62;'Models_DB_State'),
    'photo'=&#62;array('col'=&#62;'mainPicID', 'class'=&#62;'Models_DB_Photo'),
    'dress'=&#62;array('col'=&#62;'dressID', 'class'=&#62;'Models_DB_Dress')
  );
}
</pre>
<p>If you notice the first thing this class does is extend the abstract model class which I haven&#8217;t gotten into yet. The only other thing in this class is the $_map array which simply maps your object. The &#8217;self&#8217; index maps the current object to it&#8217;s base/core Zend_Db_Table file as you see here &#8216;Models_DB_Establishment&#8217; which exist in /app/Models/Db/Establishment.php and it looks like:</p>
<pre>
class Models_DB_Establishment extends Zend_Db_Table_Abstract{
  public $_name = 'spottedhere.establishments';
  protected $_primary = 'id';
}
</pre>
<p>Nothing fancy there. Then the other indexes are category, city, state, photo, and dress. These all map what the ID is in the current object (categoryID, cityID, etc.) and which DB file to use. All these DB files exist in /app/Models/DB and here is what /app/Models/DB/Category.php looks like:</p>
<pre>
class Models_DB_Category extends Zend_Db_Table_Abstract{
  public $_name = 'spottedhere.categories';
  protected $_primary = 'id';
}
</pre>
<p>As you see they are all very similar. So for the most part all you have to do is have a /app/Models/DB/ table for each table you have and each one just specifying the name of the table and the primary key. Now all you need is the abstract class which exist in /app/Modles/AbstractModel.php and it looks like:</p>
<pre>
abstract class Models_AbstractModel {

  protected $id;
  protected $data;
  protected $selfObject;
  protected $_complexFields;
  protected $_map;
  static protected $pk = 'ID';

  public function __construct() {
    $this-&#62;selfObject= new $this-&#62;_map['self']();
  }

  public function __get($what) {
    if(is_array($this-&#62;_map)) {
      if(array_key_exists($what, $this-&#62;_map)) {
        try {
          return $this-&#62;data-&#62;$what;
        } catch (Exception $e) {
          return false;
        }
      }
    }
    if(is_array($this-&#62;_complexFields)) {
      if(array_key_exists($what, $this-&#62;_complexFields)) {
        $o;
        foreach($this-&#62;_complexFields[$what]['fields'] as $field) {
          $o .= $this-&#62;data-&#62;self-&#62;$field.$this-&#62;_complexFields[$what]['seperator'];
        }
        return $o;
      }
    }
    try {
      return $this-&#62;data-&#62;self-&#62;$what;
    } catch (Exception $e) {
      return false;
    }
  }

  protected function build() {
    if(is_numeric($this-&#62;id)) {
      $this-&#62;data-&#62;self = $this-&#62;selfObject-&#62;find($this-&#62;id)-&#62;current();
      if(is_array($this-&#62;_map)) {
        foreach($this-&#62;_map as $field=&#62;$properties) {
          if(is_array($properties)) {
            $s = $properties['class'];
            $i = new $s();
            if($properties['col']) {
              //dependent table
              $this-&#62;data-&#62;$field = $i-&#62;find($this-&#62;data-&#62;self-&#62;{$properties['col']})-&#62;current();
            } else {
              //not dependent table
              $this-&#62;data-&#62;$field = Models_Loader::get('UserAccount')-&#62;find($properties['fk'], $this-&#62;id);
            }
          }
        }
      }
    }
  }

  public function find($field, $value) {
    $record = new $this-&#62;_map['self']();
    $table = $record-&#62;_name;
    $dbObj = Zend_Registry::get('db');
    if(!is_array($value)) {
      $sql = 'SELECT '. self::$pk .' FROM '. $table ." WHERE {$field} = \"{$value}\" LIMIT 1";
      $id = $dbObj-&#62;fetchOne($sql);
      if(is_numeric($id)) {
        $this-&#62;id = $id;
        $this-&#62;build();
        return $this;
      } else {
        return false;
      }
    } else {
      $sql = 'SELECT '. self::$pk .' FROM '. $table ." WHERE {$field} IN (". implode(',',$value) .')';
      return $dbObj-&#62;fetchAll($sql);
    }
  }

  public function insert($data) {
    return $this-&#62;selfObject-&#62;insert($data);
  }

  public function toArray() {
    $d = array();
    foreach($this-&#62;data as $i=&#62;$v) {
      if(get_class($v) == 'Zend_Db_Table_Row') {
        $d[$i] = $v-&#62;toArray();
      }
    }
    return $d;
  }

}
</pre>
<p>Anyways, this was my quick solution. As always, looking forward to your feedback!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[User Login with Zend Framework]]></title>
<link>http://joshteam.wordpress.com/2008/05/10/user-login-with-zend-framework/</link>
<pubDate>Sat, 10 May 2008 16:43:49 +0000</pubDate>
<dc:creator>joshteam</dc:creator>
<guid>http://joshteam.wordpress.com/2008/05/10/user-login-with-zend-framework/</guid>
<description><![CDATA[So my last post I showed a simple little form I had created for letting people create records. Let]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>So my last post I showed a simple little form I had created for letting people create records. Let&#8217;s talk about something a little more useful this time. It is very common to want to include a login form, or if they have logged in, some user control bar on every page in your site/application. Let me emphasize, I am by no stretch of the imagination the holy grail of how to do stuff, and would be safe to say that since I am suggesting this approach it is, not the best way. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  However, it has served me well in the few applications I have made with Zend Framework, thus I will share.</p>
<p>** Update **</p>
<p><strong>File Structure<br />
</strong>Below is how I structured my files:<br />
+ Project</p>
<p>+ app<br />
&#160;&#160;+ forms<br />
&#160;&#160;+ layouts<br />
&#160;&#160;&#160;&#160;+ helpers <em>(If you put your view helpers here, register this dir as a view helper dir)</em><br />
&#160;&#160;&#160;&#160;+ scripts<br />
&#160;&#160;+ lib<br />
&#160;&#160;+ models<br />
&#160;&#160;+ modules<br />
&#160;&#160;&#160;&#160;+ default<br />
&#160;&#160;&#160;&#160;&#160;&#160;+ controllers<br />
&#160;&#160;&#160;&#160;&#160;&#160;+ views<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;+ scripts<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;+ helpers <em>(default location Zend FW looks for View Helpers when default &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;module invoked)</em><br />
+ config<br />
+ misc<br />
+ www</p>
<p><strong>Invoking Code</strong><br />
Since, we will be putting this on every page it makes sense to put the invoking code in Zend_Layout. If, you aren&#8217;t using Zend_Layout.. I highly suggest you start migrating it into your code. Zend Layout basically allows you to have a &#8220;layout&#8221; for different pages, which renderes &#8220;templates&#8221; that correspond to the actions. <em>(That&#8217;s a nutshell version) </em>So in my layout I simply put:</p>
<pre>echo $this-&#62;userControlBar();</pre>
<p>This will invoke Zend_View to look for the view helper: UserControlBar. Now it&#8217;s good to know a couple of things here, each page request will only have one Zend_View object. So, Zend_Layout, doesn&#8217;t have it&#8217;s own view object, rather the Zend_View is injected into the Zend_Layout. This means, that the view helper User Control Bar, has to be registered with the view for that action. I may be over-complicating the issue, just be sure that you could call $this-&#62;userControlBar() in the template scripts corresponding to all the actions. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>The View Helper<br />
</strong>Now, we need the View Helper. In the helper, we will call default View Helpers that come with Zend_View but in order to do that we have to register the View object with the View Helper. To do that we simply add the following method to our View Helper:</p>
<pre>    public function setView($view) {
        $this-&#62;_view = $view;
    }
</pre>
<p>Then the next method we make is the actual View Helper:</p>
<pre>    public function userControlBar() { echo 'hi'; }
</pre>
<p>This should return &#8216;hi&#8217; in the Layout. Now we simply, need to make it work. We want to first determine if the user has been authenticated which can be done with:</p>
<pre>    Zend_Auth::getInstance()-&#62;hasIdentity()</pre>
<p>This, as expected, will return true or false. So let&#8217;s put it in a little if statement:</p>
<pre>    if(Zend_Auth::getInstance()-&#62;hasIdentity()) {
      //user is logged in
    } else {
      //user is not logged in
    }
</pre>
<p>Now let&#8217;s just say we want 3 controls, and we want the html to be:</p>
<ul>
<li><a href="/controller/action1">Control One</a></li>
<li><a href="/controller/action2">Control Two</a></li>
<li><a href="/controller/action3/param/value">Control Three</a></li>
</ul>
<p>We can do this very easily with two default View Helpers: (htmlList, and url). First thing we need to do is build an array of the links we want to show. You -could- abstract this out another level it warranted it, but we have a simple app, so we can just hard code this array <em>(note how we are utilizing the registered view)</em>:</p>
<pre>   $links = array();
   $links[] = '&#60;a href="' . <a>$this-&#62;_view-&#62;url</a><a></a><a>(array('controller'=&#62;'action1'),
 '', true) . "&#62;Control One</a>';
   $links[] = '&#60;a href="' . <a>$this-&#62;_view-&#62;url(array('controller'=&#62;'action2'),
'', true) . "&#62;Control Two</a>';
   $links[] = '&#60;a href="' . <a>$this-&#62;_view-&#62;url(array('controller'=&#62;'action3',
'param'=&#62;'value'), '', true) . "&#62;Control Three</a>';
</pre>
<p>Then we can register the $links array with the View Helper htmlList:</p>
<pre>   //Should change name most likely <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
   $linkList = $this-&#62;_view-&#62;htmlList($links, false, array('id'=&#62;'userControl') , false);
</pre>
<p>The above code will generate the HTML we need. So our ViewHelper now looks like:</p>
<pre>   if(Zend_Auth::getInstance()-&#62;hasIdentity()) {
      //user is logged in
      $links = array();
      $links[] = '&#60;a href="' . <a>$this-&#62;_view-&#62;url</a><a>(array('controller'=&#62;'action1'), '', true)
 . "&#62;Control One</a>';
      $links[] = '&#60;a href="' . <a>$this-&#62;_view-&#62;url(array('controller'=&#62;'action2'), '', true)
 . "&#62;Control Two</a>';
      $links[] = '&#60;a href="' . <a>$this-&#62;_view-&#62;url(array('controller'=&#62;'action3',
'param'=&#62;'value'), '', true) . "&#62;Control Three</a>';
      //Should change name most likely <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
      $linkList = $this-&#62;_view-&#62;htmlList($links, false, array('id'=&#62;'userControl') , false);
      return $linkList;
   } else {
      //user is not logged in
   }
</pre>
<p>Now that&#8217;s all good and dandy, but what if they aren&#8217;t logged in? Well, we have two options here, we can just write the Form ourself or use Zend_Form. I personally love Zend_Form. However for sake or this tutorial we will just generate the html ourself. You can simply put the html of the form in a variable and return it for now, that way if you want to do it the right way later, and use Zend_Form, it&#8217;s really easy <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre>      ...
   } else {
       $form = '... html for login form here ...';
      return $form;
   }
</pre>
<p>That&#8217;s it. Now in all of our pages we will either have a login form or a control bar. We&#8217;ve used the View Helpers, Zend_Layout, *hopefully Zend_Form*, wrote our own Helper, and the gorgeous part is we haven&#8217;t touched the &#8220;Application&#8221; code inside the Modules/Defaults/Controllers. We simply listen to Zend_Auth and return whatever.</p>
<p>Hope this helps, and I&#8217;d love to see how I could improve my technique.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Naming Recommendation for Controllers, Actions, and URLs using zend_controller]]></title>
<link>http://develop2travel.wordpress.com/2008/03/28/naming-recommendation-for-controllers-actions-urls-using-zend_controller/</link>
<pubDate>Fri, 28 Mar 2008 21:26:01 +0000</pubDate>
<dc:creator>beachwebsurf</dc:creator>
<guid>http://develop2travel.wordpress.com/2008/03/28/naming-recommendation-for-controllers-actions-urls-using-zend_controller/</guid>
<description><![CDATA[ Given the zend_controller naming changes in zend framework 1.5 for controllers and actions and the ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p> Given the zend_controller naming changes in zend framework 1.5 for controllers and actions and the corresponding url, I&#8217;m trying to figure out a recommended naming scheme that I can use for zf 1.5 and onwards.  This forum post helped a lot: <a href="http://www.nabble.com/AW%3A-Normalizing-action-function-names-p16110540.html">http://www.nabble.com/AW%3A-Normalizing-action-function-names-p16110540.html</a> but it does not mention multi-word controllers and file and directory names.  Here&#8217;s what I could figure out.   Comments?</p>
<ul type="disc">
<li>URL:
<ul type="circle">
<li>domain.com/controller-name/action-name
<ul type="square">
<li>note the use of dash (-) in the url.</li>
</ul>
</li>
</ul>
</li>
<li>Controller File:
<ul type="circle">
<li>Controller File name / Class name:
<ul type="square">
<li>Filename and class name are the same.</li>
<li><u>MixedCase </u></li>
<li>eg: file RoadMapController.php contains class RoadMapController for url domain.com/road-map <u></u></li>
<li>Zf 1.5 docs explicitly recommends caps for first character (not sure what &#8220;Title-cases&#8221; refers to in the zf docs).  Implicitly, it seems to suggest MixedCase if I want dashes in the url.</li>
<li>Need separators:
<ul type="disc">
<li>No Underscore ( _ ) since it will break mvc mapping so can&#8217;t use (might imply a sub-directory)</li>
<li>Dash ( &#8211; ) is not allowed in class name since it&#8217;s a minus sign.</li>
<li>Need casing to make it readable since I can&#8217;t use separators</li>
</ul>
</li>
</ul>
</li>
<li>View Action method name inside controller code
<ul type="square">
<li><u>Use camelCase</u> <u></u></li>
<li>Eg: componentsForHighLevelAction for domain.com/road-map/components-for-high-level</li>
<li>Mixed case does not work.  View action method must be camelCase.  This was a changed in ZF 1.5. </li>
<li>No Underscore ( _ ) since it will break mvc mapping so can&#8217;t use.</li>
</ul>
</li>
</ul>
</li>
<li>View File and directory:
<ul type="circle">
<li>Controller directory name that holds the view script files:
<ul type="square">
<li><u>All lower case</u> with dashes between words. </li>
<li>Matches controller part of url</li>
</ul>
</li>
<li>View file name:
<ul type="square">
<li><u>All lower case</u> with dashes between words. </li>
<li>Matches view part of url</li>
<li>URL Underscore ( _ ) gets mapped to filename dash ( &#8211; )</li>
</ul>
</li>
<li>Eg: my_file_system/road-map/components-for-high-level.phtml</li>
</ul>
</li>
<li>Resources and notes:
<ul type="circle">
<li>This naming scheme is pretty complicated.  It sure would be nice to have a complete example explicitly documented in the zend_controller reference guide.  I&#8217;m really looking for the zend framework recommendation on setting this up such that it covers the common cases, enables readable (word separated) URLs, and will be stable for future releases.  Well, this is my attempt at documenting it.</li>
<li>Good reference for zf 1.5: <a href="http://www.nabble.com/AW%3A-Normalizing-action-function-names-p16110540.html">http://www.nabble.com/AW%3A-Normalizing-action-function-names-p16110540.html</a>
<ul type="square">
<li>What was the thread in the mailing list before?  Is it: <a href="http://www.nabble.com/correct-controller-php-file-name-td14424663.html#a14425880">http://www.nabble.com/correct-controller-php-file-name-td14424663.html#a14425880</a></li>
<li>Or could be <a href="http://www.nabble.com/Need-help-using-dashes-in-action-names-td13348011.html#a13349348">http://www.nabble.com/Need-help-using-dashes-in-action-names-td13348011.html#a13349348</a></li>
<li>This is interesting in the context of naming: underscore is new directory: <a href="http://www.nabble.com/underscore-in-URL-td15406669.html#a15411590">http://www.nabble.com/underscore-in-URL-td15406669.html#a15411590</a></li>
</ul>
</li>
<li>From zf 1.5 manual:
<ul type="square">
<li>Zend_Controller&#8217;s dispatcher then takes the controller value and maps it to a class. By default, it Title-cases the controller name and appends the word Controller. Thus, in our example above, the controller roadmap is mapped to the class RoadmapController.</li>
<li>Similarly, the action value is mapped to a method of the controller class. By default, the value is lower-cased, and the word Action is appended. Thus, in our example above, the action components becomes componentsAction, and the final method called is RoadmapController::componentsAction().</li>
<li>From intro <a href="http://framework.zend.com/manual/en/zend.controller.html">http://framework.zend.com/manual/en/zend.controller.html</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<p>see this ZF forum post for updated information: <a href="http://www.nabble.com/Naming-Recommendation-for-Controllers%2C-Actions%2C-and-URLs-using-zend_controller-td16362913.html">http://www.nabble.com/Naming-Recommendation-for-Controllers%2C-Actions%2C-and-URLs-using-zend_controller-td16362913.html</a></p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
