Hy,
is use this, but always say me:Division by zero
What is the probleme?
<?php
$meret = new MeretClass();
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$item = Item::model()->getItem($_GET['id']),
'columns'=>array(
array(
'name'=>'Név',
'value'=>'CHtml::link(CHtml::encode(Yii::app()->baseUrl.'/'.$item->name, $meret->levag($item->name)))',
),
array(
'name'=>'méret',
'value'=> '$meret->atmeretez($item->size)',
),
array(
'class'=>'CButtonColumn',
),
),
));
?>
Keith
(Kburton)
March 15, 2012, 8:17pm
2
Your syntax is wrong in the first value specification, so it’s trying to divide a string by another string. Look for the ‘/’ symbol.
Hmm. What is the right syntax?
If i use this :
'value'=>'CHtml::link(CHtml::encode(Yii::app()->baseUrl/$item->name, $meret->levag($item->name)))',
drop error the php.
Fatal error: Call to a member function getData() on a non-object in D:\munka\web\tothszabi\framework\zii\widgets\CBaseListView.php on line 105
Keith
(Kburton)
March 15, 2012, 9:30pm
4
If you’re using a recent version of PHP, you can use a closure to make the code clearer:
array(
'name'=>'Név',
'type'=>'raw',
'value'=>function($item) use ($meret){
return CHtml::link(
CHtml::encode(Yii::app()->baseUrl.'/'.$item->name),
$meret->levag($item->name)
);
},
),
If not, your original code could possibly be replaced with:
'value'=>'CHtml::link(CHtml::encode(Yii::app()->baseUrl."/".$item->name, $meret->levag($item->name)))',
I tend to rely on closures, so I’m not sure if the second option will work correctly for you. Your problem was that the single quote character before the forward slash was terminating the existing string. Using double quotes will avoid that. Alternatively you could escape the single quote with the backslash character.
Note, you will need to set the column type to raw if you want to be able to insert HTML code, such as a link.
PHP closures:
http://php.net/manual/en/functions.anonymous.php
Keith:
If you’re using a recent version of PHP, you can use a closure to make the code clearer:
array(
'name'=>'Név',
'type'=>'raw',
'value'=>function($item) use ($meret){
return CHtml::link(
CHtml::encode(Yii::app()->baseUrl.'/'.$item->name),
$meret->levag($item->name)
);
},
),
If not, your original code could possibly be replaced with:
'value'=>'CHtml::link(CHtml::encode(Yii::app()->baseUrl."/".$item->name, $meret->levag($item->name)))',
I tend to rely on closures, so I’m not sure if the second option will work correctly for you. Your problem was that the single quote character before the forward slash was terminating the existing string. Using double quotes will avoid that. Alternatively you could escape the single quote with the backslash character.
Note, you will need to set the column type to raw if you want to be able to insert HTML code, such as a link.
PHP closures:
http://php.net/manual/en/functions.anonymous.php
The first and the second version drop this error:
Fatal error: Call to a member function getData() on a non-object in D:\munka\web\tothszabi\framework\zii\widgets\CBaseListView.php on line 105
I use php 5.3.10
softark
(Softark)
March 16, 2012, 3:17pm
6
'value'=>'CHtml::link(CHtml::encode(Yii::app()->baseUrl.'/'.$item->name, $meret->levag($item->name)))',
...
'value'=> '$meret->atmeretez($item->size)',
You can not use something like “$meret” or “$item” in the string for ‘value’.
http://www.yiiframework.com/doc/api/1.1/CDataColumn/#value-detail
joblo
(Joe)
March 16, 2012, 3:20pm
7
1.) You should assign a dataprovider to the corresponding property of the cgridview.
Does
$item = Item::model()->getItem($_GET['id']),
really return a dataProvider?
Is $item an object that implements the method getData()?
2.) You should use ‘$data->name’,$data->size… instead of $item->…
Joblo:
1.) You should assign a dataprovider to the corresponding property of the cgridview.
Does
$item = Item::model()->getItem($_GET['id']),
really return a dataProvider?
Is $item an object that implements the method getData()?
2.) You should use ‘$data->name’,$data->size… instead of $item->…
I replace $item to $data and it works. But if is wanna use external method?
$metet->levag and $meret->atmeretez? Is it impossible?
Thanks everyone.
phtamas
(Phtamas)
March 16, 2012, 4:30pm
9
Class “MeretClass” in your code seems to be a helper class that doesn’t hold any internal state. Try to rewrite it as a collection of static methods or an application component. Then you can simply write:
'value' => 'MeretClass::atmeretez($data->size)',
or
'value' => 'Yii::app()->meret->atmeretez($data->size)',