<?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>SwiftLizard Interactive {Design, Development} &#187; zend</title>
	<atom:link href="http://www.swift-lizard.com/tag/zend/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.swift-lizard.com</link>
	<description>all about a it - freelancers life</description>
	<lastBuildDate>Thu, 18 Mar 2010 09:10:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using the advantages of Zendframework with Typo3</title>
		<link>http://www.swift-lizard.com/2009/11/18/using-the-advantages-of-zendframework-with-typo3/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.swift-lizard.com/2009/11/18/using-the-advantages-of-zendframework-with-typo3/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 02:35:22 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[typo3]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[zendFramework]]></category>

		<guid isPermaLink="false">http://www.swift-lizard.com/?p=114</guid>
		<description><![CDATA[Today I want to provide two new extensions to you, as well as a little tutorial how to develop Typo3 Extension more MVC like and with a lot less work than you would have usually. But first I&#8217;d like to share two nice extensions witch will be the base to this article:

T3X_sl_zendframework-1_9_5-z-200911181108
T3X_slmvchelper-1_0_0-z-200911180116

In one of my [...]]]></description>
			<content:encoded><![CDATA[<p>Today I want to provide two new extensions to you, as well as a little tutorial how to develop Typo3 Extension more MVC like and with a lot less work than you would have usually.<span id="more-114"></span> But first I&#8217;d like to share two nice extensions witch will be the base to this article:</p>
<ol>
<li><a href="http://www.swift-lizard.com/wp-content/uploads/2009/11/T3X_sl_zendframework-1_9_5-z-200911181108.t3x#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">T3X_sl_zendframework-1_9_5-z-200911181108</a></li>
<li><a href="http://www.swift-lizard.com/wp-content/uploads/2009/11/T3X_slmvchelper-1_0_0-z-200911180116.t3x#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">T3X_slmvchelper-1_0_0-z-200911180116</a></li>
</ol>
<p>In one of my previous posts I showed you how to implement the Zend_AutoLoader in your normal PHP project to save your self some time and to make you stop carrying about if a class is loaded all ready or has to be required. Wouldn´t it be nice if one has Autoloading inside Typo3 too ? Well this can be done quite easy. First of all you will have to install the sl_zendframework Extension into your typo3.</p>
<p>This will provide two things to you.</p>
<p>First of all you will be able to use all the nice things the Zendframework delivers at the version 1.9.5 (except zend_locale, zend_gData, and zend_codegenerator those where removed because of size issues). The second advantage you will get is worth even more, you will have lazy loading via autoload.</p>
<p>By default this extension provides the autoloading for all Zend related classes you might need in your extension. The only requirement is that it is installed and loaded before your own extension. You are able to check that in the localconf.php by the order of $TYPO3_CONF_VARS['EXT']['extList']. The sl_zendframework extension has to stand at a position in that list that is before the position of your plugin.</p>
<p>The sl_zendframework will also provide you with the variable $autoloader inside the ext_localconf.php file of your extension witch is a singleton instance of Zend_Loader_Autoloader. This will be the base to get your extension to autoload what is inside,&#8230; or even if other extensions use this too, what is inside them too.</p>
<p>The way to achieve this is quite simple:</p>
<pre name="code" class="php">/**
 * this is the path to typo3conf/ext,
 * or if the extension is installed global typo3/ext
 */
$s_include_path = str_replace('yourExtensionKey/',
                    '',
                    t3lib_extMgm::extPath('yourExtensionKey'));

/**
 * now we add the path to the extensions
 * parent folder to the includepath list
 */
set_include_path(get_include_path() .
                          PATH_SEPARATOR .
                          $s_include_path);

/**
 * now we register the name of the extension as
 * a namespace for the autoloader
 */
$autoloader-&gt;registerNamespace ( 'yourExtensionKey' );</pre>
<p>After you added those lines to your ext_localconf.php you can almost forget about include and require statements, as long as the class you want to<br />
instanciate is inside your extension folder and prefixed with name of your extension, witch you just registered as a namespace to the autoloader.</p>
<p>Let me show you some examples:</p>
<pre name="code" class="php"> // file inside  a folder with the name "yourExtensionKey"
 // carrying the name yourClassName.php
 $instance_1 = new yourExtensionKey_yourClassName();

 // file inside  a folder with the name "subFolderName"
 // inside the folder "yourExtensionKey"
 // carrying the name yourClassName.php
 $instance_2 = new yourExtensionKey_subFolderName_yourClassName();</pre>
<p>No more require_once needed because the zend_autoloader will do the job for you. Now that I have showed you how to get the autoloader up and running for your extension, let me introduce you to the second extension &#8220;slmvchelper&#8221;. This extension can be called the result of working with typo3 for several years now (in 2010 it be my 7th anniversary of working with typo3). As I mentioned before I am a little bit lazy when it come to writing code, so I try to save myself as many lines as possible, and try to keep it as simple as possible if someone else or even me myself has to edit a extension I have done. This is way I came up with the idea of the two classes this extension contains (as well as a example pi1) by the start of 2009.</p>
<p>The first one helps you with the template parsing and all the methods one has to use during the development of a extension to get his template parsed and displayed. It is called &#8220;slmvchelper_view_templateParser&#8221;, and yes if you install the extension on your system it will register it self to the autoloader so that you can use it by this simple line of php:</p>
<pre name="code" class="php">  $this-&gt;view = new slmvchelper_view_templateParser($this);</pre>
<p>After that you will have an instance of the Templateparser witch provides you with some simple methods to make your live easier while developing extensions.<br />
But step by step.</p>
<p>Next thing you will have to do is this:</p>
<pre name="code" class="php">  $this-&gt;view-&gt;setTemplate($this-&gt;conf['template.']['path']);
  $this-&gt;view-&gt;setSubPart($this-&gt;conf['template.']['mainSubPart']);</pre>
<p>The &#8220;setTemplate&#8221; method excepts a string witch leads it to the template file you want to use. In this case this would be provided in plugin.tx_slmvchelper_pi1.template.path and is something like &#8220;EXT:slmvchelper/static/html/template.html&#8221;. After the call the template<br />
will be loaded. Next thing to do is to set the main Subpart of the template you want to work with. Same here, it is provided in plugin.tx_slmvchelper_pi1.template.mainSubPart and is something like &#8216;TEMPLATE_MAIN&#8217;. The setSubPart method exepts two parameters, the first one is mandatory because it is the subpart you want to declare, the second one is optional because it is the parent subpart of the subpart to declare. So if you want to work on a subpart within another one you would do something like this:</p>
<pre name="code" class="php">  $this-&gt;view-&gt;setSubPart('SUBPART_TEST', $this-&gt;conf['template.']['mainSubPart']);</pre>
<p>Witch would mean you are declaring the subpart named &#8220;SUBPART_TEST&#8221; inside &#8220;TEMPLATE_MAIN&#8221;. After you have done this you might want to set some markers and parse the whole stuff and return it. This is also quite easy:</p>
<pre name="code" class="php">  $marker = array(
		'NORMAL_MARKER' =&gt; 'Hallo Welt'
  );

  $subparts = array(
		'SUBPART_TEST' =&gt; $this-&gt;view-&gt;parse($marker, array(),
                                                'SUBPART_TEST')
  );
  $content = $this-&gt;view-&gt;parse($marker, $subparts,
                                           $this-&gt;conf['template.']['mainSubPart']);</pre>
<p>By now you might have recognized that those three &#8220;#&#8221; are missing at the marker name as well as at the subparts name, this is they are no longer required inside your php code, they will be set automatically by the template parser inside the method parse(). I think the first and the second Parameter should be quite obvious, and the third should be no that hard to guess. Right, the third param of the parse method is the name of the subpart you want to use for parsing the values. So for the subpart  &#8216;SUBPART_TEST&#8217; this would be &#8216;SUBPART_TEST&#8217; and for the template it self this would be $this-&gt;conf['template.']['mainSubPart'] or TEMPLATE_MAIN. This is it, to my mind the easiest way to get your template parsed and displayed.</p>
<p>But wait there is more:<br />
The templateparser also provides you with some markers that are there by default. You can access everyting inside your locallang file by simply adding the marker ###LL_yourLocalLangKey### to the template, it will be parsed automatically and add the value of &#8220;yourLocalLangKey&#8221; to your template, and you do have also every public member variable of $this-&gt;cObj-&gt;data available by simply adding ###COBJDATA_nameOfTheMember###. So for instance ###COBJDATA_uid### will display the uid of the tt_content element witch is stored inside $this-&gt;cObj-&gt;data-&gt;uid.</p>
<p>The second class of  the &#8220;slmvchelper&#8221; extension is called &#8220;slmvchelper_model_base&#8221;, witch will provide to you a light version of extBase witch comes with typo3 4.3 this winter.  The &#8220;slmvchelper_model_base&#8221; class gives you the opportunity to simply read and write data to your database. All that is required is for you to set up a model witch has all the fields of your database table as member variables as well as you have to set the table name to work with inside the constructor of the model.</p>
<p>Your model should be looking something like this:</p>
<pre name="code" class="php">  class yourExtensionKey_model_databaseTableName extends
  slmvchelper_model_base{
	protected $uid;
	protected $pid;
	protected $text;

	public function __construct()
	{
		$this-&gt;setTable('tx_yourExtensionKey');
	}

	public function setUid($uid)
	{
		$this-&gt;uid = $uid;
	}

	public function getUid()
	{
		return $this-&gt;uid;
	}

	public function setPid($pid)
	{
		$this-&gt;pid = $pid;
	}

	public function getPid()
	{
		return $this-&gt;pid;
	}

	public function setText($text)
	{
		$this-&gt;text = $text;
	}

	public function getText()
	{
		return $this-&gt;text;
	}
}</pre>
<p>Remember we got autoloading so now we can go on in the pi1 for instance with:</p>
<pre name="code" class="php">
  $o_newRecord = new yourExtensionKey_model_databaseTableName();
  $o_newRecord-&gt;setText('Hallo Welt');
  $o_newRecord-&gt;save();</pre>
<p>What just happened is that we inserted a new Record into the database. That simple. After the save()  $o_newDummyRecord provides you with $o_newDummyRecord-&gt;getUid() witch will return the uid of the record we just inserted.</p>
<p>If you want to read a simple record from the Database the code would look like this:</p>
<pre name="code" class="php">
  $o_newRecord = new yourExtensionKey_model_databaseTableName();
  $o_newRecord-&gt;setUid(1);
  $o_newRecord-&gt;getThis();</pre>
<p>If you want all records that contain the string &#8220;Hello&#8221; ordered by sorting this would be your code:</p>
<pre name="code"  class="php">  $o_newRecord = new yourExtensionKey_model_databaseTableName();
  $o_newRecord-&gt;setText('Hello');
  $result = $o_newRecord-&gt;getAll('sorting');</pre>
<p>In this case $result would contain an array of yourExtensionKey_model_databaseTableName objects filled with the data of each record.<br />
Even getting querys build like (hidden = 0 AND Deleted = 0 AND (starttime = 0 OR starttime &lt; time()) AND ((endtime = 0 OR endtime &lt; time()))<br />
is possible.</p>
<p>Just like this:</p>
<pre name="code" class="php">
  $o_newRecord = new yourExtensionKey_model_databaseTableName();
  $o_newRecord-&gt;setText('Hello');
  $o_newRecord-&gt;setHidden(0);
  $o_newRecord-&gt;setDeleted(0);
  $o_newRecord-&gt;setStarttime('=_0_&gt;=_'.time());
  $o_newRecord-&gt;setEndtime('=_0_&lt;=_'.time());
  $result = $o_newDummyRecord-&gt;getAll('sorting');</pre>
<p>In this case your model should contain the member variables deleted, hidden, starttime and endtime as well as their getters and setters.</p>
<p>All of this you can see in action if you install the sl_zendframework and the slmvchelper extension to your typo3 and put the pi1 of slmvchelper in one of your pages. It will show you a simple example, and if you look inside the pi1 file you can see a little summary of this tutorial working.</p>
<p>I hoped you enjoyed my tutorial and feedback would be appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.swift-lizard.com/2009/11/18/using-the-advantages-of-zendframework-with-typo3/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>The blessings of an Autoloader</title>
		<link>http://www.swift-lizard.com/2009/11/15/the-blessings-of-an-autoloader/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.swift-lizard.com/2009/11/15/the-blessings-of-an-autoloader/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 21:31:25 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[zendFramework]]></category>

		<guid isPermaLink="false">http://swift-lizard.com/?p=80</guid>
		<description><![CDATA[Lately I came across the nice little autoloader provided by the Zend Framework. So I like to share some experiences. First of all, like I mentioned in the &#8220;About&#8221; section of my page, to me Zend is more like a new PEAR, but not like a framework to build websites. This is why I use [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I came across the nice little autoloader provided by the Zend Framework. So I like to share some experiences. First of all, like I mentioned in the &#8220;About&#8221; section of my page, to me Zend is more like a new PEAR, but not like a framework to build websites. This is why I use it together with some other php frameworks and CM-Systems.</p>
<p>But back to the topic of this post,.. I came across the new Autoloader Class provided with the Zend Framework, studied some of  the documentation. <span id="more-80"></span>And Failed,.. perhaps I over-read something but where does the documentation mention that your class has to be prefixed with the name of the namespace one registers ?</p>
<p>But one by one, if you like to use the autoloader either with your extension to the CM-System of your choice (in my case this would be Typo3 at 90% of the projects I work on), or within some php-code you write for a customer, you will have to  start wit something like this:</p>
<pre name="code" class="php">  set_include_path ( '.' . PATH_SEPARATOR . 'path/to/Zend_Framework/' );

  require_once 'Zend/Loader/Autoloader.php';
  $autoloader = Zend_Loader_Autoloader::getInstance ();
  $autoloader-&gt;setFallbackAutoloader ( true );
  $autoloader-&gt;registerNamespace ( 'nameOfYourNameSpace' );</pre>
<p>This was how far I got with the documentation. Because I know some other languages like JAVA, I knew that I would have to create a nice little sub folder called &#8220;nameOfYourNameSpace&#8221; in the directory for a SOAP &#8211; Client I  lately wrote for a customer of mine.  I went on creating the class file I needed:</p>
<pre name="code" class="php">  class myClass
  {
     public function __construct()
     {
        // here the code Starts
     }
  }</pre>
<p>Like I said I am used to the conventions of other languages when it comes to namspaces, so I called the file myClass.php. Now in my imprudence I thought something like this would work right from the Start, as well as I am getting rid of those require_once statements:</p>
<pre name="code" class="php">  $o_myObject = new nameOfYourNameSpace_myClass();</pre>
<p>Hhmmm,&#8230; nope it doesen`t,&#8230; turns out that the class within the file has to be prefixed by the name of the namespace it self. So I had to change the php class to this:</p>
<pre name="code" class="php">  class nameOfYourNameSpace_myClass
  {
     public function __construct()
     {
        // here the code Starts
     }
  }</pre>
<p>After that, the first code segment worked fine for me, and I had a nice little autoloader to load my models. Is it just me, or would you too have expected that it should be enough to create the folder structure registered in the first snippet and call the class just like the file name ?</p>
<p>Perhaps this was a little help for you getting to know the Zend_Loader_Autoloader.<br />
Drop me some thoughts if you like.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.swift-lizard.com/2009/11/15/the-blessings-of-an-autoloader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

