<?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>code and effect &#187; Symfony</title>
	<atom:link href="http://www.codeandeffect.co.uk/blog/category/programming/symfony/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codeandeffect.co.uk/blog</link>
	<description>It's quite deliberate</description>
	<lastBuildDate>Mon, 08 Mar 2010 14:28:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A Daily-Symfony-Quick-Setup-Zen-Cheatsheet</title>
		<link>http://www.codeandeffect.co.uk/blog/2009/programming/symfony/a-daily-symfony-quick-setup-zen-cheatsheet/</link>
		<comments>http://www.codeandeffect.co.uk/blog/2009/programming/symfony/a-daily-symfony-quick-setup-zen-cheatsheet/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 19:26:16 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[cheatsheet]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony 1.2]]></category>

		<guid isPermaLink="false">http://www.codeandeffect.co.uk/blog/?p=323</guid>
		<description><![CDATA[Making the transition to Symfony 1.2 and Doctrine all at once was never going to be easy. As  Doctrine is the future of symfony and I have a distinct Propel addiction, the following steps (based on the early stages of the excellent Jobeet tutorial) will take no time at all and can be practised [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #7d7d7d;">Making the transition to <a title="http://www.symfony-project.org/" href="http://www.symfony-project.org/" target="_blank">Symfony 1.2</a> and <a title="Doctrine PHP Object Relational Mapper" href="http://www.doctrine-project.org/" target="_self">Doctrine </a>all at once was never going to be easy. As  <a title="New in symfony 1.3: What's up with Propel and Doctrine?" href="http://www.symfony-project.org/blog/2009/06/11/new-in-symfony-1-3-what-s-up-with-propel-and-doctrine" target="_blank">Doctrine is the future of symfony </a>and I have a distinct <a title="Propel PHP Object Relational Mapper" href="http://propel.phpdb.org/" target="_self">Propel</a> addiction, the following steps (based on the early stages of the excellent <a title="The Symfony 1.2 / Doctrine Jobeet tutorial" href="http://www.symfony-project.org/jobeet/1_2/Doctrine/en/" target="_blank">Jobeet</a> tutorial) will take no time at all and can be practised often to help cement the process in mind until it&#8217;s second nature.<br />
</span></p>
<p><span style="color: #7d7d7d;">This is no substitute for (and will make little sense without first reading) the <a title="You now have two links to this tutorial, and no excuses" href="http://www.symfony-project.org/jobeet/1_2/Doctrine/en/" target="_blank">Jobeet</a> tutorial, nor the <a title="Symfony Documentation" href="http://www.symfony-project.org/doc/1_2/" target="_blank">documentation</a>. This is just my daily-Symfony-quick-setup-zen-cheatsheet. I hope in time to be doing this one-handed in my sleep while vaccuuming the stairs. Copy+Paste strictly out of bounds.<br />
</span></p>
<p><span style="color: #7d7d7d;"><em>If you choose to use this and repeat it often, you&#8217;ll have setup your web server config&#8217; on your development setup ready to run this, so those steps are omitted.</em><br />
</span></p>
<p><span style="color: #7d7d7d;">Posted here in a  bit of a rush to respond to <a title="http://twitter.com/jwage" href="http://twitter.com/jwage" target="_blank">Jwage</a>&#8217;s request , I hope they live up to expectation, and that someone finds them useful. </span><span style="color: #7d7d7d;">I am bound to have made some errors, some omissions or not been concise enough, please let me know.</span></p>
<h3><span class="mw-headline">Create The Project</span></h3>
<ul>
<li> <em>mkdir &lt;path_to_local dev&gt;\newsymfonytest</em></li>
<li> <em>cd </em><em>&lt;path_to_local dev&gt;\</em><em>newsymfonytest</em></li>
</ul>
<p>From now on<em>&lt;path_to_local dev&gt;\</em><em>newsymfonytest</em> is your <em>&lt;project&gt;</em> directory</p>
<ul>
<li> <em>php &lt;path_to_symfony&gt;\data\bin\symfony generate:project newsymfonytest</em>
<ul>
<li> Note that this creates an absolute path to Symfony in &lt;project&gt;/config/ProjectConfiguration.class.php which you should update.</li>
</ul>
</li>
<li> copy the <em>sf </em>folder from <em> &lt;path_to_symfony&gt;\data\web\</em> into <em>&lt;project&gt;/apps/frontend/web</em> or alias it in your server configuration <em>Alias /sf &#8220;</em><em>&lt;path_to_symfony&gt;</em><em>\data\web\sf&#8221;</em></li>
</ul>
<ul>
<li> Now <em>Symfony </em>is linked from your current location, the &lt;project&gt; root, test local access to Command-Line Interface with <em>php symfony cc</em></li>
<li> <span style="text-decoration: line-through;">Check the application has been created by visiting in browser</span></li>
</ul>
<h3><span class="editsection"> </span><span class="mw-headline">Setup Doctrine Database</span></h3>
<ul>
<li> Replace the setup function in <em>&lt;project&gt;/config/ProjectConfiguration.class.php</em></li>
</ul>
<pre>public function setup()
{
  $this-&gt;enablePlugins(array('sfDoctrinePlugin'));
  $this-&gt;disablePlugins(array('sfPropelPlugin'));
}</pre>
<ul>
<li> Publish any plugin assets:<em> php symfony plugin:publish-assets</em></li>
<li> Clear the Cache <em>php symfony cc</em></li>
<li> Remove <em>Propel </em>structure, create <em>Doctrine </em>structure:
<ul>
<li><em>rm config/propel.ini</em></li>
<li><em>rm config/schema.yml</em></li>
<li><em>rm config/databases.yml</em></li>
<li> <em>mkdir config/doctrine</em></li>
</ul>
</li>
<li> create database in MySQL:  <em>mysqladmin -u root -p create newsymfonytest</em></li>
<li>&lt;&lt; enter password when prompted  or omit -p if you have no password set (shame on you!)<em> &gt;&gt; </em></li>
<li> setup the YAML schema in &lt;project&gt;/config/doctrine/schema.yml</li>
</ul>
<p>Here&#8217;s my sample schema.yml, lifted from the Jobeet tutorial:</p>
<pre># config/doctrine/schema.yml
SampleCategory:
  actAs: { Timestampable: ~ }
  columns:
    name: { type: string(255), notnull: true, unique: true }

SampleItem:
  actAs: { Timestampable: ~ }
  columns:
    category_id:  { type: integer, notnull: true }
    type:         { type: string(255) }
    is_activated: { type: boolean, notnull: true, default: 0 }
    email:        { type: string(255), notnull: true }
    expires_at:   { type: timestamp, notnull: true }
  relations:
    SampleCategory: { onDelete: CASCADE, local: category_id, foreign: id, foreignAlias: SampleItems }</pre>
<ul>
<li>
<pre> Generate a new Databases.yml:</pre>
</li>
</ul>
<p><em>php symfony configure:database &#8211;name=doctrine &#8211;class=sfDoctrineDatabase &#8220;mysql:host=localhost;dbname=newsymfonytest&#8221; &lt;mysqluser&gt; &lt;mysqlpass&gt;</em></p>
<h3>Build!!!</h3>
<ul>
<li> <em>php symfony doctrine:build-model</em></li>
<li> <em>php symfony doctrine:build-sql</em></li>
<li> <em>php symfony doctrine:insert-sql</em></li>
<li> <em>php symfony doctrine:build-forms</em></li>
</ul>
<h3>Add Sample Data</h3>
<p>Create  fixture files:</p>
<p>Here&#8217;s my sample  <span style="color: #008000;"><em><em>&lt;project&gt;</em>data/fixtures/categories.yml</em><span style="color: #000000;">, again lifted from the <a href="http://www.symfony-project.org/jobeet/1_2/Doctrine/en/" target="_blank">Jobeet</a> tutorial:</span></span></p>
<pre>SampleCategory:
  design:
    name: Design
  programming:
    name: Programming
  manager:
    name: Manager
  administrator:
    name: Administrator</pre>
<p>Here&#8217;s my sample<em> </em><span style="color: #008000;"><em><em>&lt;project&gt;</em>data/fixtures/items.</em></span><span style="color: #008000;"><em>yml</em><span style="color: #000000;">, curiously similar to one from the <a href="http://www.symfony-project.org/jobeet/1_2/Doctrine/en/" target="_blank">Jobeet</a> tutorial I&#8217;ve said so little about.</span></span></p>
<pre>SampleItem:
  job_sensio_labs:
    SampleCategory: programming
    type:         full-time
    is_activated: true
    email:        job@example.com
    expires_at:   '2010-10-10'</pre>
<ul>
<li>Populate with <em>php symfony doctrine:data-load</em></li>
</ul>
<h3><span class="mw-headline">Generate first app </span></h3>
<ul>
<li> <em>php symfony  generate:app &#8211;escaping-strategy=on &#8211;csrf-secret=1sTh15r34l1y53cur3  frontend</em></li>
<li>Visit the site root you set up in your server configuration in your browser</li>
</ul>
<h3><span>Generate first module</span></h3>
<ul>
<li>Then, using the format:</li>
</ul>
<pre>  "php symfony doctrine:generate-module --with-show --non-verbose-templates &lt;appname&gt; &lt;modulename&gt; &lt;modelname&gt;"</pre>
<p><em>php symfony doctrine:generate-module &#8211;with-show &#8211;non-verbose-templates frontend sample SampleItem</em></p>
<ul>
<li>Visit the module in your browser</li>
<li>Rinse and repeat</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.codeandeffect.co.uk/blog/2009/programming/symfony/a-daily-symfony-quick-setup-zen-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mixing Object and Form Helpers in Symfony</title>
		<link>http://www.codeandeffect.co.uk/blog/2008/programming/symfony-object-form-helpers/</link>
		<comments>http://www.codeandeffect.co.uk/blog/2008/programming/symfony-object-form-helpers/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 08:00:17 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Web Computing]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://www.codeandeffect.co.uk/blog/?p=285</guid>
		<description><![CDATA[Being new to Symfony I&#8217;m still getting my head around some of its paradigms. Two months with the manual before embarking on any development taught me that it was worth pursuing, but there&#8217;re always areas you need to see working.
The Object form helpers looked particularly useful, so for my first production development I aim to [...]]]></description>
			<content:encoded><![CDATA[<p>Being new to Symfony I&#8217;m still getting my head around some of its paradigms. Two months with the manual before embarking on any development taught me that it was worth pursuing, but there&#8217;re always areas you need to <em>see </em>working.</p>
<p>The Object form helpers looked particularly useful, so for my first production development I aim to use them wherever possible. These helpers allow you edit objects directly, simplifying the update process back in your actions.</p>
<p>sample form in <em>editformSuccess.php</em> template:</p>
<p><code>&lt;?php echo form_tag('editform/updatetitle'); ?&gt;<br />
&lt;?php echo object_input_hidden_tag($newsletter, 'getID') ;?&gt;<br />
Title: &lt;?php echo object_input_tag($newsletter, 'getTitle') ;?&gt;<br />
&lt;?php echo submit_tag('update'); ?&gt;</code></p>
<p>and in <em>actions.class.php</em>:</p>
<p><code>&lt;?php<br />
public function executeEditform($request)<br />
{<br />
$this-&gt;newsletter =  <span style="color: #99cc00;">»</span><br />
NewsletterPeer::retrieveByPk($request-&gt;getParameter('id'));<br />
$this-&gt;forward404Unless($this-&gt;newsletter);<br />
}<br />
<br />
public function executeUpdatetitle($request)<br />
{<br />
$nltoupdate = NewsletterPeer::retrieveByPk($request-&gt;getParameter('id'));<br />
$this-&gt;forward404Unless($nltoupdate );<br />
$nltoupdate-&gt;fromArray(<span style="color: #99cc00;">»</span><br />
$this-&gt;getRequest()-&gt;getParameterHolder()-&gt;getAll(),BasePeer::TYPE_FIELDNAME);<br />
$nltoupdate-&gt;save();<br />
return $this-&gt;redirect(<span style="color: #99cc00;">»</span><br />
'newsletters/view?id='.$request-&gt;getParameter('id'));<br />
}</code></p>
<p>The update code uses the <em>fromArray </em>method to update any properties of your object it holds data for, received from your form. Adding fields to your form doesn&#8217;t require changes to the action.</p>
<p>I got into difficulties when it came to setting a boolean field for my object, called &#8220;IsPublished&#8221;. Wishing to stick with the Object form helpers I investigated the <a title="ObjectHelper::object_select_tag()" href="http://www.symfony-project.org/api/1_1/ObjectHelper#method_object_select_tag">Object_select_tag</a>, however this has a different use altogether &#8211; allowing you to grab properties of other objects to match with your current object. The classic example being choosing an <em>author </em>from the <em>authors </em>object to match up to a <em>post </em>object.</p>
<p>I still wanted to save a property for my object, but I didn&#8217;t want to have it select from the object, or grab values from other objects. Further searches revealed I wasn&#8217;t alone in wondering how to set default selected values and generally get to grips with <em>object_select_tag</em>.</p>
<p>Mixing Object and Form helpers seemed the best solution, using <a title="FormHelper::select_tag()" href="http://www.symfony-project.org/api/1_1/FormHelper#method_select_tag">select_tag</a> for my boolean field. However this meant I wasn&#8217;t using the Object helper exclusively, so would it still work with <em>fromArray</em>?</p>
<p>The form code generated looked promisingly simple, so I tried a mix of <a title="ObjectHelper::object_input_tag()" href="http://http://www.symfony-project.org/api/1_1/ObjectHelper#method_object_input_tag">object_input_tag</a> and <em>select_tag</em> in my <em>editformSuccess.php</em> template:</p>
<p><code>&lt;?php<br />
$defaultOption =  <span style="color: #99cc00;">»</span><br />
$newsletter-&gt;getIsPublished() == 1?1:0; <span style="color: #99cc00;"># get current, set default</span><br />
echo select_tag('<span style="color:red;">in_published</span>', options_for_select(array(<span style="color: #99cc00;">»</span><br />
0, 1),<br />
$defaultOption));<br />
?&gt;<br />
</code></p>
<p>Note the highlighted property in <em>select_tag</em>. My Object Property is called &#8220;IsPublished&#8221;. To object-generate a plain text input field I&#8217;d have used:</p>
<p><code>&lt;?php<br />
Published: &lt;?php echo object_input_tag($newsletter, 'getIsPublished') ;<br />
?&gt;</code></p>
<p>So my current field value would be retrieved, and the Object helper generates form fields using <em>BasePeer::TYPE_FIELDNAME</em> which in turn is used in my <em>fromArray </em>method to update the Db.</p>
<p>Normally one would use <em>select_tag</em> with internal field names (<em>BasePeer:: TYPE:PHP_NAME</em>) and write more action code to marry them up before a save(), however here I have to add my database field name into my view code.</p>
<p>Tethering your templates to your database schema is a route no-one should go down. So the internal name should be converted to the Db name on-the-fly in your template. The Peer classes have a function for this, and its public. The following call converts your usual internal field name for you, ready to drop into your <em>select_tag</em>:</p>
<p><code><br />
&lt;?php<br />
$IsPublished_translated = BaseNewsletterPeer::translateFieldName(<span style="color: #99cc00;">»</span>'IsPublished',BasePeer::TYPE_PHPNAME, BasePeer::TYPE_FIELDNAME )<br />
?&gt;</p>
<p></code></p>
<p>You could assign this in your action, but it works just as well in the template:</p>
<p><code>&lt;?php<br />
echo select_tag(<span style="color: #99cc00;">»</span><br />
'<span style="color:red;">BaseNewsletterPeer::translateFieldName(<span style="color: #99cc00;">»</span><br />
'IsPublished',BasePeer::TYPE_PHPNAME, BasePeer::TYPE_FIELDNAME</span>',<span style="color: #99cc00;">»</span><br />
 options_for_select(array(<span style="color: #99cc00;">»</span><br />
0, 1),<br />
$defaultOption));<br />
?&gt;<br />
</code></p>
<p>A final step would be to migrate this into a function higher up that so as to make templates a little prettier when editing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeandeffect.co.uk/blog/2008/programming/symfony-object-form-helpers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
