Thursday, February 23, 2012

Symfony Build: Fatal error: Allowed memory size of x bytes exhausted

If you run a symfony command, it is run by php cli, not apache.
So increase the memory_limit to 128M in the /etc/php5/cli/php.ini file. Building will work fine.:)

Create Plugin in Symfony

  1. Install: sfTaskExtraPlugin
  2. Generate a plugin (example): symfony generate:plugin sfPaypalPlugin
  3. Generate a module (paypal) in a plugin (sfPaypalPlugin): symfony generate:plugin-module sfPaypalPlugin paypal

Wednesday, February 22, 2012

Allow Website from Fix IPs in Apache

Add this to the directory configuration in virtualhost:

Order Deny, Allow
Deny from All
Allow from 10.0.0.

Disable Apache Server Signature

Add ServerSignature Off to virtualhost configuration. Restart Apache.

Remove Accents in String with ICONV

Don't forget: Iconv translit is locale sensitive. You must first set locale:
// remove hungarian accents
// magyar ékezetek eltávolítása
setlocale(LC_ALL, 'hu_HU.UTF8');
$text = iconv('UTF-8', 'ASCII//TRANSLIT', 'árvíztűrő tükörfúrógép');
echo $text = str_replace(array('\'', '"', ':'), array(), $text);

url_for Helper in Action in Symfony

// now you can use url_for()

Tuesday, February 21, 2012

Install Symfony Plugin: Warning: require_once(PEAR.php): failed to open stream

  1. If you try to install a plugin (ex. prestaPaypalPlugin) with symfony cli and get something like this...
    sakra:/var/www/sakra# ./symfony plugin:install prestaPaypalPlugin
    >> plugin    installing plugin "prestaPaypalPlugin"
    Warning: require_once(PEAR.php): failed to open stream: No such file or directory in mnt/vol1/vol1/www/sakra/lib/vendor/symfony/lib/plugin/sfPearEnvironment.class.php on line 15
    Fatal error: require_once(): Failed opening required 'PEAR.php' (include_path='.:/usr/share/php:/usr/share/pear') in /mnt/vol1/vol1/www/sakra/lib/vendor/symfony/lib/plugin/sfPearEnvironment.class.php on line 15
  2. Run: apt-get update
  3. Run: apt-get install php-pear
  4. Run again: ./symfony plugin:install prestaPaypalPlugin
  5. If you get an error like this...
    No release available for plugin "prestaPaypalPlugin" in state "stable"
  6. Run with -s parameter (to enable beta plugins): ./symfony plugin:install -s beta prestaPaypalPlugin

Parse YML (Yaml) Files In Action in Symfony

$myarray = sfYaml::load(sfConfig::get('sf_config_dir').'/myconf.yml');

Monday, February 20, 2012

Disable Symfony Application for Maintenance

  1. Put check_lock: true inside the (ex.) prod section of apps/frontend/config/settings.yml.
  2. Create an unavailable.php file in the root config dir (project folder/config).
  3. Clear the cache (symfony cc).
  4. Run symfony project:disable frontend prod to disable the prod environment of the frontend application. To enable, just change the disable word to enable.

Wednesday, February 8, 2012

Format Date Based On User Culture in Action in Symfony

$user_culture = $this->getUser()->getCulture();
$formatdate = new sfDateFormat($user_culture);
echo $formatdate->format(strtotime('2012-02-08'), 'd'); // 'd' is a pattern