CREATE TABLE IF NOT EXISTS `material` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `cid` int(10) unsigned NOT NULL,
  `uid` int(10) unsigned NOT NULL,
  `title` varchar(64) NOT NULL,
  `url` varchar(64) NOT NULL,
  `preview` text NOT NULL,
  `content` text NOT NULL,
  `date_add` datetime NOT NULL,
  `date_change` datetime DEFAULT NULL,
  `user_change` int(10) unsigned DEFAULT NULL,
  `public` enum('N','Y') NOT NULL DEFAULT 'N',
  `moderated` enum('N','Y') NOT NULL DEFAULT 'N',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;


<?php

class Material extends CActiveRecord
{

 public static function model($className=__CLASS__)
 {
  return parent::model($className);
 }
    
 public function tableName()
 {
  return 'material';
 }

 public function rules()
 {
        return array(
            array('cid, title, preview, content', 'required'),
            array('id, cid, uid, title, url, preview, content, date_add, date_change, user_change, public, moderated', 'safe'),
        );
 }
    
    public function attributeLabels()
    {
        return array(
            'cid' => 'Cat',
        );
    }
    
    protected function beforeValidate()
    {
        $this->id = 1;
        $this->cid = 1;
        $this->uid = 1;
        $this->title = 'asdfsadf';
        $this->url = 'adddsadf';
        $this->preview = 'sadfsadf';
        $this->content = 'dfsdfsdsadfsadf';
        $this->date_add = date('Y-m-d H:i:s');
        $this->date_change = date('Y-m-d H:i:s');
        $this->user_change = 1;
        $this->public = 'N';
        $this->moderated = 'N';
        
        print_r($this->attributes);
        
        parent::beforeValidate();
        
        return;
        
    }
    
    protected function beforeSave()
    {
        echo 'validate successful';
        parent::beforeSave();
    }
    
}

Add a code snippet to your website: www.paste.org