Welcome Guest, Not a member yet? Register   Sign In
problem with template parser class
#1

[eluser]Sara rad[/eluser]
hello friends

its my controller :

Code:
$this->load->library('parser');

$data['username'] = 'Sara';

$data['posts'] = array(
             array(
                   'title' => 'sample',
                   'body' => 'post body',
                   'username' => 'Josh'
                   ),
             array(    
                   'title' => 'my title',
                   'body' => 'my post body',
                   'username' => 'mike'
                  )
);

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

and this is my view :

Code:
<h1>{username}</h1>

{posts}
{title}/{body}/{username}
<br>
{/posts}

output is

Quote:Sara

sample/post body/Sara
my title/my post body/Sara

but i want it :

Quote:Sara

sample/post body/josh
my title/my post body/mike


any help !?

Thanks
#2

[eluser]InsiteFX[/eluser]
It's not a parser problem, if you look at the parser it expects an array not an array with other arrays in it thats why it displays your name but not your post data!

To display your posts array you would need to do something like this:
Code:
&lt;?php foreach($posts as $row): ?&gt;
<h3>&lt;?php echo $row->title;?&gt;</h3>
<p>&lt;?php echo $row->body;?&gt;</p>
<p>&lt;?php echo $row->username;?&gt;</p>
<hr>
&lt;?php endforeach;?&gt;
And I am not even sure that would work! Being as you array then array including another array!

You should pull this posts from a database posts table and assign each row to $data['posts']

Give me a minute and I will post a sample!

InsiteFX
#3

[eluser]Sara rad[/eluser]
i test it , its dont worked !

i get all data from a table then i cant change array indexs Sad
#4

[eluser]InsiteFX[/eluser]
Like I said it's because of the way you coded it!

The Parser Class only takes a single array!

InsiteFX
#5

[eluser]Sara rad[/eluser]
i have a table with this fields : art_id , art_artist_name , art_name , art_category

when a user go to art page i show art data and i get other arts by art_artist_name for show in thumbnail size ...

what can i do ? :-?
#6

[eluser]InsiteFX[/eluser]
Code:
// pull the information form your model and put it into $data.
$data['posts'] = $this->your_model->your_function($id);

InsiteFX
#7

[eluser]scottzirkel[/eluser]
Hey Sara,

The template parser does support multiple arrays like you have, however it apparently requires each key to have a unique name (unless it's within a loop). So you have {username} twice essentially, the first one and the one within the loop. If you change one of those, it should work just fine.




Theme © iAndrew 2016 - Forum software by © MyBB