Question

I have a problem on yii model, ive been told to use the generateAttributeLabel() on the model, but i tried to use it on the way i thought it would work but it doesnt. This is my code

public function generateAttributeLabel($variable = file_get_contents('protected\column.txt'))
{
    return $variable;
}   

public function attributeLabels()
{
        return array(
        'id' => 'ID',
        'parametro_id' => 'Parametro',
    );
}

There are some columns that are being generated automatically and i thought to save their names into a file and its saved as example like (index, par, tolt, sircer). Thats why the file_get_contents(), but i get an error:

Parse error: syntax error, unexpected '(', expecting ')'. 

so i really dont know and i need this to make checkboxlist with the attributes of each column thats going to be saved as y or n, if someone could tell me how to use this with checkboxlist would be appretiated.

the content file is this

lololo, 

for now it has 1 element, but will be adding more each time a column is created

Was it helpful?

Solution

You can't use a function return value as a default value in a function declaration, you will need to set that up in the function itself

public function generateAttributeLabel($variable = null){
    if($variable){
        $variable = file_get_contents($variable);
    }

    return $variable;
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top