Programming approach

Hello everyone, i am new in yii although not new in programming in general. My question to all of you is related of how should i model a piece of code according to the yii’s way of organization (3-tier)

I wanted to have a permanent menu inside my website. in fact this menu is database driven. So the first thing is to have a class for this menu which is pretty straight-forward.

To have a function that renders a submenu is the most simple way to do it. Although I do not think it is appropriate for yii. So what I did was to create a controller, a certain action for this controller which will render a submenu and finally of course a view, which will be rendered with the renderPartial function since I do not want an entire new page to load.

Previously I would have an ajax call to some php file to render the menu and get my (dynamic) submenu. Now, with the second approach, I have the ajax call something like "index.php?r=menu/action&menuid=1"

Is this a reasonable way to do it or am I being paranoid and there is a much simpler solution?

I am still trying to adapt to the whole Model-Controller-View way of programming :)

Thank you all, this is my first topic!

Sounds OK to me.

thanks for the feedback samdark :)

Your usage description would be a better fit for a widget rather than a normal controller/view. Controllers are best left to handle application actions, such as loging in or viewing user details.

In my application I have extended CMenu in few places this sort of behavior, loading various menu options based on a DB query. I’ll also mention that in my usage case, it was better performance wise to load various options from the DB and into the session, to avoid hitting the DB on every page request.