menus - db driven or static

How would you solved this:

db schema:

project may have 1 or many - risks, issues, bugs, change requests, etc…

risks, issues, bugs, change requests must be associated with at least one project.

How would you create the menu to navigate from the project to the risk, issues, and back…

Would it be static menus in all views, or db driven? need direction. A bit confused. I am following the yii agile web development book, but not enough info.

Any examples?

Not sure what you meant but if you are using the book, try searching for solutions here:

http://www.yiiframework.com/forum/index.php/forum/38-agile-web-application-development-with-yii11-and-php5/

sometimes you’ll find answers

You can retrieve the risks, issues, bugs, … etc that belong to the current project.

So, the menu for the current project can be constructed like …




$items = array();

foreach($risks as $risk){

    $items[] = array(

        'label'=>'risk:' . $risk->name,

        'url'=>array('risk/view', 'id'=>$risk->id)

    );

}

foreach($issues as $issue){

    $items[] = array(

        'label'=>'issue:' . $issue->name,

        'url'=>array('issue/view', 'id'=>$issue->id)

    );

}

....

$this->widget('zii.widgets.CMenu', array(

    'items'=>$items,

));



Or, if you would like a nested menu …




$items = array(

    'risk' = array(

        'label' => 'Risks',

    ),

    'issue' = array(

        'label' => 'Issues',

    ),

    ....

);

foreach($risks as $risk){

    $items['risk']['items'][] = array(

        'label'=>$risk->name,

        'url'=>array('risk/view', 'id'=>$risk->id)

    );

}

foreach($issues as $issue){

    $items['issue']['items'][] = array(

        'label'=>$issue->name,

        'url'=>array('issue/view', 'id'=>$issue->id)

    );

}

....

$this->widget('zii.widgets.CMenu', array(

    'items'=>$items,

));



I’m not sure what you want for your menu to look like, but something like those will do the job.

And, this is just a personal opinion, but … if I were you, I would not use a menu widget for the links, because I can not tell how many links I have to handle with the target project. I’d rather use some CGridViews (or CListViews) for the risks, issues, … etc that will show the short descriptions and the links to the detailed informations.

Thanks but that is not what i mean…

i am a bit confused about how to generate and structure menus.

I am aware of cmenu, cgridview, etc… But the way i am reading the book above and the way GII generates menus, it seems that they are hardcoded which does not make sense to me.

So suppose when i view a project, then the menu opens up and display all options available (view all, create risks, view all, create issues, etc…) How do you handle this. Looking for examples to guide me. thanks.

What do you exactly mean by “hardcoded” ? Gii is just a template-based code generator for CRUD. It can’t figure out the details of business logic and workflow of your application - but the generated menus can be customized easily.

Also, since CMenu works with arrays you can dynamically add elements to your menus depending on the page you are on. You can have a ‘base’ menu for the site and add additional elements to those menus with each page.

Ok i see. But then please explain how i can indicate which screen the user is on?

If you don’t mind, a code example would be helpful as i learn from visuals.

Sorry about these questions, still green…