![]() |
View files with common data - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: View files with common data (/showthread.php?tid=11348) Pages:
1
2
|
View files with common data - El Forum - 09-05-2008 [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'); Main view file: Code: <?php foreach ($blogEntries as $blogEntry): ?> Userinfo view file: Code: <!-- USERINFO --> I move userinfo in a separate view file, because I want to use this userinfo in other pages. View files with common data - El Forum - 09-05-2008 [eluser]Bramme[/eluser] You're passing the $blogEntry['User'] array to your userinfo view file. The same happens when you pass $content['blogEntry'] to your blog_view. You don't access $content['blogEntry'] in your blog_view, you access $blogEntry. So you should use $nickname and $rating in your userinfo view file. If you want to keep using $blogEntry['nickname'] in your userinfo view file, don't pass an array in the second argument when loading the view file from your blog_entry view. Just do $this->load->view('userinfo'), the variables get passed along automatically. View files with common data - El Forum - 09-05-2008 [eluser]Body[/eluser] [quote author="Bramme" date="1220638731"]You're passing the $blogEntry['User'] array to your userinfo view file. The same happens when you pass $content['blogEntry'] to your blog_view. You don't access $content['blogEntry'] in your blog_view, you access $blogEntry. So you should use $nickname and $rating in your userinfo view file. [/quote] I think you're not right. Yes, when I'm passing $content['blogEntries'] to a view file, I access $blogEntries. So, when I'm passing $blogEntry['User'], i should access $User. [quote author="Bramme" date="1220638731"] If you want to keep using $blogEntry['nickname'] in your userinfo view file, don't pass an array in the second argument when loading the view file from your blog_entry view. Just do $this->load->view('userinfo'), the variables get passed along automatically. [/quote] Automatically passing is not working - error "Undefined variable: blogEntry ". :/ View files with common data - El Forum - 09-05-2008 [eluser]Bramme[/eluser] Hmm, could always be I'm mistaken. It'd surprise me though, seeing as I've used embedded view in the past and not adding an array as second parameter for the load->view function worked fine. |