Friday, September 14, 2012

ob_start: PHP Output To Variable / String

<?php ob_start(); ?>
Hello world, <?php echo "My Website"; ?>
<?php include('something.php') ?>
Thank you.
<?php $var = ob_get_clean(); ?>

Friday, September 7, 2012

The user specified as a definer ('root'@'%') does not exist

Solution:
mysql -u root -p
grant all privileges on *.* to `root`@`%` identified by 'password';
flush privileges;

Install Apache 2, PHP 5, MySQL 5 on Debian

apt-get update

apt-get install apache2
apt-get install php5
apt-get install libapache2-mod-php5
apt-get install mysql-server mysql-client mysql-common php5-mysql
apt-get install php5-xsl php5-gd php5-curl

Install the Latest APC on Debian
Install PHPMYADMIN on Debian

Install PHPMYADMIN on Debian

1. Download the latest PHPMYADMIN.
2. Put here: /usr/share/phpmyadmin
3. Create phpmyadmin.conf in /etc/apache2/conf.d :
Alias /phpmyadmin /usr/share/phpmyadmin


        Options Indexes FollowSymLinks
        DirectoryIndex index.php

4. /etc/init.d/apache2 restart

Thursday, September 6, 2012

How to Save Empty Form Fields as NULL in Symfony

If you leave a field empty in your form, Symfony will save it as a blank value. However sometimes you want to save it as NULL...

Create a method for the field in the form class:
  public function updateManufacturerColumn($value)
  {
    return (!$value) ? null : $value;
  }
Manufacturer is the name of the field now.

Post Validator in Symfony

  public function configure()
  {
    $this->getValidator('day')->setOption('required', 'true');
    
    $this->validatorSchema->setPostValidator(new sfValidatorAnd(array(
      new sfValidatorCallback(array('callback' => array($this, 'checkFields'))),
    )));
  }
  
  public function checkFields($validator, $values)
  {
    if(empty($values['manufacturer']) && empty($values['category_apollo_kod']) && empty($values['product_apollo_kod']))
    {
      throw new sfValidatorErrorSchema($validator, array('manufacturer' => new sfValidatorError($validator, 'custom error')));
    }
     
    return $values;
  }

Wednesday, August 22, 2012

Debian: Install NTPD To Synchronism Clock With Internet Standard Time Servers

date
apt-get install ntp
(wait....)
date
(works like a charm)