impossible to send array member as a parameter

I was wondering is there any bug with sending array members with for example activeDropDownList,

here is my source that does not work:




<?php


class UserFilterForm extends CFormModel

{

     ......


     public $termSymbols;


     public function initalize()

     {

         $termSymbols = array();

         $termSymbols[1] = "test";

     }

     ....	

	 

}


....

$model = new UserFilterForm;

$model->initalize();

....


//and call:

echo '<li>'.CHtml::activeDropDownList($model, 'termSymbols[1]', UserFilterForm::$something).'</li>'



And what does happen is the error message: Undefined offset: 1

Why I’m not able to give a member as a normal parameter? It seems that yii can’t handle array members in that context.

What do you try with this?


UserFilterForm::$something

There are just some options like:

public static $something = array(‘male’ => ‘male’, ‘female’=>‘female’);

Your problem is, that the current attribute value 1 is not contained in the list of available options. Besides that, your code looks a little unconventional. I can’t understand what you try with ‘termSymbols[1]’. This should be a regular attribute name (e.g. ‘gender’)

I’m sorry I just referred example and changed the context of some part so thats why it can be hard to understand.

So in fact there are no options like male and female, but options like:

1.iquals ( = )

2.contains

  1. starts with

4.ends

And the number of the dropDownList elements will be between 0 - 10, depending what does javascript determines.

So, i tried to get all termSymbols in array with length 10.

and later i would be able to call like termSymbols[7] and it would return "starts with" or something.

And dropdownlist would be generated in loop.

thats why im not able to make variable gender, or in this sitution termSymbol, becouse

I would need lot of them, like $the_fifth_gender = $genders[4];

This hole component are maint to offer filters to make database queries in browser , like look for users with email that starts with "a" and the second statement is that users have a surname which is igual than "alfonso".

In initialize you have to use $this like




     public function initalize()

     {

         $this->termSymbols = array();

         $this->termSymbols[1] = "test";

     }



I tryed to put this code in an existing model, and in the view of that model I used your dropdown code and it’s displaying without error… haven’t tried to access the data…

Hey, that was exactly correct, thanks a lot. I was looking for error somewhere else in Yii strucutre but stupid me I just forgot to add $this.

I’m very thankful to you,I just mistaked and you regoniced it very well.

Glad to be of help… :)