V, I've got. Let's do M and maybe I'll end up with a C.
September 13, 2011 2:08 PM Subscribe
I'm learning PHP and MySQL, trying to work from scratch before I ramping up to a framework. I've installed a templating system, just to play with it, so my templating/view logic feels well-organized. But how do I organize the other simple DB query code so it's more MVC-ish?
posted by circular to computers & internet (17 answers total) 2 users marked this as a favorite
I'm using a template engine, and I end up with this in my index.php:
// Include template (view) class for TinyButStrong
$TBS = new clsTinyButStrong;
$site_title = 'Weights and Measures!';
// This would be considered model logic, I think -- (how) do I spin this off into another class file(s) or something?
$sql = 'SELECT * FROM billings';
$cur_month = date("m");
$month_minus_one = date("m") - 1;
$month_minus_two = date("m") - 2;
$cur_month_sql = 'SELECT * FROM billings WHERE MONTH(DATE) = '.$cur_month;
$month_minus_one_sql = 'SELECT * FROM billings WHERE MONTH(DATE) = '.$month_minus_one;
$month_minus_two_sql = 'SELECT * FROM billings WHERE MONTH(DATE) = '.$month_minus_two;
// MergeBlock is sending data from the database to the template engine, so I can reference the data in the template/view with the template engine's tags.
$TBS->MergeBlock('billings, billings2, billingsjs', $Db->GetRows($sql));
Any advice appreciated. I know people disagree about templating classes vs. plain PHP, and I know that a framework is SO worth it. But this is the path I've chosen for my next exercise and I'd like to see it through. Thanks!