CodeIgniter Forums
Different Views for Articles - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: Different Views for Articles (/showthread.php?tid=66867)



Different Views for Articles - johnWayne - 12-13-2016

How would I go about having different views for an article in Code Igniter.
For example I have one Index for all articles and I also have a view. But what If I want to have say 10 pictures for one article and only three for another?
So my view is:



Code:
<div id="wrapper">    
<div id="main-wrapper" class="col-md-10 pull-right">
 <div id="main">  
  <div class="col-md-9">
   <div id="sec#" class="">
       <h2><?= $article['title']?></h2>
    <img border="0" src="<?= assetUrl() ?>img/article/<?= $article['image']?>">
    <h6>Date: <?= $article['date']?></h6>
    <h6>Author: <?= $article['author']?></h6>
    <br>
    <p><?= $article['body']?></p>
   </div>
  </div>
 </div><!--/right-->
</div><!--Main wrapper-->
</div><!--Wrapper-->


All the articles look the same. But what if I want to have pictures within the body of the article? And what if the number of pictures are different for each article.

I'm struggling with this, because all the articles look the same. And depending on the text, it would be nice to render pictures on different parts of the body.

Also, I've been adding HTML tags in the longtext and I save them in the database. Isn't this dangerous? I'm sure there must be a better way of doing this. But if I don't put any
tags, the body just displays as one big blob of text.

Thanks


RE: Different Views for Articles - InsiteFX - 12-13-2016

Pass the images through the $data, you can then use count() to get the count of images and loop through them using a foreach loop.


RE: Different Views for Articles - johnWayne - 12-13-2016

Yes, but the I won't have any control of where in the article the pictures render.


RE: Different Views for Articles - InsiteFX - 12-14-2016

For Bootstrap you should be using the image responsive class.

You can load other views within a view so that would be up to you
where you want to put them, just do a flag check etc;