Page 1 of 1

Framework Components

Posted: Wed Dec 24, 2008 9:33 pm
by Syntac
What components do you consider absolutely essential for a good framework? (More specifically, models and views.)

Re: Framework Components

Posted: Thu Dec 25, 2008 1:33 pm
by Theory?
Authentication, database interaction, some sort of generic CRUD functionality maybe?

Re: Framework Components

Posted: Thu Dec 25, 2008 9:44 pm
by Christopher
Syntac wrote:What components do you consider absolutely essential for a good framework? (More specifically, models and views.)
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?

Re: Framework Components

Posted: Thu Dec 25, 2008 10:03 pm
by Syntac
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.

Re: Framework Components

Posted: Thu Dec 25, 2008 11:17 pm
by Christopher
Syntac wrote:CRUD functionality,
Table Data Gateway is a good start
Syntac wrote:HTML generation,
Templates or OO SQL
Syntac wrote:data validation,
Validators (and Filters too)
Syntac wrote:and the like.
it's a long list if you want to get at all specific.

Re: Framework Components

Posted: Fri Jan 02, 2009 3:39 am
by The_Anomaly
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.

Re: Framework Components

Posted: Fri Jan 02, 2009 7:12 am
by Weirdan
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?
Isn't it easy to create yourself? I mean it's not that hard, really:

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

Posted: Fri Jan 02, 2009 9:01 am
by josh
active record with meta data

Re: Framework Components

Posted: Fri Jan 02, 2009 12:20 pm
by Luke
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.

Re: Framework Components

Posted: Fri Jan 02, 2009 2:22 pm
by Syntac
I think I've implemented all of that. Partayyyy! :D

Re: Framework Components

Posted: Fri Jan 02, 2009 3:59 pm
by josh
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

Re: Framework Components

Posted: Tue Jan 06, 2009 2:42 pm
by The_Anomaly
Weirdan wrote:
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?
Isn't it easy to create yourself? I mean it's not that hard, really:

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.