Htmlspecialchars() Expects Parameter 1 To Be String, Array Given

Hi I’ve been at this for most of the week, if I can’t get something working by the end of the week I’ll have to cut my losses with this framework.

It works when I remove msg_id which is from the other table I’m joining ppw_allcomms, if I put it in I get the error ‘htmlspecialchars() expects parameter 1 to be string, array given’ I think it’s something to do with


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(

                 'msg_id'=>array(self::HAS_MANY, 'Ppwallcomms', 'mob_num')

		);

	}

in that it’s an array is there a way of converting it to a string and using it.

Also I still don’t fully understand relations, do I need it I’ve got the join in my sql as you can see lower down?, but if I take the relationship out I get a different error.

my controller


class HomeCharge extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @param string $className active record class name.

	 * @return HomeCharge 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 'home_charge';

                return 'ppw_allcomms';

               

	}


	/**

	 * @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('msg_id,sim_num, mob_num, Scheme, PPN_ID, PONo', 'length', 'max'=>45),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('msg_id,id, sim_num, mob_num, Scheme, PPN_ID,ActivationDate', '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(

                 'msg_id'=>array(self::HAS_MANY, 'Ppwallcomms', 'mob_num')

		);

	}


       

       

	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

             

         //var_dump('power_field');

       

		return array(

			'id' => 'ID',

			'sim_num' => 'Sim Num',

			'mob_num' => 'Mob Num',

			'Scheme' => 'Scheme',

			'PPN_ID' => 'Ppn',

			'ActivationDate' => 'Activation Date',

                   'msg_id' => 'power field'

		);

	}


	/**

	 * 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()

	{

		

            

		

$sql="select id,msg_id,mob_num,sim_num,pod_phone_number from home_charge join ppw_allcomms on mob_num=pod_phone_number";

	

	return new CSqlDataProvider($sql); 

  

   

	

	

	

               

                

        }

}

view


$this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'home-charge-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'sim_num',

		'mob_num',

		'PPN_ID',

		'PONo',

                'msg_id'   , 		

		'ActivationDate'

			//	array(

			//'class'=>'CButtonColumn',

		//),

	),

)); 

You seem to have completely misunderstood relations. I’d recommend looking through the Yii definitive guide.

A relation isn’t just a value that you can read or set, it’s a link to another model or array of models. It would mean nothing to just output this.

Again, look at the guide, particularly the section on relations.

I’ve already had a good look. Can you please add to my code, what I’m missing then I might understand it more. I don’t want to use active record tried that way but it doesn’t suit complex sql queries.

Thanks