Framework Components
Posted: Wed Dec 24, 2008 9:33 pm
What components do you consider absolutely essential for a good framework? (More specifically, models and views.)
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
That could be a very long list if you actually want to itemize the many different things needed for a web app framework! Are you looking for the major functionality for models, views and controllers?Syntac wrote:What components do you consider absolutely essential for a good framework? (More specifically, models and views.)
Table Data Gateway is a good startSyntac wrote:CRUD functionality,
Templates or OO SQLSyntac wrote:HTML generation,
Validators (and Filters too)Syntac wrote:data validation,
it's a long list if you want to get at all specific.Syntac wrote:and the like.
Isn't it easy to create yourself? I mean it's not that hard, really:The_Anomaly wrote:Could there be some framework component that would get the names of all of the columns, and then create a domain object with each of the columns as properties, and then a getter and setter for each?
Code: Select all
#!/usr/bin/php
function help() {
global $argv;
return <<<EOF
Usage: $argv[0] <TableName> > class.php
EOF;
}
if ($argc < 2) {
die(help());
}
$tableName = $argv[1];
mysql_connect('localhost', 'root', '');
mysql_select_db('database');
$classDesc = new stdClass;
$classDesc->className = $tableName;
$classDesc->properties = array();
$fieldsResult = mysql_list_fields('database', $tableName);
for ($i = 0, $l = mysql_num_rows($fieldResult); $i < $l; $i++) {
$classDesc->properties[] = mysql_field_name($fieldsResult, $i);
}
echo 'class ' . $classDesc->className . ' extends BaseObject {' . "\n"; // class opening
// properties
foreach ($classDesc->properties as $property) {
echo 'protected ' . $property . ' = null;' . "\n";
}
// setters and getters
foreach ($classDesc->properties as $property) {
echo 'public function get' . ucfirst($property) . '() {' . "\n";
echo ' return $this->' . $property . ';' . "\n";
echo '}' . "\n";
echo 'public function set' . ucfirst($property) . '($value) {' . "\n";
echo ' $this->' . $property . ' = $value;' . "\n";
echo '}' . "\n";
}
// class closing
echo '}' . "\n";
Sweet. Thanks for throwing that together--you're right, I should have thought to do it myself.Weirdan wrote:Isn't it easy to create yourself? I mean it's not that hard, really:The_Anomaly wrote:Could there be some framework component that would get the names of all of the columns, and then create a domain object with each of the columns as properties, and then a getter and setter for each?Code: Select all
#!/usr/bin/php function help() { global $argv; return <<<EOF Usage: $argv[0] <TableName> > class.php EOF; } if ($argc < 2) { die(help()); } $tableName = $argv[1]; mysql_connect('localhost', 'root', ''); mysql_select_db('database'); $classDesc = new stdClass; $classDesc->className = $tableName; $classDesc->properties = array(); $fieldsResult = mysql_list_fields('database', $tableName); for ($i = 0, $l = mysql_num_rows($fieldResult); $i < $l; $i++) { $classDesc->properties[] = mysql_field_name($fieldsResult, $i); } echo 'class ' . $classDesc->className . ' extends BaseObject {' . "\n"; // class opening // properties foreach ($classDesc->properties as $property) { echo 'protected ' . $property . ' = null;' . "\n"; } // setters and getters foreach ($classDesc->properties as $property) { echo 'public function get' . ucfirst($property) . '() {' . "\n"; echo ' return $this->' . $property . ';' . "\n"; echo '}' . "\n"; echo 'public function set' . ucfirst($property) . '($value) {' . "\n"; echo ' $this->' . $property . ' = $value;' . "\n"; echo '}' . "\n"; } // class closing echo '}' . "\n";