Part of the EllisLab Network
   
 
PHP Includes
Posted: 29 October 2009 05:49 PM   [ Ignore ]  
Summer Student
Total Posts:  24
Joined  10-29-2009

I am liking the idea of codeigniter but am new to MVC mentality. I would like to keep part of my site done the same way as I used to just because it was easy and I think it is impossible to do with MVC, please prove me wrong. What I would do is set an index.php file and that would have the “framework” of the site. This would include the head of the site as well as include sections for the navigation and header. Then there would be a section that took a $_GET variable and based on the variable it would know what page to include. Under codeigniter it looks to be that I have to have all of the html in the view pages so each view would have a head and a section for the header and navigation includes like I had before. This is cumbersome because before I was able to click on the page I wanted to view the page of in my text editor and all that would be on that document was the content for that page and nothing else. Is this way of doing things possible with codeigniter?

Profile
 
 
Posted: 29 October 2009 06:45 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  811
Joined  06-10-2009

Check out the wiki entry on this: http://codeigniter.com/wiki/Header_and_footer_and_menu_on_every_page/

I basically use a class variable of $this->data that I pass to all my views. I load a “view partial” with my content into $this->content, which I alias with a reference of $this->data[‘content’] =& $this->content.

Then in my ‘master template’ for the whole page I just have an echo $content in my view, which is part of the $this->data array I pass to my all/most of my views.

The wiki details how this works, and I’ve been meaning to put my take on there but haven’t gotten around to revising it. Basically I use my controller’s constructor for these sorts of header/footer initializations, but you can just as well use a MY_controller - same basic principle.

None of this violates MVC. Indeed, nothing in MVC dictates you can only use one View.

 Signature 

CreativeHalls Web Design and Printing
A few of my projects:
OurGulfCoast Property Management and Vacation Rental (ASP/.NET)
BukuBux - Money Saving Coupons and Gift Certificates (CodeIgniter, LAMP/MySQL)
Rentals800.com - Find a place to rent (CodeIgniter, LAMP/MySQL)
bdh (dot) hall (at) gmail (dotcom)

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120337 Total Logged-in Users: 54
Total Topics: 126462 Total Anonymous Users: 3
Total Replies: 665012 Total Guests: 452
Total Posts: 791474    
Members ( View Memberlist )