can any1 help me:
here’s my modal :
<?php
/**
*/
class Career extends CActiveRecord
{
public $Name;
public $City;
public $Email;
public $Phone;
public $Qualification;
public $Skills;
public $Resume;
/**
* Returns the static model of the specified AR class.
* @return Career the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'tbl_career';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('Name, City, Email, Phone, Qualification, Skills, Resume', 'required'),
array('Phone', 'numerical', 'integerOnly'=>true),
array('Name', 'length', 'max'=>50),
array('City', 'length', 'max'=>20),
array('Email', 'length', 'max'=>30),
array('Resume', 'length', 'max'=>100),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, Name, City, Email, Phone, Qualification, Skills, Resume', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'Name' => 'Name',
'City' => 'City',
'Email' => 'Email',
'Phone' => 'Phone',
'Qualification' => 'Qualification',
'Skills' => 'Skills',
'Resume' => 'Resume',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('Name',$this->Name,true);
$criteria->compare('City',$this->City,true);
$criteria->compare('Email',$this->Email,true);
$criteria->compare('Phone',$this->Phone);
$criteria->compare('Qualification',$this->Qualification,true);
$criteria->compare('Skills',$this->Skills,true);
$criteria->compare('Resume',$this->Resume,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
public function save($runValidation=false,$attributes=null)
{
if(!$runValidation || $this->validate($attributes))
return $this->getIsNewRecord() ? $this->insert($attributes) : $this->update($attributes);
else
return false;
}
}
controller : :
// Displays the Career page
public function actionCareer()
{
$model=new Career;
if(isset($_POST['ajax']) && $_POST['ajax']==='career-career-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
if(isset($_POST['Career']))
{
$model->attributes=$_POST['Career'];
if($model->validate())
{
$career=new career;
$career->id = "";
$career->name="";
$career->city="";
$career->email = "";
$career->phone = "";
$career->qualifications = "";
$career->skills = "";
$career->resume = "";
if ($career->validate()){
$model->save(false);
$career->save(); //this does not save into db and return false
}
/* My hack method that works
$sql = 'INSERT INTO {{profiles}} (id,u_id,lastname,firstname,date_of_birth,about) VALUES ("",:u_id,"","","","")';
$parameters = array(":u_id"=>$model->id);
Yii::app()->db->createCommand($sql)->execute($parameters);
*/
$this->redirect(Yii::app()->homeUrl);
}
}
$this->render('career',array('model'=>$model));
}
view : :
<div class="form">
<?php $form=$this->beginWidget(‘CActiveForm’, array(
'id'=>'career-career-form',
'enableAjaxValidation'=>true,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'Name'); ?>
<?php echo $form->textField($model,'Name'); ?>
<?php echo $form->error($model,'Name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'City'); ?>
<?php echo $form->textField($model,'City'); ?>
<?php echo $form->error($model,'City'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Email'); ?>
<?php echo $form->textField($model,'Email'); ?>
<?php echo $form->error($model,'Email'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Phone'); ?>
<?php echo $form->textField($model,'Phone'); ?>
<?php echo $form->error($model,'Phone'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Qualification'); ?>
<?php echo $form->textField($model,'Qualification'); ?>
<?php echo $form->error($model,'Qualification'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Skills'); ?>
<?php echo $form->textField($model,'Skills'); ?>
<?php echo $form->error($model,'Skills'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Resume'); ?>
<?php echo $form->textField($model,'Resume'); ?>
<?php echo $form->error($model,'Resume'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php $this->endWidget(); ?>