[Typo3-dev] PHP syntax

Kraft Bernhard kraftb at gmx.net
Sun Sep 4 15:25:43 CEST 2005


Søren Vedel wrote:
>     if ($this->getFieldContent("type")=1) {
> ($this->getFieldContent("type") => "The second value")
> };


don't hurt a PHP programmer ! mentally :)

you can't assign function return value (which "$this->getFieldContent("type")" is) ...
neither by using the = nor the => operator ...

You can't even assign a normal variable using the => operator ...

$test => 'foobar' : invalid !!!

=> is just used to assign an array-value to an array-key:
$test = array(
   'foor' => 'bar',
);

----------------------------------

I don't know who is outputting your <select> html statement ... but in between the
<select> and </select> you have to have <option> tag's somehow like:
$content .= <option value="1" '.($this->getFieldContent('type')==1?'selected':'').'>'.$this->pi_getLL('label_1').'</option>';

this will generate an <option> tag whose value is "1" and if the value of the actual row is "1" then
this option will be the selected one: ($this->getFieldContent('type')==1?'selected':'')

What most probably your problem is:
 > Now I want to assign the correct values to display in FE and not the numbers 0 and 1.

is to have the correct value between the <option></option> tag ... that's the value which get's displayed in the
select box ...

you should retrieve those values by using $this->pi_getLL('label_1') or label_2 label_3 ...

the keys 'label_1' must get defined in the pi1/locallang.php file ...

so your extension also supports multiple languages ...


greets,
Bernhard
-- 
----------------------------------------------------------------------
"Freiheit ist immer auch die Freiheit des Andersdenkenden"
Rosa Luxemburg, 1871 - 1919
----------------------------------------------------------------------




More information about the TYPO3-dev mailing list