Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在yii中的CGridView处调用函数_Php_Yii_Model_Cgridview - Fatal编程技术网

Php 在yii中的CGridView处调用函数

Php 在yii中的CGridView处调用函数,php,yii,model,cgridview,Php,Yii,Model,Cgridview,PHP类: Table operation ( id INT PRIMERY, Name VARCHAR(50), Loading VOURCHAR(50), ) Table Waybill ( Id INT PRIMERY, name VARCHAR(50), operation_id VOURCHAR(50), // this is a foreign key of ) Table container ( Id INT PRI

PHP类:

Table operation (
    id INT PRIMERY,
    Name VARCHAR(50),
    Loading VOURCHAR(50),
)

Table Waybill (
    Id INT PRIMERY,
    name VARCHAR(50), 
    operation_id VOURCHAR(50), // this is a foreign key of 
)


Table container (
    Id INT PRIMERY,
    name VARCHAR(50),
    container_no VARCHAR(50),
    operation_id VARCHAR(50), // this is a foreign key of operation table
    waybill_id  VARCHAR(50), // this is a foreign key of waybill table
)


Table cargo (
    Id INT PRIMERY,
    name VARCHAR(50),
    description VARCHAR(50),
    operation_id  VARCHAR(50), // this is a foreign key of operation table
    waybill_id VARCHAR(50), // this is a foreign key of waybill table
)
class运单扩展了CActiveRecord{
公共职能关系()
{ 
返回数组(
'operations'=>array(self::属于'Operation'、'Operation\u id'),
'containerHM'=>数组(self::有许多'Container','waybill'id'),
'cargoHM'=>数组(self::有许多'Cargo','waybill'=>id'),
);
}
//此功能用于在Waybil CGridView中显示所有相关集装箱
公共函数getRaltedContainer(){
$result='';
如果($this->operations->load='with'){
$allContainers='';
$containers=$this->containerHM;
//集装箱运输是货运单和集装箱之间的一种多方面关系
foreach($containers作为$container){
$allContainers.=$container->container_no.“-”;
} 
$result=$allContainers;
}如果($this->operations->loading='cargo'){
$allCargo='';
$cargos=$this->cargoHM;
foreach($cargo作为$cargo){
$allCargo.=$cargo->description.“
”; } $result=$allCargo; } 返回$result; } }
PHP:


因此,我可以调用该函数,它正在工作,但问题是它只显示第一行CGridView,因为我需要显示所有货运单及其集装箱或货物。

getRelatedContainer()
在您的模型中拼写错误:

<?php
// At CGridView I need to call like this
$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'waybill-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'ajaxUpdate'=>false, 
    'columns'=>array(
         'id',
          array(
                'header'=>'Items',
                'type'=>'raw',
                'value'=>'$data->getRelatedContainer()',
            ),
    ),
)); ?>
谢谢塞缪尔, 我找到了答案,问题是我写的

// this function is to display all related containers at Waybil CGridView
public function getRaltedContainer(){
而不是

$this->operations->loading='with'

这就是我的问题,现在它工作得很好

添加控制器代码。还有
if($this->operations->loading='cargo'){
$this->operations->loading='with'
$this->operations->loading =='with'