CodeIgniter nested controllers? -
CodeIgniter nested controllers? -
i'm new codeigniter , hope question have simple answer.
i have website couple of menu items (menua,menub , menuc). have modeled 1 main controller, index(), menua(), menub() , menuc() in controller. called function sets session value currentmenu , includes header, x, footer. x depends on function called. header high lights choosen menu.
within menuc (account settings in webapp) have different controller controls subviews of accountsettings/notloggedin.
logically menuc() include header , footer forwards phone call subcontroller managed login or sub pages.
am using framwork wrong or there straight forwards way accomplish this?
i think sounds you're not understanding how apply mvc structure. image way:
controllers represent facet of application users can interact with. example, have items
controller allows users create, read, update, or delete items
. logic interacting items
handled controller (meaning calls items
model , renders necessary views).
in case sounds building pages
controller handles displaying content specific pages user may call. controller this:
class page extends ci_controller { public function index() { // logic render home page } public function about() { // logic render page } // ... etc ...
views can little tricky when you're dealing complex sites have overlap. 1 of useful tricks i've discovered along way using emplating library cut down redundancy. 1 utilize time: http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html . using template library can define layout includes header , footer , pass in partial content want display.
when want deal logic in menu, need pass in variable page name , basic php render menu.
// pass in variable called $current our view // $current contains name of current page // $current = 'about' example. $sitemenu = array( array('/', 'home'), array('/about', 'about'), array('/help', 'page 2'), array('/contact', 'page 3') ); ?> <nav> <ul> <?php foreach( $sitemenu $page) { ?> <?php if($current == $page[1]) { ?> <li class="current"><a href="<?php echo $page[0]; ?>"><?php echo $page[1]; ?></a></li> <?php } else { ?> <li><a href="<?php echo $page[0]; ?>"><?php echo $page[1]; ?></a></li> <?php } ?> <?php } ?> </ul> </nav>
hope helps!
codeigniter nested controllers
Comments
Post a Comment