I’m trying to define CGridView colums but ‘value’ attribute is not working. I can’t define it at all without
getting rare error message. This structure was working with my other applications.
Here is the code:
admin.php(generated with Gii, then modificated)
<?php
$this->breadcrumbs=array(
'Invoices'=>array('index'),
'Manage',
);
$this->menu=array(
array('label'=>'List Invoice', 'url'=>array('index')),
array('label'=>'Create Invoice', 'url'=>array('create')),
);
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('invoice-grid', {
data: $(this).serialize()
});
return false;
});
");
?>
<h1>Manage Invoices</h1>
<p>
You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php
//$commandString = 'echo \'<a href="\'.Yii::app()->storage->getFilePath($data->pdfUrl).\'">Näytä PDF</a>';
$commandString = 'echo "aa"';//$data->pdfUrl';
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'invoice-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'idInvoice',
'idPerson',
array( //if this array is removed, everything works.
'header' => 'pdf',
'value' => '$data->pdfUrl' //THIS IS WHAT DOESN'T WORK
),
'state',
'reason',
'paid',
'uploadDate',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
Invoice.php (model)
<?php
/**
* This is the model class for table "invoice".
*/
class Invoice extends CActiveRecord
{
/**
* The followings are the available columns in table 'invoice':
* @var integer $idInvoice
* @var integer $idPerson
* @var string $pdfUrl
* @var string $state
* @var string $reason
* @var string $paid
* @var string $uploadDate
*/
/**
* Returns the static model of the specified AR class.
* @return Invoice 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 'invoice';
}
/**
* @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('idPerson', 'required'),
array('idPerson', 'numerical', 'integerOnly'=>true),
array('pdfUrl', 'length', 'max'=>64),
array('state', 'length', 'max'=>32),
array('reason', 'length', 'max'=>128),
array('paid, uploadDate', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('idInvoice, idPerson, pdfUrl, state, reason, paid, uploadDate', '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(
'idPerson0' => array(self::BELONGS_TO, 'Person', 'idPerson'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'idInvoice' => 'Id Invoice',
'idPerson' => 'Id Person',
'pdfUrl' => 'Pdf Url',
'state' => 'State',
'reason' => 'Reason',
'paid' => 'Paid',
'uploadDate' => 'Upload Date',
);
}
/**
* 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('idInvoice',$this->idInvoice);
$criteria->compare('idPerson',$this->idPerson);
$criteria->compare('pdfUrl',$this->pdfUrl,true);
$criteria->compare('state',$this->state,true);
$criteria->compare('reason',$this->reason,true);
$criteria->compare('paid',$this->paid,true);
$criteria->compare('uploadDate',$this->uploadDate,true);
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
}
}
This is error message:
CException
Description
Property "Invoice." is not defined.
Source File
C:\xampp\htdocs\laskut\framework\db\ar\CActiveRecord.php(107)
00095: */
00096: public function __get($name)
00097: {
00098: if(isset($this->_attributes[$name]))
00099: return $this->_attributes[$name];
00100: else if(isset($this->getMetaData()->columns[$name]))
00101: return null;
00102: else if(isset($this->_related[$name]))
00103: return $this->_related[$name];
00104: else if(isset($this->getMetaData()->relations[$name]))
00105: return $this->getRelated($name);
00106: else
00107: return parent::__get($name);
00108: }
00109:
00110: /**
00111: * PHP setter magic method.
00112: * This method is overridden so that AR attributes can be accessed like properties.
00113: * @param string property name
00114: * @param mixed property value
00115: */
00116: public function __set($name,$value)
00117: {
00118: if($this->setAttribute($name,$value)===false)
00119: {
Stack Trace
#0 C:\xampp\htdocs\laskut\framework\db\ar\CActiveRecord.php(107): CComponent->__get('')
#1 C:\xampp\htdocs\laskut\framework\web\helpers\CHtml.php(1692): CActiveRecord->__get('')
#2 C:\xampp\htdocs\laskut\framework\web\helpers\CHtml.php(1166): CHtml::activeInputField('text', Object(Invoice), false, Array)
#3 C:\xampp\htdocs\laskut\framework\zii\widgets\grid\CDataColumn.php(96): CHtml::activeTextField(Object(Invoice), NULL, Array)
#4 C:\xampp\htdocs\laskut\framework\zii\widgets\grid\CGridColumn.php(103): CDataColumn->renderFilterCellContent()
#5 C:\xampp\htdocs\laskut\framework\zii\widgets\grid\CGridView.php(380): CGridColumn->renderFilterCell()
#6 C:\xampp\htdocs\laskut\framework\zii\widgets\grid\CGridView.php(358): CGridView->renderFilter()
#7 C:\xampp\htdocs\laskut\framework\zii\widgets\grid\CGridView.php(331): CGridView->renderTableHeader()
#8 C:\xampp\htdocs\laskut\framework\zii\widgets\CBaseListView.php(152): CGridView->renderItems()
#9 [internal function]: CBaseListView->renderSection(Array)
#10 C:\xampp\htdocs\laskut\framework\zii\widgets\CBaseListView.php(135): preg_replace_callback('/{(\w+)}/', Array, '{summary}?{item...')
#11 C:\xampp\htdocs\laskut\framework\zii\widgets\CBaseListView.php(121): CBaseListView->renderContent()
#12 C:\xampp\htdocs\laskut\framework\web\CBaseController.php(174): CBaseListView->run()
#13 C:\xampp\htdocs\laskut\protected\views\invoice\admin.php(65): CBaseController->widget('zii.widgets.gri...', Array)
#14 C:\xampp\htdocs\laskut\framework\web\CBaseController.php(119): require('C:\xampp\htdocs...')
#15 C:\xampp\htdocs\laskut\framework\web\CBaseController.php(88): CBaseController->renderInternal('C:\xampp\htdocs...', Array, true)
#16 C:\xampp\htdocs\laskut\framework\web\CController.php(748): CBaseController->renderFile('C:\xampp\htdocs...', Array, true)
#17 C:\xampp\htdocs\laskut\framework\web\CController.php(687): CController->renderPartial('admin', Array, true)
#18 C:\xampp\htdocs\laskut\protected\controllers\InvoiceController.php(149): CController->render('admin', Array)
#19 C:\xampp\htdocs\laskut\framework\web\actions\CInlineAction.php(32): InvoiceController->actionAdmin()
#20 C:\xampp\htdocs\laskut\framework\web\CController.php(300): CInlineAction->run()
#21 C:\xampp\htdocs\laskut\framework\web\filters\CFilterChain.php(129): CController->runAction(Object(CInlineAction))
#22 C:\xampp\htdocs\laskut\framework\web\filters\CFilter.php(41): CFilterChain->run()
#23 C:\xampp\htdocs\laskut\framework\web\CController.php(999): CFilter->filter(Object(CFilterChain))
#24 C:\xampp\htdocs\laskut\framework\web\filters\CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))
#25 C:\xampp\htdocs\laskut\framework\web\filters\CFilterChain.php(126): CInlineFilter->filter(Object(CFilterChain))
#26 C:\xampp\htdocs\laskut\framework\web\CController.php(283): CFilterChain->run()
#27 C:\xampp\htdocs\laskut\framework\web\CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)
#28 C:\xampp\htdocs\laskut\framework\web\CWebApplication.php(320): CController->run('admin')
#29 C:\xampp\htdocs\laskut\framework\web\CWebApplication.php(120): CWebApplication->runController('invoice/admin')
#30 C:\xampp\htdocs\laskut\framework\base\CApplication.php(135): CWebApplication->processRequest()
#31 C:\xampp\htdocs\laskut\index.php(12): CApplication->run()
If someone get any idea, I would greatly appreciate for help.