Archive for August, 2009

Custom Scaffolding Theme (Symfony)

Copy the default theme from

[sfPropelPlugin]data/generator/sfPropelCrud/default/theme

to

data/generator/sfPropelCrud/default/theme

Edit the files in data/generator/sfPropelCrud/default/theme/templates as you would with an admin template.

Generate like usual: ./symfony propel:generate-crud [app] [module] [base]

Derived from: http://www.playingwithwire.com/2007/02/review-of-the-definitive-guide-to-symfony/

PHP UUID generator function

Via: http://www.ajaxray.com/blog/2008/02/06/php-uuid-generator-function/

/**
  * Generates an UUID
  *
  * @author     Anis uddin Ahmad
  * @param      string  an optional prefix
  * @return     string  the formatted uuid
  */
  function uuid($prefix = ”)
  {
    $chars = md5(uniqid(rand()));
    $uuid  = substr($chars,0,8) . '-';
    $uuid .= substr($chars,8,4) . '-';
    $uuid .= substr($chars,12,4) . '-';
    $uuid .= substr($chars,16,4) . '-';
    $uuid .= substr($chars,20,12);

    return $prefix . $uuid;
  }

Force A Secure Page Using PHP

Via: http://php.dzone.com/news/force-secure-page-using-php

//force redirect to secure page
if($_SERVER['SERVER_PORT'] != '443') { header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); exit(); }

Setup PHP5 on Media Temple DV 3

  1. These changes must be made on a per domain basis. Log into Plesk and enter the setup area for the domain that you would like to enable php5. Under ‘Services’ make sure that:
    • PHP support is checked, safe_mode ‘on’ is unchecked
    • CGI support is checked
    • FastCGI support is checked
  2. SSH into your server as ‘root’ and execute these commands one at a time:
        cp /opt/php51/cgi-bin/php5 /var/www/vhosts/<domain>/bin/
        cd /var/www/vhosts/<domain>/
        chown -R <domain-user>:psacln bin/
        cd conf
        vim vhost.conf

    Remember to replace <domain> with your actual domain name and <domain-user> with the ftp username for that domain. These commands: make a copy of the CGI version of php5 and place it in the ‘bin’ directory of the domain, change the owner of the ‘bin’ directory and the copy of php5 to the same as the domain user and create a vhost.conf file in the conf directory.

  3. Add these lines to the vhost.conf file that you are editing with ‘vim’:
    AddHandler fcgid-script .php .php5
    SuexecUserGroup <domain-user> psacln
    <Directory /var/www/vhosts/<domain>/httpdocs>
         FCGIWrapper /var/www/vhosts/<domain>/bin/php5 .php
         FCGIWrapper /var/www/vhosts/<domain>/bin/php5 .php5
         Options ExecCGI +Indexes +FollowSymLinks
         allow from all
    </Directory>

    Again please remember to make the correct substitutions for <domain> and <domain-user>.

  4. Execute this command to reconfigure your server to use the new vhost.conf file:
        /usr/local/psa/admin/sbin/websrvmng -a -v

    This will automatically restart your webserver.

Remove .svn Folders from Project

Navigate to the root of the projects, and execute the following command:

find . -name '.svn' -exec 'rm -rf' {} \;

NOTE: You can also used “svn export source destination”