My Docs Controller file
<?php
class DocsController extends Controller
{
/**
* @var string the default layout for the views. Defaults to '//layouts/column2', meaning
* using two-column layout. See 'protected/views/layouts/column2.php'.
*/
public $layout='//layouts/column2';
/**
* @var CActiveRecord the currently loaded data model instance.
*/
private $_model;
/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
/**
* Displays a particular model.
*/
public function actionView()
{
$this->render('view',array(
'model'=>$this->loadModel(),
));
}
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new Docs;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Docs']))
{
$model->attributes=$_POST['Docs'];
$model->image = CUploadedFile::getInstance($model, 'image');
if($model->save())
//$model->filename->saveAs('../../pics/.jpg');
$this->redirect(array('view','id'=>$model->docsid));
$model->filename->saveAs('/tmp/uploads/');
}
$this->render('create',array('model'=>$model));
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
*/
public function actionUpdate()
{
$model=$this->loadModel();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Docs']))
{
$model->attributes=$_POST['Docs'];
if($model->save())
$this->redirect(array('view','id'=>$model->docsid));
}
$this->render('update',array(
'model'=>$model,
));
}
/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'index' page.
*/
public function actionDelete()
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadModel()->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
/**
* Lists all models.
*/
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Docs');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
/**
* Manages all models.
*/
public function actionAdmin()
{
$model=new Docs('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Docs']))
$model->attributes=$_GET['Docs'];
$this->render('admin',array(
'model'=>$model,
));
}
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
*/
public function loadModel()
{
if($this->_model===null)
{
if(isset($_GET['id']))
$this->_model=Docs::model()->findByPk($_GET['id']);
if($this->_model===null)
throw new CHttpException(404,'The requested page does not exist.');
}
return $this->_model;
}
/**
* Performs the AJAX validation.
* @param CModel the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='docs-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}
My Model file Docs.php
<?php
/**
* This is the model class for table "{{docs}}".
*
* The followings are the available columns in table '{{docs}}':
* @property string $document_name
* @property string $document_author
* @property string $document_title
* @property string $document_desc
* @property integer $docsid
*/
class Docs extends CActiveRecord
{
public $image;
/**
* Returns the static model of the specified AR class.
* @return Docs 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 '{{docs}}';
}
/**
* @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('document_name, document_author, document_title, document_desc', 'required'),
array('document_name, document_author, document_title, document_desc', 'length', 'max'=>255),
array('image', 'file', 'types'=>'jpg,jpeg,gif,png', 'maxSize'=>30720),
array('image', 'required'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('document_name, document_author, document_title, document_desc, docsid', '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(
'document_name' => 'Document Name',
'document_author' => 'Document Author',
'document_title' => 'Document Title',
'document_desc' => 'Document Desc',
'docsid' => 'Docsid',
);
}
/**
* 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('document_name',$this->document_name,true);
$criteria->compare('document_author',$this->document_author,true);
$criteria->compare('document_title',$this->document_title,true);
$criteria->compare('document_desc',$this->document_desc,true);
$criteria->compare('docsid',$this->docsid);
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
}
}
My site view file docs/_form.php
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'docs-form',
'enableAjaxValidation'=>false,
)); ?>
<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,'document_name'); ?>
<?php echo $form->textField($model,'document_name',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'document_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'document_author'); ?>
<?php echo $form->textField($model,'document_author',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'document_author'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'document_title'); ?>
<?php echo $form->textField($model,'document_title',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'document_title'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'document_desc'); ?>
<?php echo $form->textField($model,'document_desc',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'document_desc'); ?>
</div>
<div class="row">
<?php echo CHtml::form('','post',array('enctype'=>'multipart/form-data')); ?>
<?php echo CHtml::activeLabel($model,'image'); ?>
<?php echo CHtml::activeFileField($model, 'image'); ?>
<?php echo CHtml::submitButton('UPLOAD'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
i m getting following error
CException
Description
Property "Docs.filename" is not defined.
In advance thank you for your help guys. YII rocksss