CodeIgniter Forums

Full Version: some ci questions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

i'm new to ci and I have a few questions.

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

<?                $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) {

                         ?&gt;<a >title?&gt;/&lt;?=$entry?&gt;" rel="lightbox[&lt;?=$row->title?&gt;]"><img >title?&gt;/thumbs/thumb_&lt;?=$entry?&gt;" alt="photo"></a>
                $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!


El Forum

[eluser]Nima A.[/eluser]
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 !

El Forum

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