<?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>{5} Setfive - Talking to the World &#187; symfony</title>
	<atom:link href="http://shout.setfive.com/tag/symfony/feed/" rel="self" type="application/rss+xml" />
	<link>http://shout.setfive.com</link>
	<description></description>
	<lastBuildDate>Wed, 18 Jan 2012 21:09:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>AJAX Request Slow With PHP?  Here&#8217;s Why</title>
		<link>http://shout.setfive.com/2012/01/18/ajax-request-slow-with-php-heres-why/</link>
		<comments>http://shout.setfive.com/2012/01/18/ajax-request-slow-with-php-heres-why/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 21:09:19 +0000</pubDate>
		<dc:creator>Matt Daum</dc:creator>
				<category><![CDATA[Free Advice]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sessions]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://shout.setfive.com/?p=1372</guid>
		<description><![CDATA[Recently I was working on a project where we had a page which loads tons of data from numerous sources. I decided after a while that we wanted to AJAX each section of data so that the page would load a bit quicker. After splitting up the requests and sending them asyncronously, there was little [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was working on a project where we had a page which loads tons of data from numerous sources.  I decided after a while that we wanted to AJAX each section of data so that the page would load a bit quicker.  After splitting up the requests and sending them asyncronously, there was little improvement.  I thought at first it may be due to the fact we were pinging a single API for most of the data multiple times, that wasn&#8217;t it.  Maybe it was a browser limit? Nope was still far below the 6 requests most allow.  I setup xdebug and kcachegrind and to my surprise it was the session_start() that was taking the most time on the requests.  </p>
<p>I looked around the web for a while trying to figure out what in the world was going on.  It turns out that PHP&#8217;s default session_start will block future session_starts for the same session until the session is closed.  This is because the default method uses a file on the filesystem which it locks until you close it.  If you want more information on this and how to close it you can read a bit more <a href="http://konrness.com/php5/how-to-prevent-blocking-php-requests" target="_blank">here</a>.</p>
<p>We switched over to database based sessions and it fixed it.  In symfony 1.4 the default session storage uses the file system, however switching over to <a href="http://trac.symfony-project.org/browser/branches/1.4/lib/storage/sfPDOSessionStorage.class.php">sfPDOSessionStorage</a> is very easy and quick.  </p>
]]></content:encoded>
			<wfw:commentRss>http://shout.setfive.com/2012/01/18/ajax-request-slow-with-php-heres-why/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Adding a task/command in Symfony2</title>
		<link>http://shout.setfive.com/2011/09/09/adding-a-taskcommand-in-symfony2/</link>
		<comments>http://shout.setfive.com/2011/09/09/adding-a-taskcommand-in-symfony2/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 20:04:13 +0000</pubDate>
		<dc:creator>Ashish Datta</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[symfony2]]></category>

		<guid isPermaLink="false">http://shout.setfive.com/?p=822</guid>
		<description><![CDATA[I recently took the Symfony2 plunge and started working on a little fun side project (more on that later). Anyway, this particular project involves sending out daily text messages using the rather awesome Twilio API so I decided to use a Symfony2 task for this. The documentation on how to actually add your own task [...]]]></description>
			<content:encoded><![CDATA[<p>I recently took the Symfony2 plunge and started working on a little fun side project (more on that later).</p>
<p>Anyway, this particular project involves sending out daily text messages using the rather awesome Twilio API so I decided to use a Symfony2 task for this. The documentation on how to actually add your own task is a bit sparse so I figured I&#8217;d share.</p>
<p>The process is actually pretty straight forward:</p>
<ol>
<li>In your bundle create a directory named &#8220;Command&#8221; (without the quotes).</li>
<li>Create a file that extends ContainerAwareCommand</li>
<li>Create a protected function configure &#8211; &#8220;protected function configure()&#8221; to allow you to configure the name of your task and add any options or arguments you might need.</li>
<li>Create a protected function execute &#8211; &#8220;protected function execute(InputInterface $input, OutputInterface $output)&#8221; to actually do whatever needs to be done.</li>
<li>Thats it! Now you can run app/console and you&#8217;ll see your task.</li>
</ol>
<p>Here is the code for mine:</p>
<pre name="code" class="php">
namespace Setfive\SextDejourBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class SendTextsCommand extends ContainerAwareCommand
{

    protected function configure()
    {
        parent::configure();

        $this-&gt;setName('sj:sendTexts')
             -&gt;setDescription('Sends the day\'s sexts to everyone.');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {

         $ph = $this-&gt;getContainer()-&gt;get('doctrine')
                    -&gt;getRepository("SextDejourBundle:Phonenumber")
                    -&gt;createQueryBuilder("u")
                    -&gt;getQuery()
                    -&gt;getResult();

         $msg = $this-&gt;getContainer()-&gt;get('doctrine')
                    -&gt;getRepository("SextDejourBundle:Message")
                    -&gt;createQueryBuilder("u")
                    -&gt;where("u.is_used = false")
                    -&gt;setMaxResults(1)
                    -&gt;getQuery()
                    -&gt;getResult();
         $msg = array_pop( $msg );

         $msg-&gt;setIsUsed( true );
         // $this-&gt;getContainer()-&gt;get('doctrine')-&gt;getEntityManager()-&gt;flush();

         $accountId = $this-&gt;getContainer()-&gt;getParameter("twilio_app_id");
         $authToken = $this-&gt;getContainer()-&gt;getParameter("twilio_token");
         $myNumber = $this-&gt;getContainer()-&gt;getParameter("twilio_number");

         $client = new \Services_Twilio($accountId, $authToken);

         foreach( $ph as $p ){

           $sms = $p-&gt;getGender() == 0 ? $msg-&gt;getGuyText() : $msg-&gt;getGirlText();

           $res = $client-&gt;account-&gt;sms_messages-&gt;create ( $myNumber, $p-&gt;getPhoneNumber(), $sms );

           $output-&gt;writeln( $p-&gt;getPhoneNumber() . " =&gt; " . $sms );

         }

         return 0;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://shout.setfive.com/2011/09/09/adding-a-taskcommand-in-symfony2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Celebrating Symfony2 With One Free Project</title>
		<link>http://shout.setfive.com/2011/07/30/celebrating-symfony2-with-one-free-project/</link>
		<comments>http://shout.setfive.com/2011/07/30/celebrating-symfony2-with-one-free-project/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 16:10:12 +0000</pubDate>
		<dc:creator>Matt Daum</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[free project]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[symfony2]]></category>

		<guid isPermaLink="false">http://shout.setfive.com/?p=812</guid>
		<description><![CDATA[Symfony2 was released this past Thursday.  This marks a huge advancement in the framework with tons of new features, better programming patterns, and much better performance.  Symfony2 is now the most popular PHP project on GitHub and contributors are helping better it each day. Since we are so excited for this release, we are going [...]]]></description>
			<content:encoded><![CDATA[<p>Symfony2 was released this past Thursday.  This marks a huge advancement in the framework with tons of new features, better programming patterns, and much better performance.  Symfony2 is now the most popular PHP project on GitHub and contributors are helping better it each day.</p>
<p>Since we are so excited for this release, we are going to take on one small free project for the person or company who submits the best idea and reason for their project.  We&#8217;ll be picking the free project within one week of today. Shoot us an email with your project and reason you&#8217;d like it done for free.</p>
<p>Congrats to the entire Symfony2 team and we look forward to helping out with it!</p>
]]></content:encoded>
			<wfw:commentRss>http://shout.setfive.com/2011/07/30/celebrating-symfony2-with-one-free-project/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Congrats RentPrefs!</title>
		<link>http://shout.setfive.com/2011/07/29/congrats-rentprefs/</link>
		<comments>http://shout.setfive.com/2011/07/29/congrats-rentprefs/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 15:27:03 +0000</pubDate>
		<dc:creator>Ashish Datta</dc:creator>
				<category><![CDATA[Launch]]></category>
		<category><![CDATA[dogpatch]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[xconomy]]></category>

		<guid isPermaLink="false">http://shout.setfive.com/?p=797</guid>
		<description><![CDATA[Last week we launched RentPrefs a new take on renting an apartment. RentPrefs flips the process around by allowing renters to post their preferences and then allowing agents to match them with listings that fit their criteria. Anyway, yesterday Xconomy did an awesome write up about them so definitely check it out. We also got [...]]]></description>
			<content:encoded><![CDATA[<p>Last week we launched <a href="https://www.rentprefs.com" target="_blank">RentPrefs</a> a new take on renting an apartment. RentPrefs flips the process around by allowing renters to post their preferences and then allowing agents to match them with listings that fit their criteria.</p>
<p>Anyway, yesterday <a href="http://www.xconomy.com/boston/2011/07/28/rentprefs-with-matchmaking-approach-to-apartment-rentals-rolls-out-beta-service/" target="_blank">Xconomy</a> did an awesome write up about them so definitely check it out. We also got a nice mention at the end there!</p>
<p>Happy Friday! </p>
]]></content:encoded>
			<wfw:commentRss>http://shout.setfive.com/2011/07/29/congrats-rentprefs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TrackYourImpact.com Launched!</title>
		<link>http://shout.setfive.com/2011/03/25/trackyourimpact-com-launched/</link>
		<comments>http://shout.setfive.com/2011/03/25/trackyourimpact-com-launched/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 13:36:24 +0000</pubDate>
		<dc:creator>Matt Daum</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Launch]]></category>
		<category><![CDATA[apostrophe]]></category>
		<category><![CDATA[new launch]]></category>
		<category><![CDATA[sms]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[tea]]></category>

		<guid isPermaLink="false">http://shout.setfive.com/?p=592</guid>
		<description><![CDATA[Recently we&#8217;ve launched a new site for a client called Purpose Beverages: http://trackyourimpact.com . We&#8217;ve received great feedback from users so far. The site uses a wide range of technologies. It is built on symfony and uses the Apostrophe CMS to manage the main parts of the site. It integrates with a SMS provider to [...]]]></description>
			<content:encoded><![CDATA[<p>Recently we&#8217;ve launched a new site for a client called Purpose Beverages: <a title="http://trackyourimpact.com" href="http://trackyourimpact.com" target="_blank">http://trackyourimpact.com</a> .  We&#8217;ve received great feedback from users so far.  The site uses a wide range of technologies.  It is built on <a href="http://symfony-project.org">symfony</a> and uses the <a href="http://www.apostrophenow.com/">Apostrophe</a> CMS to manage the main parts of the site.  It integrates with a SMS provider to allow you text into it to find out more about your purchase.</p>
<p>Tēvolution is a new brand of tea on the market that does good with each purchase.  Every time someone buys it they done a specific amount(for example 25 cents) to a specific charity.  In order to find out how large of a donation and what charity your bottle goes to you can actually text the code found on the bottle to the website, or you can login in on your phone browser or regular browser and enter the code.  You will find out how much and to whom you just donated money to!</p>
<p>Right now Tēvolution is just coming to the market so keep your eyes peeled for it!  It&#8217;s a great product that does good!</p>
]]></content:encoded>
			<wfw:commentRss>http://shout.setfive.com/2011/03/25/trackyourimpact-com-launched/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting an extra &#8216;Invalid&#8217; or other error on your symfony form?</title>
		<link>http://shout.setfive.com/2011/01/27/getting-an-extra-invalid-or-other-error-on-your-symfony-form/</link>
		<comments>http://shout.setfive.com/2011/01/27/getting-an-extra-invalid-or-other-error-on-your-symfony-form/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 21:39:11 +0000</pubDate>
		<dc:creator>Matt Daum</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[postvalidators]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[validator]]></category>

		<guid isPermaLink="false">http://shout.setfive.com/?p=522</guid>
		<description><![CDATA[On a project I&#8217;m working on I came across the following problem: we had a email field that we needed to be unique in our system, but we also made sure that it matched a confirm email field. A snippet of our form looks like this: public function configure() { $this-&#62;setWidgets( array( 'email' =&#62; new [...]]]></description>
			<content:encoded><![CDATA[<p>On a project I&#8217;m working on I came across the following problem:  we had a email field that we needed to be unique in our system, but we also made sure that it matched a confirm email field.  A snippet of our form looks like this:</p>
<pre class="php" name="code">  public function configure()
  {
     $this-&gt;setWidgets( array(
        'email'         =&gt; new sfWidgetFormInputText()
        'confirm_email' =&gt; new sfWidgetFormInputText()
      ));

      $this-&gt;setValidators(array(

      'email'=&gt;         new sfValidatorAnd(
                          array(
                              new sfValidatorEmail( array('required' =&gt; true) ),
                              new sfValidatorDoctrineUnique(
                                  array('throw_global_error' =&gt; true, 'model' =&gt; 'sfGuardUser', 'column' =&gt; 'username'),
                                  array('invalid' =&gt; 'Sorry! A user with that email address already exists.')
                              )
                          )),
        'confirm_email' =&gt; new sfValidatorEmail( array('required' =&gt; true) )

      ));

      $this-&gt;validatorSchema-&gt;setPostValidator(
        new sfValidatorSchemaCompare('password', '==', 'confirm_password')
      );
  }
</pre>
<p>When we submitted an email that was already in the system we got back two errors:</p>
<ul>
<li>Sorry! A user with that email address already exists.</li>
<li>Invalid.</li>
</ul>
<p>For a while I thought is there some extra validator somewhere that I left on?  Where is this invalid coming from?  It ended up being due to the way the validators work.  If a validator throws an error it doesn&#8217;t return that validator&#8217;s value.  So by the time it gets to the sfValidatorSchemaCompare post validator the value of `email` is null and `confirm_email` has the value you input, thus the seemingly extra &#8216;Invalid&#8217; message.</p>
<p>This can be fixed easily with a sfValidatorCallback instead of the sfValidatorSchemaCompare.  Here is the fix:</p>
<pre class="php" name="code">  public function validateConfirmEmail( $validator, $values ){

    if($values['email']&amp;&amp;$values['email']!=$values['confirm_email'])
    {
      throw new sfValidatorError($validator, 'Please confirm your email, currently they do not match!.');
    }

    return $values;
  }
</pre>
<p>This way if the email is blank it doesn&#8217;t both making sure that the `email` matches the `confirm_email`.  You don&#8217;t need to worry about a person just passing two blank emails as the earlier validator(the sfValidatorEmail requires it to be there and valid).</p>
<p><strong>If you are getting an extra validation error, check your postValidators and how the values get to them.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://shout.setfive.com/2011/01/27/getting-an-extra-invalid-or-other-error-on-your-symfony-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing a Doctrine connection with the same name in single instance</title>
		<link>http://shout.setfive.com/2010/12/06/changing-a-doctrine-connection-with-the-same-name-in-single-instance/</link>
		<comments>http://shout.setfive.com/2010/12/06/changing-a-doctrine-connection-with-the-same-name-in-single-instance/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 17:01:06 +0000</pubDate>
		<dc:creator>Matt Daum</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[doctrine_manager]]></category>
		<category><![CDATA[multiple connections]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://shout.setfive.com/?p=482</guid>
		<description><![CDATA[On one of our projects that we use multiple connections that are defined at run time we recently were generating reports that required us to change a specific connection multiple times in a single run.    We noticed that even though we would define a new connection, it would not throw any errors but just continue [...]]]></description>
			<content:encoded><![CDATA[<p>On one of our projects that we use multiple connections that are defined at run time we recently were generating reports that required us to change a specific connection multiple times in a single run.    We noticed that even though we would define a new connection, it would not throw any errors but just continue to use the originally defined connection.  Here is how we were doing the connections:</p>
<pre name="code" class="php">
$databaseManager = sfContext::getInstance()->getDatabaseManager();
$manager=Doctrine_Manager::getInstance();
$newConn = new sfDoctrineDatabase(array('dsn'=>'XXX','name'=> 'ExampleName'));
$newConn->connect();
$databaseManager->setDatabase('ExampleName',$newConn);
</pre>
<p>If you called the code above once, it would connect properly to the given DSN.  However if you then called it a second time with a new DSN, it would not error and would simply just remain connected to the first DSN.  After hunting around a bit it was the problem that Doctrine wasn&#8217;t assigning the new connection as the old connection was still open.  To get around this we updated the code to the following:</p>
<pre name="code" class="php">
$databaseManager = sfContext::getInstance()->getDatabaseManager();
$manager=Doctrine_Manager::getInstance();

// If the Doctrine Manager has the connection already close it so the new connection can be established
if($manager->contains('ExampleName'))
        $manager->closeConnection($manager->getConnection('ExampleName'));
$newConn = new sfDoctrineDatabase(array('dsn'=>'XXX','name'=> 'ExampleName'));
$newConn->connect();
$databaseManager->setDatabase('ExampleName',$newConn);
</pre>
<p>You need to first check to see if the Doctrine Manager has the connection, as if you try to get a connection that doesn&#8217;t exist, it will throw an exception.</p>
<p>Hope this saves you some time!</p>
]]></content:encoded>
			<wfw:commentRss>http://shout.setfive.com/2010/12/06/changing-a-doctrine-connection-with-the-same-name-in-single-instance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone style checkboxes for Symfony</title>
		<link>http://shout.setfive.com/2010/10/13/iphone-style-checkboxes-for-symfony/</link>
		<comments>http://shout.setfive.com/2010/10/13/iphone-style-checkboxes-for-symfony/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 22:46:13 +0000</pubDate>
		<dc:creator>Ashish Datta</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://shout.setfive.com/?p=412</guid>
		<description><![CDATA[No one worry, I did in fact survive my birthday and subsequent party! Anyway, I was poking around for some cool UI elements for checkboxes and stumbled across this neat jQuery plugin &#8211; http://github.com/tdreyno/iphone-style-checkboxes Basically, what it does is converts checkboxes into iPhone style toggles. Check out a demo at http://tdreyno.github.com/iphone-style-checkboxes/ This is for a [...]]]></description>
			<content:encoded><![CDATA[<p>No one worry, I did in fact survive my birthday and subsequent party!</p>
<p>Anyway, I was poking around for some cool UI elements for checkboxes and stumbled across this neat jQuery plugin &#8211; <a href="http://github.com/tdreyno/iphone-style-checkboxes" target="_blank">http://github.com/tdreyno/iphone-style-checkboxes</a> Basically, what it does is converts checkboxes into iPhone style toggles.</p>
<p>Check out a demo at <a href="http://tdreyno.github.com/iphone-style-checkboxes/" target="_blank">http://tdreyno.github.com/iphone-style-checkboxes/</a></p>
<p>This is for a symfony project (shocker!), so I figured I&#8217;d roll it into a widget and share.</p>
<p>You&#8217;ll need to download and include the JS+CSS+images for the plugin yourself and then copy the following code into your project:</p>
<pre name="code" class="php">

class sfWidgetFormInputiPhoneCheckbox extends sfWidgetFormInputCheckbox {

	public function __construct($options = array(), $attributes = array())
	{

		$this->addOption('checked_label');
        $this->addOption('un_checked_label');

		parent::__construct($options, $attributes);
	}

	public function render($name, $value = null, $attributes = array(), $errors = array())
	{
		$str = parent::render( $name, $value, $attributes, $errors );

		$checkedLabel = $this->getOption("checked_label");
        $uncheckedLabel = $this->getOption("un_checked_label");
        $id = $this->generateId($name);

		$str .= <<<EOF
		<script type='text/javascript'>

		  $(document).ready( function(){

                $('#$id').iphoneStyle({
                    checkedLabel: '$checkedLabel',
                    uncheckedLabel: '$uncheckedLabel'
                });

		  });
		</script>
EOF;

		return $str;
	}

}
</pre>
<p>Using it is straightforward:</p>
<pre name="code" class="php">
    $this->setWidgets(array(
      'show-upcoming-events-nav' => new sfWidgetFormInputiPhoneCheckbox( array("checked_label" => "on", "un_checked_label" => "off") ),
    ));
</pre>
]]></content:encoded>
			<wfw:commentRss>http://shout.setfive.com/2010/10/13/iphone-style-checkboxes-for-symfony/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ahDoctrineEasyEmbeddedRelationsPlugin and Composite Primary Keys</title>
		<link>http://shout.setfive.com/2010/09/03/ahdoctrineeasyembeddedrelationsplugin-and-composite-primarykeys/</link>
		<comments>http://shout.setfive.com/2010/09/03/ahdoctrineeasyembeddedrelationsplugin-and-composite-primarykeys/#comments</comments>
		<pubDate>Fri, 03 Sep 2010 18:47:09 +0000</pubDate>
		<dc:creator>Matt Daum</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[ahDoctrineEasyEmbeddedRelationsPlugin]]></category>
		<category><![CDATA[composite keys doctrine]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[embedding forms]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[symfony plugins]]></category>

		<guid isPermaLink="false">http://shout.setfive.com/?p=389</guid>
		<description><![CDATA[We&#8221;ve been working on a project in which a bunch of the tables had composite primary keys.  Often we wanted to embed these tables in other forms.  ahDoctrineEasyEmbeddedRelationsPlugin is a great plugin for managing embedded forms with Doctrine and Symfony.  It lets you easily let users add multiple new relations and delete previous ones.   However, [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8221;ve been working on a project in which a bunch of the tables had composite primary keys.  Often we wanted to embed these tables in other forms.  <a href="http://www.symfony-project.org/plugins/ahDoctrineEasyEmbeddedRelationsPlugin/1_4_3">ahDoctrineEasyEmbeddedRelationsPlugin</a> is a great plugin for managing embedded forms with Doctrine and Symfony.  It lets you easily let users add multiple new relations and delete previous ones.   However, it didn&#8217;t really support composite keys.   We also wanted to be able to expose the primary keys rather than unsetting them from the form(so that the relation is automatically declared).  This was a problem as we needed to be able to select at least one of the primary keys.  Here is an example where we wanted to let the user pick one of the primary keys:</p>
<pre>User:
  columns:
     first_name:
        type: string(16)
Product:
   columns:
      name:
         type: string(32)
UserProduct:
   columns:
      user_id:
         type: integer
      product_id:
         type: integer
        price:
          type: decimal
    relations:
       User:
          local: user_id
          foreign: id
       Product:
         local: product_id
         foreign: id
</pre>
<p>In this case there are Products and Users.  A Users can have a products and specify how much each costs.  When you are adding products to a user, you would want to be able to select which product you are adding in the embedded form.  This is where our problem was, with the plugin as of version 1.4.4 you couldn&#8217;t tell it not to unset the primary keys when it embedded the form.  We did a checkout of the plugin from SVN and modified it a bit.  It now has and additional parameter: newFormUnsetPrimaryKeys .  This will make it so the plugin will not unset the primary keys on a new form if you set it to true (it defaults to false).</p>
<p>We also found that the plugin had hard coded a couple of places findOneById which required the primary key to be called `id`.  We&#8217;ve updated this to use the Doctrine method getIdentifierColumnNames() to get the primary keys.</p>
<p>We only applied to be developers on this script, so are currently waiting on it to be packaged and released, however if you want our updated just do a svn checkout of the plugin and you will be all set!</p>
<p>Let us know if you have any questions on it!</p>
]]></content:encoded>
			<wfw:commentRss>http://shout.setfive.com/2010/09/03/ahdoctrineeasyembeddedrelationsplugin-and-composite-primarykeys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doctrine Multiple Connections with Symfony Web Debug Toolbar</title>
		<link>http://shout.setfive.com/2010/07/08/doctrine-multiple-connections-with-symfony-web-debug-toolbar/</link>
		<comments>http://shout.setfive.com/2010/07/08/doctrine-multiple-connections-with-symfony-web-debug-toolbar/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 19:31:34 +0000</pubDate>
		<dc:creator>Matt Daum</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[web debug toolbar]]></category>

		<guid isPermaLink="false">http://shout.setfive.com/?p=374</guid>
		<description><![CDATA[In April I wrote about using Doctrine with multiple connections for specific table models.  This worked really well, except Symfony&#8217;s web debug toolbar would not show any SQL queries that were not defined in the databases.yml file.  This of course made it quite difficult to debug many queries, as the query logs show the queries [...]]]></description>
			<content:encoded><![CDATA[<p>In April I wrote about using <a href="http://shout.setfive.com/2010/04/07/doctrine-multiple-connections-and-specific-tables/">Doctrine with multiple connections for specific table models</a>.  This worked really well, except Symfony&#8217;s web debug toolbar would not show any SQL queries that were not defined in the databases.yml file.  This of course made it quite difficult to debug many queries, as the query logs show the queries before the parameters are inserted, for example:</p>
<pre name="code" class="sql">SELECT a.id, a.title FROM posts a WHERE id = ?
</pre>
<p>The web debug toolbar however shows them with the parameters in place.  This makes it a ton quicker to debug as you can see the parameters in place, as well as copy and paste the query straight into the SQL client to see the raw results.  After a few months and a project becoming much more complex it was necessary to see the queries.  I looked up how <a href="http://www.symfony-project.org/api/1_4/sfWebDebugPanelDoctrine">sfWebDebugPanelDoctrine</a> gets the queries and found:</p>
<pre class="php" name="code" >  protected function getDoctrineEvents()
  {
    $databaseManager = sfContext::getInstance()-&gt;getDatabaseManager();

    $events = array();
    if ($databaseManager)
    {
      foreach ($databaseManager-&gt;getNames() as $name)
      {
        $database = $databaseManager-&gt;getDatabase($name);
        if ($database instanceof sfDoctrineDatabase &amp;&amp; $profiler = $database-&gt;getProfiler())
        {
          foreach ($profiler-&gt;getQueryExecutionEvents() as $event)
          {
            $events[$event-&gt;getSequence()] = $event;
          }
        }
      }
    }

    // sequence events
    ksort($events);

    return $events;
  }
</pre>
<p>So the <a href="http://www.symfony-project.org/api/1_4/sfDatabaseManager">sfDatabaseManager</a> would manage all the connections and return which ones to pull queries off of.  I looked at it a bit and saw that it has setDatabase which sets the databases it has registered.  Since it requires you give it a <a href="http://www.symfony-project.org/api/1_4/sfDatabase">sfDatabase</a> as a parameter I had to update the way we connect the databases a bit so we could pass them to it.  The new version is below:</p>
<pre class="php" name="code" >          $databaseManager = sfContext::getInstance()-&gt;getDatabaseManager();
          $newConn=new sfDoctrineDatabase(array('name'=&gt;'NewConnectionName','dsn'=&gt;$databaseString));
          $newConn-&gt;connect();
          $databaseManager-&gt;setDatabase('NewConnectionName',$newConn);
</pre>
<p>Now you will now see the queries in the web debug toolbar.</p>
]]></content:encoded>
			<wfw:commentRss>http://shout.setfive.com/2010/07/08/doctrine-multiple-connections-with-symfony-web-debug-toolbar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

