Recommend this page to a friend! |
Classes of Will Tinsdeall | Boiler Framework | README | Download |
|
Download To install simply move htdocs to your public html directory, then set BOILER_LOCATION on line 3 of index to point to the framework folder. Controllers are the start point of your page. Testing and BuildingBuilding and testing (optional) is done with a build.xml make file for "ant". You may also consider using the following to help test your code. The following tools have a config shipped with ant targets, and are fully compatible with Hudson/Jenkins CI
pear channel-discover pear.phpmd.org pear channel-discover pear.pdepend.org pear install --alldeps phpmd/PHP_PMD
pear install PHP_CodeSniffer
pear channel-discover components.ez.no pear install phpunit/phpcpd
pear channel-discover pear.phpunit.de pear channel-discover pear.symfony-project.com pear install phpunit/PHPUnit
pear install phpunit/PHPUnit_SkeletonGenerator CONTROLLERS-Namespacing follows folder structure to allow PHP lazy loading (please see php.net for Namespacing and __autoload) -All classes must be namespaced with Controller. This is to allow you to have a controller and model, for example, with the same name. -Functions being called must be public -First letter only of class is capitalized Examples: http://localhost/class/function/args1/args2/args3 Would execute: $c = new \Controller\Class(); $c->function(args1, args2, args3); http://localhost/ns1/ns2/ns3/class/function Would Execute: $c = new \Controller\ns1\ns2\ns3\Class(); $c->function(); MODELS-Models should extend DBObject normally for MySQL objects -Models must be namespaced -DBObject class (found in application/model/DBObject.php) must have login details entered for PHP <?php namespace Model; class MySQLTable extends DBObject {
} //That's it! No SQL! Your MySQL settings are retrieved from a config.php file, built by ant. This stops you committing your MySQL details to git - pretty irritating! ?> More advanced functions: N.B. This is a demo which came from when the framework was not namespaced. <?php ini_set('display_errors', "On"); include "Linq.php"; include "DBObject.php"; /* Employee */ class Employee extends DBObject {
} /* LINK TABLE to stop many-to-many between Employee and Job */ class EmployeeJob extends DBObject {
} /* Jobs table */ class Job extends DBObject {
} // class LinqDB extends mysqli, so feel free to use it as mysqli too! //Lets use it to setup some temp tables
$db = LinqDB::getDB("mysql.bcslichfield.com", "star241_6", "devpasswd123=", "bcslichfield_dev");
$db->query("CREATE TEMPORARY TABLE IF NOT EXISTS $db->query("CREATE TEMPORARY TABLE IF NOT EXISTS $db->query("CREATE TEMPORARY TABLE IF NOT EXISTS ) ENGINE=InnoDB"); /* For debug (not applicable on temporary tables): FOREIGN KEY ( /* Once upon a time, in a factory far away there were three workers! */ $me = Employee::Create(array("name"=>"Will Tinsdeall")); $bob = Employee::Create(array("name"=>"Bob Bloggs")); $joe = Employee::Create(array("name"=>"Joe Bloggs")); /* And my AUTO_INCREMENT ID was: */ echo "TEST 1: ".$me->id."\r\n"; /* In the factory there were many jobs */ $joba = Job::Create(array('name'=>'A very hard job')); $jobb = Job::Create(array('name'=>'An average job')); $jobc = Job::Create(array('name'=>'An easy job')); /* And we all had jobs */ $me->giveJob($joba); $me->giveJob($jobb); $bob->giveJob($joba); $bob->giveJob($jobc); $joe->giveJob($jobb); $joe->giveJob($jobc); /* First of all the boss wanted to know all the jobs that were being done */ foreach (Job::getAll() as $j) {
} /* Next, he decided to quickly call me */ $me = new Employee("1"); /* And asked me to check to see who was working well. */ $db->Select(Employee); /* This consisted of people EITHER: */ $db->getOrFilter(); /* Those doing a medium job only */ $jobs = $db->Select(EmployeeJob);
$jobs->addCount("jobs");
$jobs->addField("employee");
$jobs->addField("job");
$jobs->setGroup("employee");
/SELECT COUNT() as jobs, employee FROM /* Or those doing an easy job and a very hard job */ $jobsB = $db->Select(EmployeeJob); $jobsB->addField("employee"); $jBFilter = $db->getAndFilter(); $jBFilter->eq('job', 1)->eq("job", 3); $jobsB->setFilter($jBFilter); //XXX this would work if the tables weren't temporary! /* $u = $db->Union(); $u->addSelect($jobsB)->addSelect($jobs); echo $u->getSQL(); */ $out = array(); foreach (array_merge($jobsB->Exec(), $jobs->Exec()) as $a) {
} var_dump($out); /* Lastly he wanted a to assess everyone at their jobs (simple JOIN) */ $qEmployee = $db->Select(Employee); $qEmployeeJob = $db->Select(EmployeeJob); $qJob = $db->Select(Job); $qEmployeeJob->joinLeft("employee", $qEmployee, "id"); $qEmployeeJob->joinLeft("job", $qJob, "id"); var_dump($qEmployeeJob->Exec()); ?> |