Structuring My Application

I have an existing application (American Football Results Picking Competition) (its on github under my akc42 account called MBBall, but since this is my first post I can’t embed a link to it). Its been in operation for about 4 years on a yearly basis.

As part of a between season revamp, and as a way of trialing the yii framework, I have just started to look at how I might implement it using Yii. I AM BRAND NEW TO YII, although I have been through lots of vidoe tutorials and read the guide cover to cover, I have yet to do any actual coding. I am now planing my attack on the application

It basically consists of just two pages. The first is the general participants page and allows them to pick results, and see their current progress in the competition. This consists of 6 major sections, two of these are optional input sections, the remainder are complicated query results sections for parts of the competition. There is a little bit of Javascript/backend PHP to support the input section.

The second is the administrators panel, which is more or less loaded piece by piece by the javascript (Mootools based). Each panel is loaded and reloaded dynamically (ie the Ajax request contains the new html to be included within the page) with changes the administrator makes, and within each panel the data can be changed dynamically by the javascript application (and sends data back to backend scripts to update the database).

I use a mini templating system to effectively surround the pages with the header, menu and footer.

I would like some advice (for now) about the first of these two pages. I am quite confused about how I should be splitting these 6 sections up into elements. Ideally, each element should have its own model and associated view, controlled by a single controller. But each view seems to get surrounded by the layout, whereas I would want the layout over the whole lot.

The other possibility is to implement each of the sections as a widget, but I don’t quite see how I can join widgets and models together.

Can someone give me a thumbnail sketch of the right approach and point me at some documentation that can get be started down the recommended path

Thank you.

Read the MVC section of the guide and start thinking about how to represent your entities. How many database tables are we talking about?

Most sites are little more than a table (or multiple related ones) expressed as models with a view as an interface to that. Multiple models can be handled in a single view. It would help having a little idea of how the app is currently structured from a data standpoint to answer your question better.

As I said, there are 6 sections on the one page. The most complicated section, is a summary which actually involves a query which joins views and table which ends up with 6 tables joined and then repeated for each user (so I might also have joined one more table). The result of all of that though is just a 2d table of values, so the model for that section will just deliver that 2D table.

The structure I think I need is a controller which can utilise 6 models to deliver the content for 6 views. But I don’t understand what the recommended way to do that within yii when its all on one page, especially as it needs to fit within a single layout (which - when I’ve learn’t about it - will be themed).

I’m also new to yii.

Why not use your own widgets ?

Think in terms of what data you are passing to the view. You can certainly execute raw SQL in your controller which manually joins several tables and indeed for a view-heavy application that may be appropriate. Otherwise, you create a model for each table (use Gii) and relate them via the relations() declaration in each.

It sounds like with 6 sections you might be passing 6 different model objects to a view and displaying each ‘section’ as a partial view.

Or as the other guy said, use widgets for each section.

The way the layouts work is that everything you generate in code gets wrapped as $content within your main layout view. So don’t worry too much about how to present your template at this point - that isn’t part of your application code, that is really getting into layouts.

My existing code already has a top level index.php controlling the page layout, it then calls (via require_once) separate php files for each of my 6 sections

I can deal with the model and view separation - my existing code in these separate php files is a spaghetti of model and view code mixed together, I’ll just create a model with my existing database access stuff returning results in an array, and then take a copy of the existing code and turn it into a view, replacing the existing query results with the array stuff.

Its this bit I didn’t really understand. I couldn’t understand views with partialRender (I assume that is what you meant by partial views) nor could I understand this bit about widgets

<?php $this->beginWidget(’’, array(


’property2’=>’value2’)); ?>

...body content of the widget...

<?php $this->endWidget(); ?>

Because I didn’t understand that that embedded body content was not being rendered at that time.

However I just discovered and that helps me understand it much better.

I think I am good to go. Thanks for your help.