Welcome Guest, Not a member yet? Register   Sign In
Parser library, variable scope..
#1

[eluser]imamiscool[/eluser]
Today I realize that my view always went wrong because I had two variable: first is scalar, the last is array.

the last variable contains variable with same name with the first variable.

for example:
In controller:
Code:
//...... controller

$last_industry = '20';


$industries = $this->industriesmodel->findAll();
// will contain array of industries, each element contains:
// industry_id, industry_name
$data['industry_id'] = $last_industry;
$data['industries']  = $industries;

$this->parser->parse('myview', $data);


In view:
Code:
<table>
   <tr>
      <td>Last Industry ID : {industry_id}</td>
   </tr>
   <tr>
      <td>Select other ID:
          <select name="industry_id">
           {industries}
                <option value="{industry_id}">{industry_name}</option>
           {/industries}
          </select>
      </td>
   </tr>
</table>

Lets say, the value of the first 'industry_id' (after the word "Industry ID:") is '20',
then the combo box (select box)'s industry_id will be replaced with '20' too..

anyone ever face with this problem?
just share my thought, the problem was solved by changing the combobox's industry_id name into something else like '_industry_id' to differs with the first 'industry_id',

ps. sorry my english.

*edited


Messages In This Thread
Parser library, variable scope.. - by El Forum - 05-07-2010, 02:54 AM
Parser library, variable scope.. - by El Forum - 05-08-2010, 02:13 PM



Theme © iAndrew 2016 - Forum software by © MyBB