[eluser]Unknown[/eluser]
Hello all, this is my first post...
Just to notice that my php programming skills greatlly increased when I started to use codeigniter, and I plan to use it for the rest of my life
I wanted to fully remove php code from my views, so my plan is to put everything in data array, so i can easily access variables using templates...
I have a problem using codeigniter's template parser combined with form helper (form_dropdown)...
Problem is form_dropdown cant get "selected" value correctly.
I would really appreaciate some help...
This is part of controller code:
Code:
// popis protivnika
$list_opp_country = array(
'SLO'=>'Slovenia',
'BIH'=>'Bosnia',
);
// skupi sve varijable u array
$data = array(
'site_title' => lang('admin_page_nation_edit').lang('admin_page_site_title').$this->config->item('site_name'),
'validation_errors' => validation_errors(),
'form_open' => form_open('admin/nation/hrv/edit/{id}'),
'label_dropdown_opponent' => form_label(lang('opponent'), 'opp_country'),
'dropdown_opponent' => form_dropdown('opp_country', $list_opp_country, set_value('opp_country', '{opp_country}')),
'label_input_our_score' => form_label(lang('our_score'), 'our_score'),
'input_our_score' => form_input('our_score', set_value('our_score', '{our_score}')),
'label_opp_score' => form_label(lang('opp_score'), 'opp_score'),
'input_opp_score' => form_input('opp_score', set_value('opp_score', '{opp_score}')),
'form_submit' => form_submit(FALSE, lang('edit')),
'form_close' => form_close(),
'one_nation' => $this->admin_model->nation_hrv_get_one($id)
);
// parse view
$this->parser->parse('templates/header', $data);
$this->parser->parse('admin/nation/edit', $data);
$this->parser->parse('templates/footer', $data);
This is view file:
Code:
<p>Breadcrumbs: <?=set_breadcrumb();?></p>
<fieldset>
<legend>Edit Nation War</legend>
{validation_errors}
{one_nation}
<p>zemlja: {opp_country} </p>
{form_open}
<p>{label_dropdown_opponent} <br /> {dropdown_opponent}</p>
<p>{label_input_our_score} <br /> {input_our_score}</p>
<p>{label_opp_score} <br /> {input_opp_score}</p>
{form_submit}
{form_close}
{/one_nation}
</fieldset>
The issue is in this line
Code:
form_dropdown('opp_country', $list_opp_country, set_value('opp_country', '{opp_country}')),
1. "form_dropdown" function cannot read value "{opp_country}" in view file, while
2. any "form_input" reads the parsed value well...
If i use this:
Code:
form_dropdown('opp_country', $list_opp_country, set_value('opp_country', 'BIH')),
then selected value is "Bosnia" as defined in $list_opp_country variable - array...
but when I use template parser to return value "BIH" from database, form_dropdown ignores or cannot read the same value...
if i put {opp_country} anywhere else in view file, i get correct echo from database...