<?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>Agence de Développement Informatique du Nord &#187; Symfony</title>
	<atom:link href="http://blog.adin.pro/category/symfony/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.adin.pro</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Thu, 26 Dec 2019 08:54:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>PHP &#8211; Only the &#8216;en&#8217; locale is supported. Please install the &#8216;intl&#8217; extension for full localization capabilities.</title>
		<link>http://blog.adin.pro/2015-05-30/php-only-the-en-locale-is-supported-please-install-the-intl-extension-for-full-localization-capabilities/</link>
		<comments>http://blog.adin.pro/2015-05-30/php-only-the-en-locale-is-supported-please-install-the-intl-extension-for-full-localization-capabilities/#comments</comments>
		<pubDate>Sat, 30 May 2015 13:52:04 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[intl]]></category>
		<category><![CDATA[Symfony2]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=478</guid>
		<description><![CDATA[<p>If you encounter this error message on a Symfony2 project, you just have to install php5-intl module And don&#8217;t forget to restart apache</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2015-05-30/php-only-the-en-locale-is-supported-please-install-the-intl-extension-for-full-localization-capabilities/">PHP &#8211; Only the &#8216;en&#8217; locale is supported. Please install the &#8216;intl&#8217; extension for full localization capabilities.</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>If you encounter this error message on a Symfony2 project, you just have to install php5-intl module</p>
<pre class="brush: bash; title: ; notranslate">
apt-get install php5-intl
</pre>
<p>And don&#8217;t forget to restart apache</p>
<pre class="brush: bash; title: ; notranslate">
service apache2 restart
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2015-05-30/php-only-the-en-locale-is-supported-please-install-the-intl-extension-for-full-localization-capabilities/">PHP &#8211; Only the &#8216;en&#8217; locale is supported. Please install the &#8216;intl&#8217; extension for full localization capabilities.</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2015-05-30/php-only-the-en-locale-is-supported-please-install-the-intl-extension-for-full-localization-capabilities/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>doctrine2 random</title>
		<link>http://blog.adin.pro/2014-03-06/doctrine2-random/</link>
		<comments>http://blog.adin.pro/2014-03-06/doctrine2-random/#comments</comments>
		<pubDate>Thu, 06 Mar 2014 20:21:46 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctrine2]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[rand]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[Symfony2]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=367</guid>
		<description><![CDATA[<p>For some really good reasons or, doctrine2 do not implement the RAND() fonction to sort randomly your query results. Here some dirty ways to do it. Don&#8217;t use them it&#8217;s bad. One solution is to shuffle your collection of rows &#8230; <a href="http://blog.adin.pro/2014-03-06/doctrine2-random/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-03-06/doctrine2-random/">doctrine2 random</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>For some really good reasons or, doctrine2 do not implement the RAND() fonction to sort randomly your query results. Here some dirty ways to do it. Don&#8217;t use them it&#8217;s bad.</p>
<p>One solution is to shuffle your collection of rows using php</p>
<pre class="brush: php; title: ; notranslate">
      public function getRandom($max = 10,$site) {
        $results = $this-&gt;createQueryBuilder('u')
                -&gt;where('u.site = :site')
                -&gt;setParameter('site', $site)
                -&gt;orderBy('u.sort', 'DESC')
                -&gt;setMaxResults($max)
                -&gt;getQuery()
                -&gt;getResult();
        shuffle($results);
        return $results;
    }
</pre>
<p>In this solution, you retrieve the last 10 rows and shuffle them after. Peformances are not too bad but you will always retrieves the same last rows from your table.</p>
<p>Another solution is to use the array_rand php fonction</p>
<pre class="brush: php; title: ; notranslate">
      public function getRandom($site) {
        $results = $this-&gt;createQueryBuilder('u')
                -&gt;where('u.site = :site')
                -&gt;setParameter('site', $site)
                -&gt;orderBy('u.sort', 'DESC')
                -&gt;getQuery()
                -&gt;getResult();
        $result2 = array_rand($results);
        return $result2;
    }
</pre>
<p>In this case you fetch all rows from your table, this could be slow and memory consuming&#8230;</p>
<p>If you need to retrieve only one row, you can use somethinfg like this</p>
<pre class="brush: php; title: ; notranslate">
 public function getOneRandom()
{
$em = $this-&gt;getEntityManager();
$max = $em-&gt;createQuery('
SELECT MAX(q.id) FROM questions q
')
-&gt;getSingleScalarResult();
return $em-&gt;createQuery('
SELECT q FROM questions q
WHERE q.id &gt;= :random
ORDER BY q.id ASC
')
-&gt;setParameter('random',rand(0,$max))
-&gt;setMaxResults(1)
-&gt;getSingleResult();
}
</pre>
<p>This solution can only be used if you want to retrieve any of the tables rows, if you add a filtrer you may return an empty result.</p>
<p>This solution is not dirty it just use 2 queries instead of one. the tips is to use the offset. And you can use a filter !!!</p>
<pre class="brush: php; title: ; notranslate">
$qCount = Doctrine::getTable('Questions')
     -&gt;createQuery()
     -&gt;select('count(*)')
     -&gt;where('site = :site')
     -&gt;setParameter('site', $site)
     -&gt;fetchOne(array(), Doctrine::HYDRATE_NONE);
$question = Doctrine::getTable('Questions')
     -&gt;createQuery()
     -&gt;select('*')
     -&gt;where('site = :site')
     -&gt;setParameter('site', $site)
     -&gt;limit(1)
     -&gt;offset(rand(0, $qCount[0] - 1))
     -&gt;fetchOne();
</pre>
<p>And you still can use native queries : http://docs.doctrine-project.org/en/latest/reference/native-sql.html</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-03-06/doctrine2-random/">doctrine2 random</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2014-03-06/doctrine2-random/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fatal error : Declaration of {{path}}::validate() must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate()</title>
		<link>http://blog.adin.pro/2013-10-08/fatal-error-declaration-of-pathvalidate-must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate/</link>
		<comments>http://blog.adin.pro/2013-10-08/fatal-error-declaration-of-pathvalidate-must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate/#comments</comments>
		<pubDate>Tue, 08 Oct 2013 20:01:30 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Sonata]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Symfony2]]></category>
		<category><![CDATA[validator]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=311</guid>
		<description><![CDATA[<p>You are trying to setup a custom validator on Sonata and you get this error : Fatal error: Declaration of Adin\AdminBundle\Admin\AnnonceAdmin::validate() must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate() in /home/www/arlogis/src/Adin/AdminBundle/Admin/AnnonceAdmin.php on line 250 Don&#8217;t panic, just add this at the &#8230; <a href="http://blog.adin.pro/2013-10-08/fatal-error-declaration-of-pathvalidate-must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-08/fatal-error-declaration-of-pathvalidate-must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate/">Fatal error : Declaration of {{path}}::validate() must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate()</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>You are trying to setup a custom validator on Sonata and you get this error :</p>
<p>Fatal error: Declaration of Adin\AdminBundle\Admin\AnnonceAdmin::validate() must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate() in /home/www/arlogis/src/Adin/AdminBundle/Admin/AnnonceAdmin.php on line 250 </p>
<p>Don&#8217;t panic, just add this at the begining of your class</p>
<pre class="brush: php; title: ; notranslate">
use Sonata\AdminBundle\Validator\ErrorElement;
</pre>
<p>in our example it&#8217;s in this file  : /AdminBundle/Admin/AnnonceAdmin.php</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-08/fatal-error-declaration-of-pathvalidate-must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate/">Fatal error : Declaration of {{path}}::validate() must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate()</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-10-08/fatal-error-declaration-of-pathvalidate-must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doctrine2 override save method</title>
		<link>http://blog.adin.pro/2013-10-08/doctrine2-override-save-method/</link>
		<comments>http://blog.adin.pro/2013-10-08/doctrine2-override-save-method/#comments</comments>
		<pubDate>Tue, 08 Oct 2013 19:51:44 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctrine2]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Sonata]]></category>
		<category><![CDATA[Symfony2]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=308</guid>
		<description><![CDATA[<p>With Doctrine2 you cannot override save method but you can execute preUpdate() method. See below how to implement it. On your entity class, for example AdminBundle/Entity/Annonce.php, add the HasLifecycleCallbacks annontation And your method, with the annotation That&#8217;s all, it should &#8230; <a href="http://blog.adin.pro/2013-10-08/doctrine2-override-save-method/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-08/doctrine2-override-save-method/">Doctrine2 override save method</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>With Doctrine2 you cannot override save method but you can execute preUpdate() method.<br />
See below how to implement it.</p>
<p>On your entity class, for example AdminBundle/Entity/Annonce.php, add the HasLifecycleCallbacks annontation</p>
<pre class="brush: php; title: ; notranslate">
/**
 * @ORM\Entity(repositoryClass=&quot;Tripix\AdminBundle\Repository\AnnonceRepository&quot;)
 * @ORM\HasLifecycleCallbacks
 */
</pre>
<p>And your method, with the annotation</p>
<pre class="brush: php; title: ; notranslate">
/** @ORM\PreUpdate() */
        public function preUpdate()
        {
                $this-&gt;created_at = new \DateTime(&quot;now&quot;);
        }
</pre>
<p>That&#8217;s all, it should works.</p>
<p>A complete example, just in case :</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
namespace Tripix\AdminBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;


/**
 * @ORM\Entity(repositoryClass=&quot;Tripix\AdminBundle\Repository\AnnonceRepository&quot;)
 * @ORM\HasLifecycleCallbacks
 */
class Annonce
{

/** @ORM\PreUpdate() */
        public function preUpdate()
        {
                $this-&gt;created_at = new \DateTime(&quot;now&quot;);
        }

    public function __construct()
    {
        $this-&gt;created_at = new \DateTime(&quot;now&quot;);
        $this-&gt;visuels = new ArrayCollection();
    }

</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-08/doctrine2-override-save-method/">Doctrine2 override save method</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-10-08/doctrine2-override-save-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony2 sonata custom CRUD template</title>
		<link>http://blog.adin.pro/2013-10-07/symfony2-sonata-custom-crud-template/</link>
		<comments>http://blog.adin.pro/2013-10-07/symfony2-sonata-custom-crud-template/#comments</comments>
		<pubDate>Mon, 07 Oct 2013 14:10:57 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Sonata]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Twig]]></category>
		<category><![CDATA[Override]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony2]]></category>
		<category><![CDATA[twig]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=306</guid>
		<description><![CDATA[<p>It is possible to change templates use by default. First, override the controller action method, in your AdminBundle/Controller/SecteurAdminController.php file The import thing on previous code is the render() fonction, the first parameter is the template to use. In our example, &#8230; <a href="http://blog.adin.pro/2013-10-07/symfony2-sonata-custom-crud-template/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-07/symfony2-sonata-custom-crud-template/">Symfony2 sonata custom CRUD template</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>It is possible to change templates use by default.</p>
<p>First, override the controller action method, in your AdminBundle/Controller/SecteurAdminController.php file</p>
<pre class="brush: php; title: ; notranslate">
 /**
     * return the Response object associated to the list action
     *
     * @return Response
     */
    public function listAction()
    {
        if (false === $this-&gt;admin-&gt;isGranted('LIST')) {
            throw new AccessDeniedException();
        }

        $datagrid = $this-&gt;admin-&gt;getDatagrid();
        $formView = $datagrid-&gt;getForm()-&gt;createView();

        // set the theme for the current Admin Form
        $this-&gt;get('twig')-&gt;getExtension('form')-&gt;setTheme($formView, $this-&gt;admin-&gt;getFilterTheme());

        //custom code from here
        $total = 0;
        $enable = 0;
        $new = 0;
        $site = $this-&gt;admin-&gt;site;

        $repository = $this-&gt;getDoctrine()-&gt;getRepository('TripixAdminBundle:Annonce');
        $total = $repository-&gt;getNombreAnnonceTotal($site);
        $enable = $repository-&gt;getNombreAnnonceEnabled($site);
        $new = $repository-&gt;getNombreAnnonceNew($site);



        return $this-&gt;render('TripixAdminBundle:CRUD:list_secteur.html.twig', array(
            'action'   =&gt; 'list',
            'form'     =&gt; $formView,
            'datagrid' =&gt; $datagrid,
            'total'     =&gt; $total,
            'enable'    =&gt; $enable,
            'new'       =&gt; $new,
        ));
    }
</pre>
<p>The import thing on previous code is the render() fonction, the first parameter is the template to use.<br />
In our example, the template file will be /AdminBundle/Ressources/view/CRUD/list_secteur.html.twig</p>
<p>You can use the /AdminBundle/Ressources/view/CRUD/base_secteur.html.twig file as example for your custom template.</p>
<p>Parent function to override on the controller are here : /vendor/bundles/Sonata/AdminBundle/Controller/CRUDController.php</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-07/symfony2-sonata-custom-crud-template/">Symfony2 sonata custom CRUD template</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-10-07/symfony2-sonata-custom-crud-template/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony2 Sonata add custom column on page list</title>
		<link>http://blog.adin.pro/2013-10-07/symfony2-sonata-add-custom-column-on-page-list/</link>
		<comments>http://blog.adin.pro/2013-10-07/symfony2-sonata-add-custom-column-on-page-list/#comments</comments>
		<pubDate>Mon, 07 Oct 2013 12:44:16 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Sonata]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony2]]></category>
		<category><![CDATA[twig]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=302</guid>
		<description><![CDATA[<p>To add a custom column on a page list, just follow these steps. In the example, we will add a &#8220;Nombre d&#8217;annoce(s)&#8221; column. On your admin class file (ex: /AdminBundle/Admin/SecteurAdmin.php), on your configureListFields() fonction, add a new entry on the &#8230; <a href="http://blog.adin.pro/2013-10-07/symfony2-sonata-add-custom-column-on-page-list/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-07/symfony2-sonata-add-custom-column-on-page-list/">Symfony2 Sonata add custom column on page list</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>To add a custom column on a page list, just follow these steps. In the example, we will add a &#8220;Nombre d&#8217;annoce(s)&#8221; column.</p>
<p>On your admin class file (ex: /AdminBundle/Admin/SecteurAdmin.php), on your configureListFields() fonction, add a new entry on the listMapper object</p>
<pre class="brush: php; title: ; notranslate">
    /**
     * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
     * @return void
     */
    protected function configureListFields(ListMapper $listMapper) {
        $listMapper
                -&gt;addIdentifier('titre')
                -&gt;add('Tri', 'string', array('template' =&gt; 'TripixAdminBundle:Admin:list_tri.html.twig'))
                -&gt;add('Nb', 'string', array('label' =&gt; 'Nombre d\'annonce(s)', 'template' =&gt; 'TripixAdminBundle:Admin:list_nb_annonce.html.twig'))
                -&gt;add('_action', 'actions', array(
                    'actions' =&gt; array(
                        'edit' =&gt; array(),
                        'delete' =&gt; array(),
                    )
                ))
        ;
    }
</pre>
<p>This new entry said to use the TripixADminBundle:Admin:list_tri.html.twig template.</p>
<p>Now, create your template file (list_nb_annonce.html) in the /AdminBundle/ressources/view/admin/ directory.</p>
<pre class="brush: php; title: ; notranslate">
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}

{% block field%}
{% if admin.datagrid.results|length &gt; 1 %}
 &lt;div&gt;
        &lt;strong&gt;{{ object.getNombreAnnonce}}&lt;/strong&gt;
    &lt;/div&gt;
{% endif %}
{% endblock %}
</pre>
<p>In our example, getNombreAnnonce() is not defined, let&#8217;s do it<br />
In the /adminBundle/Entity/Secteur.php file, add</p>
<pre class="brush: php; title: ; notranslate">
   public function getNombreAnnonce()
    {
      return count($this-&gt;getAnnonces());
    }
</pre>
<p>That&#8217;s all.</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-07/symfony2-sonata-add-custom-column-on-page-list/">Symfony2 Sonata add custom column on page list</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-10-07/symfony2-sonata-add-custom-column-on-page-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate() error message</title>
		<link>http://blog.adin.pro/2013-10-06/must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate-error-message/</link>
		<comments>http://blog.adin.pro/2013-10-06/must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate-error-message/#comments</comments>
		<pubDate>Sun, 06 Oct 2013 14:53:03 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Sonata]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Symfony2]]></category>
		<category><![CDATA[validator]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=299</guid>
		<description><![CDATA[<p>You are using sonata and want to validate some fields. You innocently add the validate function to your Admin file Then, you get this error : You checked to AdminInterface file the declaration is the same. To fix it, you &#8230; <a href="http://blog.adin.pro/2013-10-06/must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate-error-message/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-06/must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate-error-message/">must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate() error message</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>You are using sonata and want to validate some fields.<br />
You innocently add the validate function to your Admin file</p>
<pre class="brush: php; title: ; notranslate">
function validate(ErrorElement $errorElement, $object)
{
}
</pre>
<p>Then, you get this error :</p>
<pre class="brush: bash; title: ; notranslate">
Fatal error: Declaration of Adin\AdminBundle\Admin\AnnonceAdmin::validate() must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate() in /home/www/arlogis/src/Adin/AdminBundle/Admin/AnnonceAdmin.php on line 251 
</pre>
<p>You checked to AdminInterface file the declaration is the same.</p>
<p>To fix it, you need to use additionnal namespace :</p>
<pre class="brush: php; title: ; notranslate">
use Sonata\AdminBundle\Validator\ErrorElement;
use Symfony\Component\Validator\ValidatorInterface;
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-06/must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate-error-message/">must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate() error message</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-10-06/must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate-error-message/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony 1.2 propel &amp; transaction</title>
		<link>http://blog.adin.pro/2013-08-13/symfony-1-2-propel-transaction/</link>
		<comments>http://blog.adin.pro/2013-08-13/symfony-1-2-propel-transaction/#comments</comments>
		<pubDate>Tue, 13 Aug 2013 07:00:58 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Propel]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[transaction]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=283</guid>
		<description><![CDATA[<p>Using transactions could be really usefull and it is really easy to use so you have no excuse to not use them :</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-08-13/symfony-1-2-propel-transaction/">Symfony 1.2 propel &#038; transaction</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Using transactions could be really usefull and it is really easy to use so you have no excuse to not use them :</p>
<pre class="brush: php; title: ; notranslate">
$con = Propel::getConnection(); //get propel connection
$con-&gt;beginTransaction();   //start transaction
//do stuff
$con-&gt;commit(); //commit transaction
//or
$con-&gt;rollback(); //rollback
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-08-13/symfony-1-2-propel-transaction/">Symfony 1.2 propel &#038; transaction</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-08-13/symfony-1-2-propel-transaction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony validator custom error message</title>
		<link>http://blog.adin.pro/2013-05-13/symfony-validator-custom-error-message/</link>
		<comments>http://blog.adin.pro/2013-05-13/symfony-validator-custom-error-message/#comments</comments>
		<pubDate>Mon, 13 May 2013 07:55:21 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[validator]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=195</guid>
		<description><![CDATA[<p>If you need to customize your validator error messages, you can use the setMessage() function. On your Form class (ex: /lib/form/doctrine/DemandeForm.class.php)</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-05-13/symfony-validator-custom-error-message/">Symfony validator custom error message</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>If you need to customize your validator error messages, you can use the setMessage() function.<br />
On your Form class (ex: /lib/form/doctrine/DemandeForm.class.php)</p>
<pre class="brush: php; title: ; notranslate">
//sfValidatorInteger
$this-&gt;validatorSchema['produit_ean']-&gt;setMessage('invalid', 'ean should be integer');
$this-&gt;validatorSchema['produit_ean']-&gt;setMessage('min', 'ean must be at least %min%');
$this-&gt;validatorSchema['produit_ean']-&gt;setMessage('max', 'ean must be at least %max%');

//sfValidatorDate
$this-&gt;validatorSchema['date']-&gt;setMessage('bad_format', 'Format must be dd/mm/YYYY');
$this-&gt;validatorSchema['date']-&gt;setMessage('max', 'Date should be after than 01/01/2013');
$this-&gt;validatorSchema['date']-&gt;setMessage('min', 'Date should be before than 01/02/2013');

//required
$this-&gt;validatorSchema['date']-&gt;setMessage('required', 'Date is mandatory');

</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-05-13/symfony-validator-custom-error-message/">Symfony validator custom error message</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-05-13/symfony-validator-custom-error-message/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony2 twig add new function file_exists</title>
		<link>http://blog.adin.pro/2013-05-10/symfony2-twig-add-new-function-file_exists/</link>
		<comments>http://blog.adin.pro/2013-05-10/symfony2-twig-add-new-function-file_exists/#comments</comments>
		<pubDate>Fri, 10 May 2013 07:43:52 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Twig]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony2]]></category>
		<category><![CDATA[twig]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=184</guid>
		<description><![CDATA[<p>An important function is missing on twig : file_exists. I will show you here how to define a new function for twig. On your namespace/bundle, add a Twig/Extension directory and create your class file : /src/Adin/ArlogisBundle/Twig/Extension/FileExistsExtension.php You then have to &#8230; <a href="http://blog.adin.pro/2013-05-10/symfony2-twig-add-new-function-file_exists/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-05-10/symfony2-twig-add-new-function-file_exists/">Symfony2 twig add new function file_exists</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>An important function is missing on twig : file_exists.</p>
<p>I will show you here how to define a new function for twig.</p>
<p>On your namespace/bundle, add a Twig/Extension directory and create your class file :<br />
/src/Adin/ArlogisBundle/Twig/Extension/FileExistsExtension.php</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace Adin\ArlogisBundle\Twig\Extension;

class FileExistsExtension extends \twig_Extension
{
        /**
         *Return the function registered as twig extension
         *
         *@return array
         */
        public function getFunctions()
        {
                return array(
                        'file_exists' =&gt; new \Twig_Function_Function('file_exists'),
                        );
        }

        public function getName()
        {
                return 'adin_file_exists';
        }
}
?&gt;
</pre>
<p>You then have to register your service, add a <service> in your /Adin/ArlogisBundle/Ressources/config/services.xml file</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; ?&gt;

&lt;container xmlns=&quot;http://symfony.com/schema/dic/services&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    xsi:schemaLocation=&quot;http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd&quot;&gt;
&lt;services&gt;
       &lt;service id=&quot;adin.twig.tripix_extension&quot; class=&quot;Adin\ArlogisBundle\Twig\Extension\FileExistsExtension&quot;&gt;
        &lt;tag name=&quot;twig.extension&quot; /&gt;
        &lt;/service&gt;
    &lt;/services&gt;
&lt;/container&gt;
</pre>
<p>It&#8217;s ready, you can use it on your twig template</p>
<pre class="brush: php; title: ; notranslate">
{% if file_exists('/var/www/image.jpg') %}
    File exists
{% else %}
    File not exists
{% endif %}
</pre>
<p>Be carefull, you need to specify the absolute path of the file. You can create a twig global variable root_path.<br />
app/config/config.yml</p>
<pre class="brush: php; title: ; notranslate">
# Twig Configuration
twig:
    globals:
        root_path: %kernel.root_dir%/../web
</pre>
<p>Then on twig template</p>
<pre class="brush: php; title: ; notranslate">
{% if file_exists({{root_path}}'/var/www/image.jpg') %}
    File exists
{% else %}
    File not exists
{% endif %}
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-05-10/symfony2-twig-add-new-function-file_exists/">Symfony2 twig add new function file_exists</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-05-10/symfony2-twig-add-new-function-file_exists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
