views:

36

answers:

2

Hi ...

I wanna ask you best practices about blog front page. I wanna build blog application using CodeIgniter framework. I have 2 type of page (front page, and admin page)

Supposed I have several controller in my front page (home, post, page, and link). By default I have include viewer of for all of these controller: header.php, footer.php, sidebar.php.

In the sidebar, I always display categories, recent comment, recent post, links, and archived.So .., In all of my front page controller I must implement select of categories, recent comment, recent post, links, and archived. Supposed I implement in all controller's constructor.

__construct () {
//data['categories'] = CategoryModel->getlist
//data['recent_posts] = PostModel->get_recent_post
//etc

can you suggest me, where I must place this method so I mustn't implement this method in all controller.

Thanks

+1  A: 

The best way to do this is to create a MY_Controller and use $this->data instead of $data. That means all your controllers will run from MY_Controller (as long as you explicitley tell your controllers to inherit from it).

http://codeigniter.com/wiki/MY_Controller_-_how_to_extend_the_CI_Controller/

Phil Sturgeon
+1  A: 

You can write a base controller which the other ones inherit from

class AppStartup extends Controller {

 function __construct() {
  // whatever you need
 }

}

then

class Home extends AppStartup {

 // ....

}

Also you could start accepting some of the answer given to you, or people won't be so happy to help you.

kemp