Framework Components
Moderator: General Moderators
Framework Components
What components do you consider absolutely essential for a good framework? (More specifically, models and views.)
Re: Framework Components
Authentication, database interaction, some sort of generic CRUD functionality maybe?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Framework Components
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.)
(#10850)
Re: Framework Components
Just models and views at the moment. I'm going for a "bare-bones" sort of list here. You know, CRUD functionality, HTML generation, data validation, and the like.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Framework Components
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.
(#10850)
- The_Anomaly
- Forum Contributor
- Posts: 196
- Joined: Fri Aug 08, 2008 4:56 pm
- Location: Tirana, Albania
Re: Framework Components
Pagination is really sweet when it's done right.
The following is just something that I thought of when I was irritated with writing domain objects for tables in my database. In my other thread, we have the Note, which has a bunch of properties, say, 20. I make the table in the database first, and then I sit down for half an hour and basically just copy all of the properties, and make standard getters and setters for each one. It's a real pain.
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?
EDIT: Ugh, I just read "Absolutely necessary," in the OP. Feel free to ignore this post, as it's most definitely not "Absolutely necessary," but still, I'd use it literally all the time.
The following is just something that I thought of when I was irritated with writing domain objects for tables in my database. In my other thread, we have the Note, which has a bunch of properties, say, 20. I make the table in the database first, and then I sit down for half an hour and basically just copy all of the properties, and make standard getters and setters for each one. It's a real pain.
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?
EDIT: Ugh, I just read "Absolutely necessary," in the OP. Feel free to ignore this post, as it's most definitely not "Absolutely necessary," but still, I'd use it literally all the time.
Re: Framework Components
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";
Re: Framework Components
active record with meta data
Re: Framework Components
Well, absolutely necessary is really a matter of opinion. To me, absolutely necessary means, if it the framework doesn't have it, I would use something else. Here are things I find necessary when building an application:
View:
Template system - this doesn't have to be a whole template engine or anything, just need two things. First, layouts. I need to be able to specify a layout for every view that is rendered. Second, I need to be able to set conext variables for every view. I just use the template syntax in php for view scripts
Model:
DAO - a simple class with CRUD methods for a given table/model
Model - a class that uses the DAO to create more abstract methods such as "User::createAdmin()", "Article::createDraft()", "Article::getAllWithinDateRange($datestart, $dateend)" etc.
View:
Template system - this doesn't have to be a whole template engine or anything, just need two things. First, layouts. I need to be able to specify a layout for every view that is rendered. Second, I need to be able to set conext variables for every view. I just use the template syntax in php for view scripts
Model:
DAO - a simple class with CRUD methods for a given table/model
Model - a class that uses the DAO to create more abstract methods such as "User::createAdmin()", "Article::createDraft()", "Article::getAllWithinDateRange($datestart, $dateend)" etc.
Re: Framework Components
I think I've implemented all of that. Partayyyy! 
Re: Framework Components
The components aren't as important as what each can do. Your controller should support:
template method for hooking controller construction
plugin / "filter" support
integration with view object
forwarding
Various methods of routing in the FC to the controller, including regex routes, and ideally support "backwards URL construction" where I can generate URLs with parameters, using the router - to centralize URL handling
These are just some more things I consider "essential"
Other cool things would be "out of the box" plugins / action helpers like action Stack, view rendering, ACL + auth support & integration, etc
template method for hooking controller construction
plugin / "filter" support
integration with view object
forwarding
Various methods of routing in the FC to the controller, including regex routes, and ideally support "backwards URL construction" where I can generate URLs with parameters, using the router - to centralize URL handling
These are just some more things I consider "essential"
Other cool things would be "out of the box" plugins / action helpers like action Stack, view rendering, ACL + auth support & integration, etc
- The_Anomaly
- Forum Contributor
- Posts: 196
- Joined: Fri Aug 08, 2008 4:56 pm
- Location: Tirana, Albania
Re: Framework Components
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";