$this->fields['email'] = new Field('email');
    }
    protected function before_save()
    {
        $this->validates_presence_of('name', 'address')->message('%s should be filled!');
        $this->validates_length_of('name')->in(1, 5)->too_short('Too short: %s [min: %d]')->too_long('Too long: %s, [max: %d]');
        $this->validates_length_of('address')->max(5)->too_long('%s is too long, maximum is %d charachters');
        $this->validates_numericality_of('phone');
        $this->validates_format_of('email')->with('/^([^@\\s]+)@((?:[-a-z0-9]+\\.)+[a-z]{2,})$/i');
        return true;
    }
}
class ActiveRecordHelper extends Object
{
    public static function error_messages_for(ActiveRecord $record)
    {
        foreach ($record->getFields() as $field) {
            foreach ($field->getErrors() as $error) {
                echo $error . "\n";
            }
        }
    }
}
$p = new Person();
$p->email = 'F';
$p->phone = 'a';
$p->name = 'Marel';
$p->address = 'Andro';
var_dump($p->save());
ActiveRecordHelper::error_messages_for($p);
 /**
  * @todo Implement testAll_input_tags().
  */
 public function testAll_input_tags()
 {
     $ar = new ActionController();
     $GLOBALS['current_controller_object'] = $ar;
     $dt = new DataType();
     $ar->DataType = $dt;
     $arh = new ActiveRecordHelper();
     $arh->scaffolding = true;
     echo "calling all_input_tags()\n";
     echo $arh->all_input_tags($dt, 'DataType', array());
     // Remove the following line when you implement this test.
     throw new PHPUnit2_Framework_IncompleteTestError();
 }
Example #3
0
 /**
  * Retrieves a list of models based on the current search/filter conditions.
  * Typical usecase:
  * - Initialize the model fields with values from filter form.
  * - Execute this method to get CActiveDataProvider instance which will filter
  * models according to data in model fields.
  * - Pass data provider to CGridView, CListView or any similar widget.
  * @return CActiveDataProvider the data provider that can return the models
  * based on the search/filter conditions.
  */
 public function search()
 {
     $criteria = new CDbCriteria();
     $criteria->compare('name', $this->name, true);
     // Filtre sur le nombre de news associƩes
     $filterCriteria = ActiveRecordHelper::addFilterOnAggregatedNumericColumn($this, 'countNews', 'news', 'news', 'category_id', '', false);
     $criteria->mergeWith($filterCriteria);
     return new CActiveDataProvider($this, array('criteria' => $criteria));
 }