Question on Solving Dynamic Menu System

I set up a simple menu system that allows users to add menu items on the site.

Came across a design issue with determining the main landing page, deleting the breadcrumbs, and if it is active or not.

The only solutions I can think up are hacks, any suggestions? Seems like some of the guys on here who have spent time developing a Yii CMS could point me in the right direction.

Here is my index action on my SiteController:


  /**

   * This is the default 'index' action that is invoked

   * when an action is not explicitly requested by users.

   */

  public function actionIndex()

  {

    $criteria = new CDbCriteria();

    $criteria->order = 'isLandingPage DESC, ordering ASC, id DESC';

    $menuItem = MenuItem::model()->find($criteria);


    $page = $menuItem->page;

    if ($page != null)

    {

      $clientScript = Yii::app()->clientScript;

      $clientScript->registerMetaTag($page->description, 'description');

      $clientScript->registerMetaTag($page->keywords, 'keywords');


      $this->render('/page/view', array('model' => $page));

    }

    else

    {

      $this->redirect(array($menuItem->url));

    }

  }

here is my layout:


	<div id="mainmenu">

    <?php

      $menuItems = MenuItem::model()->ordered()->findAll();

      $items = array();


      foreach ($menuItems as $menuItem)

      {

        $items[] = $menuItem->toMenuItem();

      }

    ?>

    <?php $this->widget('zii.widgets.CMenu',array('items'=>$items)); ?>

	</div><!-- mainmenu -->


	<?php $this->widget('zii.widgets.CBreadcrumbs', array(

		'links'=>$this->breadcrumbs,

	)); ?><!-- breadcrumbs -->


	<?php echo $content; ?>

It looks good, what are the hacks that you want to improve?

Looks absolutely normal and good written code… at least at my hacker’s eyes…

For instance, i’d like to hide the breadcrumbs on the index. Can’t really figure out a clean way to accomplish this. Not only does it have to hide the crumbs for the pages, but also for modules (so the logic can’t only reside in the page view or controller).

The cleanest way I can think of is to do some operation in the parent Controller’s afterAction() to check to see if the current page is the landing page. Seems like an unnecessary performance hit for each page load though.

[delete this reply]