Jump to content
Larry Ullman's Book Forums

Putting A Nested Mysql Report Into The Correct Yii Context

Recommended Posts

Hi all.


So I'm a Yii learner. Just completed YiiBook which I really enjoyed. I'm now trying to put its principles into practise, however i'm still not fully getting the  "mindset" so I need to turn to the experts for help. Goes like this


// assign

// get topic
$topic = Yii::app()->db->createCommand()
->select('id, parent_id, name, description, url')
->where('silo.id = '.$id.'')

<img class="title" src="<?php echo $topic[0]['url']; ?>" width="300" height="200" />
<div id="headline"><strong><?php echo $topic[0]['name']?></strong><em> Magazine</em></div>

$subtopics = Yii::app()->db->createCommand()
->select('id, parent_id, name, description')
->where('silo.parent_id = '.$id.'')

// read out
for ($x = 0 ; $x < count($subtopics) ; $x++)
// query
$entries = Yii::app()->db->createCommand()
->Join('entry', 'entrysilo.entry_id = entry.id')
->where('entrysilo.silo_id = '.$subtopics[$x]['id'].'')

// title
print "<fieldset>";
print "<h3>" . $subtopics[$x]['name'] . "</h3>";
print '<div id="h3description">' . $subtopics[$x]['description'] . '</div>';

// read entries out
for ($y = 0 ; $y < count($entries) ; $y++)
print '<a href="http://domain/index.php?r=entry/view&id='.$entries[$y]['id'].'">' . $entries[$y]['title'] . '</a>';
print '<br/>';
print '<div id="description">' . $entries[$y]['entry_description'] . '</div>';
print "</fieldset>";


I have a report that runs a number of individual and nested MySQL queries before producing a newspaper type report. In my ignorance I first built this into a view utilising Query Builder. This works OK, but as Larry points out on page 20, this should really go into the model. trouble is that I can't find any examples of how I should go about building a nested query in the model, then reading it out to a layout.


I'd really appreciate your advise

thanks in advance

Link to post
Share on other sites

This stuff is definitely covered in Larry's Yii book, you really need to get more into it. I could give some examples but there are so many variations of doing something. I also need to correct some of my own code as later on i found better ways of doing things, Yii takes time and experience to learn, the best way is to get your hands dirty. Don't worry too much about being perfect right now, just have a play around and things will fall in to place. Yeah my best advise for you is to work through the Yii Book, i think the Yii Definitive guide is also good it can make you see things from another angle, which on some occasions can help. If i was to explain stuff to you here it might not make a lot of sense right now until you have a firm grasp of the basics of Yii and its Model View Controller infrastructure.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...