I want to display one column with the attribute brand.’-’.model of the teclado model
teclado model:
<?php
/**
* This is the model class for table "teclado".
*
* The followings are the available columns in table 'teclado':
* @property integer $idteclado
* @property string $brand
* @property string $model
*
* The followings are the available model relations:
* @property Ritmo[] $ritmos
*/
class Teclado extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Teclado 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 'teclado';
}
/**
* @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('model, brand', 'required'),
array('model, brand', 'length', 'max'=>45),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('idteclado,brand,model', '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(
'ritmos' => array(self::MANY_MANY, 'Ritmo', 'ritmo_teclado(idteclado, idritmo)'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'idteclado' => 'Idteclado',
'brand' => Yii::t('app','Brand'),
'model' => Yii::t('app','Model'),
);
}
public function getTecladoName(){
return $this->brand.'-'.$this->model;
}
/**
* 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('idteclado',$this->idteclado);
$criteria->compare('brand',$this->brand,true);
$criteria->compare('model',$this->model,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
and ritmo_teclado model:
<?php
/**
* This is the model class for table "ritmo_teclado".
*
* The followings are the available columns in table 'ritmo_teclado':
* @property integer $idritmo
* @property integer $idteclado
*/
class RitmoTeclado extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return RitmoTeclado the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function addTeclado(){
if($this->findByPk(array('idritmo'=>$this->idritmo,'idteclado'=>$this->idteclado))==null)
{
$this->save();
}
}
public function revokeTeclado(){
$ritmoteclado=$this->findByPk(array('idritmo'=>$this->idritmo,'idteclado'=>$this->idteclado));
if ($ritmoteclado)
{
$ritmoteclado->delete();
}
}
public function grantAllTeclados($idritmo){
$this->revokeAllTeclados($idritmo);
$teclados=Teclado::model()->findAll();
foreach($teclados as $teclado ){
$tecladoR=new RitmoTeclado;
$tecladoR->idteclado=$teclado->idteclado;
$tecladoR->idritmo=$idritmo;
$tecladoR->addTeclado();
}
}
public function revokeAllTeclados($idritmo){
$this->deleteAll('idritmo='.$idritmo);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'ritmo_teclado';
}
/**
* @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('idritmo, idteclado', 'required'),
array('idritmo, idteclado', 'numerical', 'integerOnly'=>true),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('idritmo, idteclado', '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(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'idritmo' => 'Idritmo',
'idteclado' => 'Idteclado',
);
}
/**
* 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('idritmo',$this->idritmo);
$criteria->compare('idteclado',$this->idteclado);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}