EllisLab text mark
Advanced Search
     
Requesting the same query for each controller
Posted: 22 July 2007 02:00 PM   [ Ignore ]
Avatar
Joined: 2007-07-22
69 posts

Hi, CodeIgniter users! smile As you can se, I’m new in this community and afterall quite new in frameworks. I found CI very usefull and easy to use but still I ran into one problem. So here is the deal.

I’m developing a website about computer graphics and web design, so I created controllers for each menu section (news, articles, usefull links, contact form, users list). By default CI loads news controller when someone enters the website. Now, I’ve splitted main view file into seperate files and this is how it looks like:

<!-- <WRAPPER -->

<
div id="wrapper">
<?php $this->load->view('header'); 
   
$this->load->view('menu'); 
?>
<div id="content">
<?=$this->load->view(CONF_PAGE)?>
</div>  
<?php $this->load->view('additional'); ?>
<div id="clear"></div

<!-- </
WRAPPER --> 

</
div>

<?php $this->load->view('footer'); ?>

</body>

</
html
<?=$this->load->view(CONF_PAGE)?> 

This loads view file depending on what controller is active at the momment.

<?=$this->load->view('additional')?> 

This one loads whatever the controller is. So the problem is I added a mysql query into news controller to get the data from DB and show it in every page. But I forgot that it won’t work if, for example, the articles controller will be active at the moment. The main question would be, where and how to add mysql query so data would be shown?
Sorry if my question is not perfectly clean for you, I just don’t know how to explain it in other words. I’d be grateful for your help. oh oh

Live example of this problem can be seen here: http://www.e-grafika.lt/ci/ after the text “MĖNESIO SVETAINĖ”.

 Signature 

Sprinkle - Asset Management Library | FlamingGrowl - GNTP library | Twiggy - Twig template engine implementation for CodeIgniter
You will have to excuse me for my sometimes poor English.

 
Posted: 22 July 2007 07:20 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-02-06
743 posts

You can’t call the news controller from the article controller. If you want DB results shown on every page, then you have to load that data in every controller. But there are some stategies to avoid code repetition.

Also ,one thing in your code doesn’t look correct:

<?=$this->load->view(CONF_PAGE)?>

// should be this:
<?=$this->load->view(CONF_PAGE''true); ?>
// or this:
<?php $this->load->view(CONF_PAGE); ?> 
 Signature 

“I am the terror that flaps in the night”

 
Posted: 22 July 2007 08:16 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2007-07-22
69 posts

Thanks. Actually I made it working by inserting MySQL query into additional.php file. I know it’s not the best idea, but it works.

 Signature 

Sprinkle - Asset Management Library | FlamingGrowl - GNTP library | Twiggy - Twig template engine implementation for CodeIgniter
You will have to excuse me for my sometimes poor English.