I am new to Yii and trying to port an existing PHP application to use Yii. But I am having trouble getting started.
There are three initial issues that are puzzling me.
First - how does Yii create the database structure. I see a file in the data directory called schema.sqlite.sql which is used to setup the database. In my existing application I have some code like this
if(!file_exists(AIR_HOCKEY_DATABASE.AIR_HOCKEY_VARIANT.'.db')) {
$db = new PDO('sqlite:'.AIR_HOCKEY_DATABASE.AIR_HOCKEY_VARIANT.'.db');
$db->exec(file_get_contents('./database.sql'));
} else {
$db = new PDO('sqlite:'.AIR_HOCKEY_DATABASE.AIR_HOCKEY_VARIANT.'.db');
}
and then later, allowing for potential updates to the database structure
$result = $db->query("SELECT count(*) FROM sqlite_master WHERE name = 'config' ;");
if(!($result && ($present = $result->fetchColumn()) && $present == '1')) {
//NO CONFIG TABLE - so database must be at version 1 - update to version 2
$result->closeCursor();
$db->exec(file_get_contents('./update1.sql'));
} else {
$result->closeCursor();
}
Where in the yii framework should I put this stuff?
The second issue I have is that I need to make my menu dynamic, reading a database query. I need to read a the database and create a list of menu items (and the second level) from a table in the database. In the default application built by yiic the menu is in the layout. with a call to
$this->widget('zii.widgets.CBreadcrumbs' ...
How am I supposed to setup to correct data for it to draw a dynamic menu?
The last issue I have is that the default page (ie the site/index action) should comprise several sections, which should ideally be a separate model and view.
But I don’t understand how I should do that. If it was just one view then site controller does
$this->render('index');
but this causes the layout to surround it which is fine.
But if I did
$this->render('part1');
$this->render('part2');
Then I would get two sets of layout. But if I did
$this->renderPartial('part1');
$this->renderPartial('part2');
I presume I have no layout. So what am I supposed to do.