<?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; PHP</title>
	<atom:link href="http://blog.adin.pro/tag/php/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>PHP define constants with arrays</title>
		<link>http://blog.adin.pro/2015-01-14/php-define-constants-with-arrays/</link>
		<comments>http://blog.adin.pro/2015-01-14/php-define-constants-with-arrays/#comments</comments>
		<pubDate>Wed, 14 Jan 2015 09:30:18 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[constant]]></category>
		<category><![CDATA[define]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=445</guid>
		<description><![CDATA[<p>You need to define a constant containing an array but the code below doesn&#8217;t work ? You get an error : To define an use a constant containing an array you can simply serialize it :</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2015-01-14/php-define-constants-with-arrays/">PHP define constants with arrays</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 need to define a constant containing an array but the code below doesn&#8217;t work ?</p>
<pre class="brush: php; title: ; notranslate">
define('FILTER_ECOLE', array('price, categorie, niveau'));
</pre>
<p>You get an error :</p>
<pre class="brush: php; title: ; notranslate">
Notice: Use of undefined constant FILTER_ECOLE - assumed 'FILTER_ECOLE'  in /home/www/adin/app/code/local/Adin/Catalog/Block/Nav/Catalog/Layer/View/Sidebar.php on line 50
</pre>
<p>To define an use a constant containing an array you can simply serialize it :</p>
<pre class="brush: php; title: ; notranslate">
#define
define('FILTER_ECOLE', serialize(array('price, categorie, niveau')));

#use
$filter = unserialize(FILTER_ECOLE);
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2015-01-14/php-define-constants-with-arrays/">PHP define constants with arrays</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-01-14/php-define-constants-with-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Use of undefined constant MCRYPT_BLOWFISH &#8211; assumed &#8216;MCRYPT_BLOWFISH</title>
		<link>http://blog.adin.pro/2014-08-07/php-use-of-undefined-constant-mcrypt_blowfish-assumed-mcrypt_blowfish/</link>
		<comments>http://blog.adin.pro/2014-08-07/php-use-of-undefined-constant-mcrypt_blowfish-assumed-mcrypt_blowfish/#comments</comments>
		<pubDate>Thu, 07 Aug 2014 12:45:43 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[apache2]]></category>
		<category><![CDATA[module]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=393</guid>
		<description><![CDATA[<p>While your coding session, you encounter this error : You think, easy, a module should be missing on my php So you install it : And restart apache. But it still doesn&#8217;t work. In phpinfo() it seems the module is &#8230; <a href="http://blog.adin.pro/2014-08-07/php-use-of-undefined-constant-mcrypt_blowfish-assumed-mcrypt_blowfish/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-08-07/php-use-of-undefined-constant-mcrypt_blowfish-assumed-mcrypt_blowfish/">PHP &#8211; Use of undefined constant MCRYPT_BLOWFISH &#8211; assumed &#8216;MCRYPT_BLOWFISH</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>While your coding session, you encounter this error :</p>
<pre class="brush: bash; title: ; notranslate">
Use of undefined constant MCRYPT_BLOWFISH - assumed 'MCRYPT_BLOWFISH
</pre>
<p>You think, easy, a module should be missing on my php<br />
So you install it :</p>
<pre class="brush: bash; title: ; notranslate">
sudo apt-get install php5-mcrypt
</pre>
<p>And restart apache.</p>
<p>But it still doesn&#8217;t work. In phpinfo() it seems the module is not installed.</p>
<p>In fact with the new version of PHP, you still need to activate the module</p>
<pre class="brush: bash; title: ; notranslate">
php5enmod -s apache2 mcrypt
</pre>
<p>The restart apache and the module should work.</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-08-07/php-use-of-undefined-constant-mcrypt_blowfish-assumed-mcrypt_blowfish/">PHP &#8211; Use of undefined constant MCRYPT_BLOWFISH &#8211; assumed &#8216;MCRYPT_BLOWFISH</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-08-07/php-use-of-undefined-constant-mcrypt_blowfish-assumed-mcrypt_blowfish/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>Using GnuPG with PHP</title>
		<link>http://blog.adin.pro/2014-02-10/using-gnupg-with-php/</link>
		<comments>http://blog.adin.pro/2014-02-10/using-gnupg-with-php/#comments</comments>
		<pubDate>Mon, 10 Feb 2014 16:05:17 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[GnuPG]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=355</guid>
		<description><![CDATA[<p>GnuPG is a great tool to encrypt texts and files and you can use it with PHP, only if you install it succesfully. First, you will get this error : Fatal error: Class &#8216;gnupg&#8217; not found in &#8230;. OK the &#8230; <a href="http://blog.adin.pro/2014-02-10/using-gnupg-with-php/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-02-10/using-gnupg-with-php/">Using GnuPG with PHP</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>GnuPG is a great tool to encrypt texts and files and you can use it with PHP, only if you install it succesfully.</p>
<p>First, you will get this error : Fatal error: Class &#8216;gnupg&#8217; not found in &#8230;.</p>
<p>OK the lib is not installed, do it with pecl</p>
<pre class="brush: bash; title: ; notranslate">
pecl install gnupg
</pre>
<p>But you will also have this error :</p>
<pre class="brush: bash; title: ; notranslate">
configure: error: Please reinstall the gpgme distribution
ERROR: `/tmp/pear/temp/gnupg/configure' failed
</pre>
<p>You need to install the libgpgme too !!!</p>
<pre class="brush: bash; title: ; notranslate">
apt-get install libgpgme11-dev
</pre>
<p>Now retry to install gnupg</p>
<pre class="brush: bash; title: ; notranslate">
pecl install gnupg
</pre>
<p>It should be OK.</p>
<p>Don&#8217;t forget to modify your php.ini file to load the extension</p>
<pre class="brush: bash; title: ; notranslate">
extension=gnupg.so
</pre>
<p>And of course, restart your apache web server</p>
<pre class="brush: bash; title: ; notranslate">
/etc/init.d/apache2 restart
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-02-10/using-gnupg-with-php/">Using GnuPG with PHP</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-02-10/using-gnupg-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP form limited to 1000 fields</title>
		<link>http://blog.adin.pro/2013-11-15/php-form-limited-to-1000-fields/</link>
		<comments>http://blog.adin.pro/2013-11-15/php-form-limited-to-1000-fields/#comments</comments>
		<pubDate>Fri, 15 Nov 2013 11:04:56 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[suhison]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=323</guid>
		<description><![CDATA[<p>Since PHP 5.3.9 form are limited to 1000 fields by default. To fix it, you can edit your php.ini file and modify this variable And don&#8217;t forget to restart apache. You can also edit it in your .htaccess file Change &#8230; <a href="http://blog.adin.pro/2013-11-15/php-form-limited-to-1000-fields/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-11-15/php-form-limited-to-1000-fields/">PHP form limited to 1000 fields</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>Since PHP 5.3.9 form are limited to 1000 fields by default.<br />
To fix it, you can edit your php.ini file and modify this variable</p>
<pre class="brush: bash; title: ; notranslate">
max_input_vars = 4000
</pre>
<p>And don&#8217;t forget to restart apache.</p>
<p>You can also edit it in your .htaccess file</p>
<pre class="brush: bash; title: ; notranslate">
 php_value max_input_vars 4000 
</pre>
<p>Change it directly in your php file with this</p>
<pre class="brush: bash; title: ; notranslate">
 ini_set('php_value max_input_vars', 4000); 
</pre>
<p>won&#8217;t work.</p>
<p>But change this varible may not fix your issue.<br />
If you have suhosin installed, you laso have to edit his configuration file (/etc/php5/apache2/conf.d/suhosin.ini)</p>
<pre class="brush: bash; title: ; notranslate">
suhosin.get.max_vars = 4000 
suhosin.post.max_vars = 4000 
suhosin.request.max_vars = 4000 
</pre>
<p>To check your suhison configuration, use phpinfo() or in your php script</p>
<pre class="brush: bash; title: ; notranslate">
echo ini_get('suhosin.post.max_vars');
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-11-15/php-form-limited-to-1000-fields/">PHP form limited to 1000 fields</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-11-15/php-form-limited-to-1000-fields/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP check email validity</title>
		<link>http://blog.adin.pro/2013-10-23/php-check-email-validity/</link>
		<comments>http://blog.adin.pro/2013-10-23/php-check-email-validity/#comments</comments>
		<pubDate>Wed, 23 Oct 2013 08:39:29 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[check]]></category>
		<category><![CDATA[email]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=316</guid>
		<description><![CDATA[<p>The easiest and safest way to check email address validity is to use the php embedded function filter_var() :</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-23/php-check-email-validity/">PHP check email validity</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>The easiest and safest way to check email address validity is to use the php embedded function filter_var() :</p>
<pre class="brush: php; title: ; notranslate">
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
  //invalid email
}
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-23/php-check-email-validity/">PHP check email validity</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-23/php-check-email-validity/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>
	</channel>
</rss>
