English 中文(简体)
Yii CGridview - search/sort work, but Value aren t being reflected on each cell
原标题:Yii CGridview - search/sort works, but values aren t being displayed on respective cells

I am semi-frustrated with this Yii CGridView problem and any help or guidance would be highly appreciated.

我有两张相关表格(商店——直面小学)和联系(商号——外国),这样一家商店可以有多个联系。 采用“CGridview”将记录和分类以及我在商店模式中的关系功能等同:

   shopscontact  => array(self::HAS_MANY,  Shopsmodel ,  shop_id );

On the shop grid, I need to display the shop row with any one of the available contacts. My attempt to filter, search the Grid has worked pretty fine, but I m stuck in one very strange problem. The respective grid column does not display the value that is intended.

在CGridview档案中,Im从事类似事情。

  array(
     name  =>  shopscontact.contact_firstname ,
     header  =>  First Name ,        
     value  =>  $data->shopscontact->contact_firstname 
    ),

页: 1 然而,即使在搜查/护送工作(我通过检查 d协会发现)的情况下,电网栏也空洞! 而且,当我做一个var时,我就把 子_死。

 array(
     name  =>  shopscontact.contact_firstname ,
     header  =>  First Name ,
     value  =>  var_dump($data->shopscontact) 
    ),

The dump shows record values in _private attributes as follows:

  private  _attributes  (CActiveRecord) => 
    array
       contact_firstname  => string  rec1  (length=4)
       contact_lastname  => string  rec1 lsname  (length=11)
       contact_id  => string  1  (length=1)

< Edit: >

My criteria code in the model is as follows:

  $criteria->with = array(
     owner , 
     states , 
     shopscontacts  => array(
       alias  =>  shopscontacts ,
       select  =>  shopscontacts.contact_firstname,shopscontacts.contact_lastname ,
       together  => true
    )
  );

以及

我如何利用各自栏目中的数值? 请帮助!

最佳回答

Hmm, I have not used the with() and together() methods much. What s interesting is how in the value part of the column, $data->shopscontacts loads up the relation fresh, based on the relations() definition (and is not based on the criteria you declared).

处理阵列产出的更清洁的方法可能类似:

 value  =>  array_shift($data->shopscontacts)->contact_lastname 

www.un.org/Depts/DGACM/index_spanish.htm 但是,也许要建立新的(附加的)关系,就像在您的<条码>商店/条码中建立这种关系。 模式:

public function relations()
{
  return array(
     shopscontacts  => array(self::HAS_MANY,  Shopsmodel ,  shop_id ), // original
     firstShopscontact  => array(self::HAS_ONE,  Shopsmodel ,  shop_id ), // the new relation
  );
}

Then, in your CGridView you can just set up a column like so:

 columns =>array(
   firstShopscontact.contact_lastname ,
),

卡车

问题回答

由于商店名称是旧关系,_$data->shopscontact应当将一个阵列归还所有与商店有关......您是否修改了关系以便只归还一个记录(如果我没有错,你只需要显示一个,正确吗?) 如果是的话,我是否可以认为你的过滤法?

P.S. A hunch to have a brief but temporal Solutions: have Youtries Value =>$data->shopscontact[link_firstname] ?





相关问题
Codeigniter WHERE on "AS" field

I have a query where I need to modify the selected data and I want to limit my results of that data. For instance: SELECT table_id, radians( 25 ) AS rad FROM test_table WHERE rad < 5 ORDER BY rad ...

Problem find joined table in rails

I have model represent association rule (Body => Head) def Item has_many :heads has_many :bodies ... end def Rule has_many :heads has_many :bodies ... end def Body belongs_to :item belongs_to :rule ...

FreeTDS Bad token from the server (SQL Server)

Today we had a lot more activity than normal between our Ruby on Rails application and our remote legacy SQL Server 2005 database, and we started getting the error below intermittently. What is is? ...

Castle ActiveRecord: one-to-one

While playing around with one-to-one associations in castle activerecord I stumbled upon the following problem: I m trying to model a one-to-one relationship (user-userprofile in this case). I ...

Sending email updates: model or observer?

I have an Event model, which stores an event feed for each user. I also need to email the updates to users which have enabled email notifications in their profile. From an architectural point of view,...

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

热门标签