Функция вызова в CGridView в yii

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
)

PHP-класс:

class Waybill extends CActiveRecord  {

public function relations()
{ 
    return array(
         'operations' => array(self::BELONGS_TO, 'Operation', 'operation_id'),
         'containerHM' => array(self::HAS_MANY, 'Container', 'waybill_id'),
        'cargoHM' => array(self::HAS_MANY, 'Cargo', 'waybill_id'),
       );
}

// this function is to display all related containers at Waybil CGridView
    public function getRaltedContainer(){
               $result ='';
            if($this->operations->loading='with' ){
                $allContainers =''; 
                $containers = $this->containerHM ; 
               // containerHM  is a HAS_MANY relation between Waybill and Container 
                foreach($containers as $container){                
                   $allContainers .= $container->container_no." - "; 
                } 
                $result =  $allContainers;
            }  if($this->operations->loading='cargo'){
                $allCargo =''; 
                $cargos = $this->cargoHM ;
                foreach($cargos as $cargo){                
                   $allCargo .= $cargo->description." <br />"; 
                } 
                $result = $allCargo;
            }

            return $result;
        }
}

PHP:

<?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()',
            ),
    ),
)); ?>

Итак, я могу вызвать эту функцию, и она работает, но проблема в том, что она отображает только первую строку CGridView, потому что мне нужно отобразить все накладные с их контейнерами или грузом.


person Mahdi Miad    schedule 16.01.2014    source источник
comment
добавьте код контроллера.   -  person Kumar V    schedule 16.01.2014


Ответы (2)


getRelatedContainer() в вашей модели написано неправильно:

// this function is to display all related containers at Waybil CGridView
public function getRaltedContainer(){
person Samuel Liew♦    schedule 16.01.2014

Спасибо Самуэль, я получил решение, проблема была в том, что я написал

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

вместо

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

Так что это была моя проблема, и теперь она работает хорошо

person Mahdi Miad    schedule 18.01.2014
comment
А еще if($this->operations->loading='cargo'){ - person Kumar V; 18.01.2014