Welcome Guest, Not a member yet? Register   Sign In
View files with common data
#11

[eluser]Body[/eluser]
Thanks very much for all.

So, as i understand, the best way is to calculate rating for all blogs users in controller, and then just output all data in views (without any calculations in view file)? But how should I deal with userinfo block if i want to use it in many other pages?

Is it good practice:

My main controller now look like this:
Code:
$this->load->library('RatingCounter');

// Hardcoded. In real programm this data is fetched from database.
$content['blogEntries'] = array(
      0 => array(
                 'id' => 5,
                 'title' => 'Some title',
                 'content' => 'Some content',
                 'User' => array (
                                  'id' => 2,
                                  'nickname' => 'body',
                                  'points' => '25'
                           )
           ),
      1 => array(
                 'id' => 6,
                 'title' => 'Some title 2',
                 'content' => 'Some content 2',
                 'User' => array (
                                  'id' => 3,
                                  'nickname' => 'test',
                                  'points' => '13'
                           )
           )
);

for ($i = 0, $size = count($content['blogEntries']); $i < $size; $i++) {
    $content['blogEntries'][$i]['User']['rating'] = $this->ratingcounter->get_rating($content['blogEntries'][$i]['User']['points']);
}

$this->load->view('blog_view', $content);

Main view file:
Code:
&lt;?php foreach ($blogEntries as $blogEntry): ?&gt;
    <h1>&lt;?=$blogEntry['title']?&gt;</h1>

    &lt;?php $this->load->view('userinfo', $blogEntry['User']); ?&gt;

    <br /><br />
&lt;?php endforeach; ?&gt;

Userinfo view file:
Code:
&lt;!-- USERINFO --&gt;
    Username: &lt;?=$User['nickname']?&gt;<br />
    Rating: &lt;?=$User['rating']?&gt;
    &lt;!-- /USERINFO --&gt;

I move userinfo in a separate view file, because I want to use this userinfo in other pages.


Messages In This Thread
View files with common data - by El Forum - 09-05-2008, 12:06 AM
View files with common data - by El Forum - 09-05-2008, 01:00 AM
View files with common data - by El Forum - 09-05-2008, 01:10 AM
View files with common data - by El Forum - 09-05-2008, 01:40 AM
View files with common data - by El Forum - 09-05-2008, 01:42 AM
View files with common data - by El Forum - 09-05-2008, 01:47 AM
View files with common data - by El Forum - 09-05-2008, 02:53 AM
View files with common data - by El Forum - 09-05-2008, 02:57 AM
View files with common data - by El Forum - 09-05-2008, 03:11 AM
View files with common data - by El Forum - 09-05-2008, 03:14 AM
View files with common data - by El Forum - 09-05-2008, 06:35 AM
View files with common data - by El Forum - 09-05-2008, 07:18 AM
View files with common data - by El Forum - 09-05-2008, 07:40 AM
View files with common data - by El Forum - 09-05-2008, 08:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB