CodeIgniter Forums
some ci questions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: some ci questions (/thread-9608.html)



some ci questions - El Forum - 07-01-2008

[eluser]chops[/eluser]
i'm new to ci and I have a few questions.

How would I excecute a bit of code like this in a view

Code:
<?                $d = dir("/images/project");
                $i = 0;
                while (false !== ($entry = $d->read())) {
                    if(is_file("<?=base_url();?>images/".$row->title."/".$entry) && strcasecmp(substr($entry, -4), ".jpg")==0) {
                        if($i >= 5) {

                             $i=0;
                        }
                         ?&gt;<a >title?&gt;/&lt;?=$entry?&gt;" rel="lightbox[&lt;?=$row->title?&gt;]"><img >title?&gt;/thumbs/thumb_&lt;?=$entry?&gt;" alt="photo"></a>
                         &lt;?php
                         $i++;
                    }
                }
                $d->close(); ?&gt;
i know it shouldn't go in the view, should i set this as a function in models?

Also, what would be the best way to include a global query (eg: latest news sidebar) into most pages? would i have to set the query up in every controller? surely not!

thanks


some ci questions - El Forum - 07-01-2008

[eluser]Nima A.[/eluser]
Hi,
1. first, I don't think using native php coding is a good approach for views (esp. for control structures such as for,while, etc ... ), in these cases, php alternate syntax performs a bit faster and it's more readable ,
2. you can retrieve data from your model and then pass it to view using controller
3. design and implement a model for your news that represents it's structure and call it in every method of every controller that you want, I don't think setting and creating queries in controller is a good approach !


some ci questions - El Forum - 07-01-2008

[eluser]louis w[/eluser]
I think it's ok to iterate results (i would do it with a foreach thou) inside a view.