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
#2

[eluser]Tominator[/eluser]
Hi man!

It's because pseudo-variable replacing is before cycles. I've made my own Template Parser, whitch is correct + providing more functions.

Take a look:
[url="http://parser.comper.sk/en/"]http://parser.comper.sk/en/[/url]

or

[url="http://ellislab.com/forums/viewthread/153269/"]http://ellislab.com/forums/viewthread/153269/[/url]




Theme © iAndrew 2016 - Forum software by © MyBB