Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with MVC example. 2

Status
Not open for further replies.

petrosky

Technical User
Aug 1, 2001
512
AU
Hi there,

I am following this tutorial in an effort to have a better understanding of MVC frameworks.


Alas I have downloaded the files but I can find no way to call data from a model.

The example merely shows hard-coded vars in the controller file.

If anyone has time to have a look, I'd appreciate any help you may be able to offer.

Thanks.

Remember- It's nice to be important,
but it's important to be nice :)
 
Hi,
I have just finished a project using this. It is more of a Controller View system from what I can gather.

Here is an example controller that passes orders and loads up the view file.

Code:
public function index() 
{
	try {
	$registry->db = db::getInstance();
	$qry = $registry->db->prepare('select * from employees');
	$qry->execute();
	$rst = $qry->fetchAll();
	$this->registry->template->rst = $rst;
	$this->registry->template->show('employees');
	$db = null;
	} 
	catch (PDOException $e)
	{
	echo $e . ' ' . 'Fail';
	}
}

Then I just loop through the results in the view.

Code:
	<?php foreach($rst as $k => $v):?>

Somehow I feel I'm missing something as the controller should generally "ask" the model/s for the data then load up the view...

Anyway it works and keeps code separated.

Regards,
petrosky




Remember- It's nice to be important,
but it's important to be nice :)
 
don't get hung up on the 'purity' of what each aspect of an MVC model should do. The basic concept is simply to separate (as far as easily practicable) the aspects of each application that are most often in different person's responsibility.

basic premise is:

1. keep the presentation layer as separate as possible from the application layer. but don't go overboard. there is no reason not to have loop code and conditional logic in a presentation template, for example.
2. keep the database layer separate from the application layer. typically I use a further abstraction layer from PDO and then inherit the abstraction class in each of my entity classes. This works very well when there are nicely defined entities and is still usable (via pseudo anonymous classes) for less structured applications. But again I don't take this to a purist level in that I like each entity class to know about its own data structure.
3. keep the application layer in a logically consistent form so that you can easily remember what and how you did something and that others can easily derive the same. Here I have a bunch of library functions and classes that I store in a library folder (and that are always included()) but all the controller-type code tends to be in one file for me, as I use a despatch method for application design. On smaller screens, this can result in quite a bit of scrolling to get to the right place in the switch statement. I have also known it to cause debugging issues when tired eyes don't spot the right bit ... I do not usually spin out from a switch statement into a separate function as I design my entities with intelligence about themselves; so typically all that is needed is a call to create the right entity; pass it some data; tell it to do something and then show the results. this can usually be done in less than 10 lines of code and I prefer to keep that within the switch rather than outside.

the point is simply this: MVC is a construct of convenience and good practice. But there is no requirement at all to be slavish to it. 'best practice' must take into account your coding style and preferences too. Also, as a last thought, some MVC layers like the zend framework are sub-optimal (imo); because in order to do a single task they are having to open and parse 23 or more included files. that's slow work for php as disk access, file read, parsing and execution (perhaps) are needed on many different files. You might not see a problem/slow down with that on a dev machine running a couple of threads. but I suspect that all that disk access would soon become an issue on a busy server.
 
Hi jpadie,
Thanks (again) for your insightful and detailed reply. Another reason why Tek-tips is a great site. I've found threads of mine on google searches.

Regards,
Petrosky

Remember- It's nice to be important,
but it's important to be nice :)
 
@petrosky
to give you a better example, let's say that we take your employee table and that it has some standard data like first/last name, email address and employee number

the table might look like this

Code:
create table [b][COLOR=#000000]employees[/color][/b] [COLOR=#990000]([/color]
employeeID [b][COLOR=#000000]int[/color][/b][COLOR=#990000]([/color][COLOR=#993399]10[/color][COLOR=#990000])[/color] primary key auto_increment[COLOR=#990000],[/color]
employeeFirstName [b][COLOR=#000000]varchar[/color][/b][COLOR=#990000]([/color][COLOR=#993399]255[/color][COLOR=#990000]),[/color]
employeeLastName [b][COLOR=#000000]varchar[/color][/b][COLOR=#990000]([/color][COLOR=#993399]255[/color][COLOR=#990000]),[/color]
employeeEmailAddress [b][COLOR=#000000]varchar[/color][/b][COLOR=#990000]([/color][COLOR=#993399]255[/color][COLOR=#990000])[/color]
[COLOR=#990000]);[/color]

and then the entity might look like this

Code:
[b][COLOR=#0000FF]class[/color][/b] employee [b][COLOR=#0000FF]extends[/color][/b] base[COLOR=#FF0000]{[/color]
[tab]
[tab]public [COLOR=#009900]$fields[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color]
[tab][tab][COLOR=#FF0000]'employeeID'[/color][COLOR=#990000],[/color]
[tab][tab][COLOR=#FF0000]'employeeFirstName'[/color][COLOR=#990000],[/color]
[tab][tab][COLOR=#FF0000]'employeeLastName'[/color][COLOR=#990000],[/color]
[tab][tab][COLOR=#FF0000]'employeeEmailAddress'[/color]
[tab][COLOR=#990000]);[/color]
[tab]public [COLOR=#009900]$primary[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]'employeeID'[/color][COLOR=#990000];[/color]
[tab]public [COLOR=#009900]$table[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]'employees'[/color][COLOR=#990000];[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]__construct[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab]parent[COLOR=#990000]::[/color][b][COLOR=#000000]__construct[/color][/b][COLOR=#990000]();[/color]
[tab][COLOR=#FF0000]}[/color]
[tab][tab]
[COLOR=#FF0000]}[/color]

so you see that this (bare minimum) entity knows about its data and that's about it. we might want it to do more later but this is a minimum.

now to look at the base class, which is my db abstraction layer. again, keeping it simple

Code:
[COLOR=#990000]<?php[/color]

[b][COLOR=#0000FF]class[/color][/b] base [COLOR=#FF0000]{[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]__construct[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]load[/color][/b][COLOR=#990000]();[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]getPrimary[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]return[/color][/b] [COLOR=#990000]![/color][b][COLOR=#0000FF]empty[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color][COLOR=#FF0000]{[/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]primary[COLOR=#FF0000]}[/color][COLOR=#990000])[/color] [COLOR=#990000]?[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][COLOR=#FF0000]{[/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]primary[COLOR=#FF0000]}[/color] [COLOR=#990000]:[/color] false[COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]save[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]getPrimary[/color][/b][COLOR=#990000]()[/color] [COLOR=#990000]===[/color] false[COLOR=#990000]):[/color]
[tab][tab][tab][b][COLOR=#0000FF]return[/color][/b] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]insert[/color][/b][COLOR=#990000]();[/color]
[tab][tab][b][COLOR=#0000FF]else[/color][/b][COLOR=#990000]:[/color]
[tab][tab][tab][b][COLOR=#0000FF]return[/color][/b] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]update[/color][/b][COLOR=#990000]();[/color]
[tab][tab][b][COLOR=#0000FF]endif[/color][/b][COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]insert[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]global[/color][/b] [COLOR=#009900]$pdo[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$params[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]();[/color]
[tab][tab][COLOR=#009900]$sql[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]"INSERT into {$this->table} SET "[/color][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]foreach[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]fields [b][COLOR=#0000FF]as[/color][/b] [COLOR=#009900]$key[/color][COLOR=#990000]=>[/color][COLOR=#009900]$field[/color][COLOR=#990000]):[/color]
[tab][tab][tab][COLOR=#009900]$fields[/color][COLOR=#990000][][/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]"`$field` = :{$field}"[/color][COLOR=#990000];[/color]
[tab][tab][tab][COLOR=#009900]$params[/color][COLOR=#990000][[/color][COLOR=#009900]$field[/color][COLOR=#990000]][/color] [COLOR=#990000]=[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][COLOR=#FF0000]{[/color][COLOR=#009900]$field[/color][COLOR=#FF0000]}[/color][COLOR=#990000];[/color] 
[tab][tab][b][COLOR=#0000FF]endforeach[/color][/b][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$query[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$sql[/color] [COLOR=#990000].[/color] [b][COLOR=#000000]implode[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]','[/color][COLOR=#990000],[/color] [COLOR=#009900]$fields[/color][COLOR=#990000]);[/color]
[tab][tab]
[tab][tab][COLOR=#009900]$s[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$pdo[/color][COLOR=#990000]->[/color][b][COLOR=#000000]prepare[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$query[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$s[/color] [COLOR=#990000]==[/color] false[COLOR=#990000])[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]bail[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$pdo[/color][COLOR=#990000]->[/color][b][COLOR=#000000]errorInfo[/color][/b][COLOR=#990000]());[/color]
[tab][tab][COLOR=#009900]$r[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]execute[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$params[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$r[/color] [COLOR=#990000]==[/color] false[COLOR=#990000])[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]bail[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]errorInfo[/color][/b][COLOR=#990000]());[/color]
[tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color][COLOR=#FF0000]{[/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]primary[COLOR=#FF0000]}[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$pdo[/color][COLOR=#990000]->[/color][b][COLOR=#000000]lastInsertID[/color][/b][COLOR=#990000]();[/color]
[tab][tab][b][COLOR=#0000FF]return[/color][/b] [COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]rowCount[/color][/b][COLOR=#990000]();[/color] 
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]update[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]global[/color][/b] [COLOR=#009900]$pdo[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$params[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]();[/color]
[tab][tab][COLOR=#009900]$sql[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]"UPDATE {$this->table} SET "[/color][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]foreach[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]fields [b][COLOR=#0000FF]as[/color][/b] [COLOR=#009900]$key[/color][COLOR=#990000]=>[/color][COLOR=#009900]$field[/color][COLOR=#990000]):[/color]
[tab][tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$field[/color] [COLOR=#990000]===[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]primary[COLOR=#990000])[/color] [b][COLOR=#0000FF]continue[/color][/b][COLOR=#990000];[/color]
[tab][tab][tab][COLOR=#009900]$fields[/color][COLOR=#990000][][/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]"`$field` = :{$field}"[/color][COLOR=#990000];[/color]
[tab][tab][tab][COLOR=#009900]$params[/color][COLOR=#990000][[/color][COLOR=#009900]$field[/color][COLOR=#990000]][/color] [COLOR=#990000]=[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][COLOR=#FF0000]{[/color][COLOR=#009900]$field[/color][COLOR=#FF0000]}[/color][COLOR=#990000];[/color] 
[tab][tab][b][COLOR=#0000FF]endforeach[/color][/b][COLOR=#990000];[/color]
[tab][tab]
[tab][tab][COLOR=#009900]$query[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$sql[/color] [COLOR=#990000].[/color] [b][COLOR=#000000]implode[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]','[/color][COLOR=#990000],[/color] [COLOR=#009900]$fields[/color][COLOR=#990000])[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]" WHERE `{$this->primary}` = :{$this->primary}"[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$params[/color][COLOR=#990000][[/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]primary[COLOR=#990000]][/color] [COLOR=#990000]=[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]getPrimary[/color][/b][COLOR=#990000]();[/color]
[tab][tab][COLOR=#009900]$s[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$pdo[/color][COLOR=#990000]->[/color][b][COLOR=#000000]prepare[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$query[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$s[/color] [COLOR=#990000]==[/color] false[COLOR=#990000])[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]bail[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$pdo[/color][COLOR=#990000]->[/color][b][COLOR=#000000]errorInfo[/color][/b][COLOR=#990000]());[/color]
[tab][tab][COLOR=#009900]$r[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]execute[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$params[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$r[/color] [COLOR=#990000]==[/color] false[COLOR=#990000])[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]bail[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]errorInfo[/color][/b][COLOR=#990000]());[/color]
[tab][tab]
[tab][tab][b][COLOR=#0000FF]return[/color][/b] [COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]rowCount[/color][/b][COLOR=#990000]();[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]delete[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]global[/color][/b] [COLOR=#009900]$pdo[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$sql[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]"delete from {$this->table} where {$this->primary} = ?"[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$params[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]getPrimary[/color][/b][COLOR=#990000]());[/color]
[tab][tab][COLOR=#009900]$s[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$pdo[/color][COLOR=#990000]->[/color][b][COLOR=#000000]prepare[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$sql[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$s[/color] [COLOR=#990000]===[/color] false[COLOR=#990000])[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]bail[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$pdo[/color][COLOR=#990000]->[/color][b][COLOR=#000000]errorInfo[/color][/b][COLOR=#990000]());[/color]
[tab][tab][COLOR=#009900]$r[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]execute[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$params[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$r[/color] [COLOR=#990000]===[/color] false[COLOR=#990000])[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]bail[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]errorInfo[/color][/b][COLOR=#990000]());[/color]
[tab][tab][b][COLOR=#0000FF]return[/color][/b] [COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]rowCount[/color][/b][COLOR=#990000]();[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]loadFromID[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$id[/color][COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]global[/color][/b] [COLOR=#009900]$pdo[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$sql[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]"Select * from {$this->table} where {$this->primary} = ?"[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$s[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$pdo[/color][COLOR=#990000]->[/color][b][COLOR=#000000]prepare[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$sql[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$s[/color] [COLOR=#990000]===[/color] false[COLOR=#990000])[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]bail[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$pdo[/color][COLOR=#990000]->[/color][b][COLOR=#000000]errorInfo[/color][/b][COLOR=#990000]());[/color]
[tab][tab][COLOR=#009900]$r[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]execute[/color][/b][COLOR=#990000]([/color][b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$id[/color][COLOR=#990000]));;[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$r[/color] [COLOR=#990000]===[/color] false[COLOR=#990000])[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]bail[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]errorInfo[/color][/b][COLOR=#990000]());[/color]
[tab][tab][COLOR=#009900]$row[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]fetchObject[/color][/b][COLOR=#990000]();[/color]
[tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]load[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$row[/color][COLOR=#990000]);[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]load[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$row[/color] [COLOR=#990000]=[/color] null[COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]is_array[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$row[/color][COLOR=#990000]))[/color] [COLOR=#009900]$row[/color] [COLOR=#990000]=[/color] [COLOR=#990000]([/color]object[COLOR=#990000])[/color] [COLOR=#009900]$row[/color][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]is_null[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$row[/color][COLOR=#990000]))[/color] [COLOR=#009900]$row[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]new[/color][/b] stdClass[COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]foreach[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]fields [b][COLOR=#0000FF]as[/color][/b] [COLOR=#009900]$field[/color][COLOR=#990000]):[/color]
[tab][tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color][COLOR=#FF0000]{[/color][COLOR=#009900]$field[/color][COLOR=#FF0000]}[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]isset[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$row[/color][COLOR=#990000]->[/color][COLOR=#FF0000]{[/color][COLOR=#009900]$field[/color][COLOR=#FF0000]}[/color][COLOR=#990000])[/color] [COLOR=#990000]?[/color] [COLOR=#009900]$row[/color][COLOR=#990000]->[/color][COLOR=#FF0000]{[/color][COLOR=#009900]$field[/color][COLOR=#FF0000]}[/color][COLOR=#990000]:[/color] [COLOR=#FF0000]''[/color][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]endforeach[/color][/b][COLOR=#990000];[/color] 
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]bail[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$array[/color][COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]echo[/color][/b] [COLOR=#FF0000]'<pre>'[/color] [COLOR=#990000].[/color] [b][COLOR=#000000]print_r[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$array[/color][COLOR=#990000],[/color] true[COLOR=#990000])[/color] [COLOR=#990000].[/color] [COLOR=#FF0000]'</pre>'[/color][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]die[/color][/b][COLOR=#990000];[/color][tab]
[tab][COLOR=#FF0000]}[/color]
[COLOR=#FF0000]}[/color]
[COLOR=#990000]?>[/color]

in this way the database/access layer is kept separate. it is easily portable to other databases as it uses PDO. you need to rewrite a few lines of a few methods only, say, to convert from mysql to sqlite.

so at the moment we have the ability primarily to load arbitrary data into the entity (for example from a web form) or to load from a known ID. eg
Code:
[COLOR=#009900]$employeeID[/color] [COLOR=#990000]=[/color] [COLOR=#993399]4[/color][COLOR=#990000];[/color]
[COLOR=#009900]$employee[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]new[/color][/b] employee[COLOR=#990000];[/color]
[COLOR=#009900]$employee[/color][COLOR=#990000]->[/color][b][COLOR=#000000]loadFromID[/color][/b][COLOR=#990000]([/color][COLOR=#993399]4[/color][COLOR=#990000]);[/color]

you can then change some data perhaps
Code:
[COLOR=#009900]$employee[/color][COLOR=#990000]->[/color]lastName [COLOR=#990000]=[/color] [COLOR=#FF0000]"Bloggs"[/color][COLOR=#990000];[/color]
[COLOR=#009900]$employee[/color][COLOR=#990000]->[/color][b][COLOR=#000000]save[/color][/b][COLOR=#990000]();[/color]

or output to a template
Code:
[b][COLOR=#000080]require[/color][/b] [COLOR=#FF0000]'templates/employeeData.php'[/color][COLOR=#990000];[/color]

and the template would look like this
Code:
[COLOR=#990000]<?php[/color]
[b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000](![/color][b][COLOR=#0000FF]isset[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$employee[/color][COLOR=#990000])[/color] [COLOR=#990000]||[/color] [COLOR=#990000]![/color][COLOR=#009900]$employee[/color] instanceof employee[COLOR=#990000]):[/color]
 [b][COLOR=#0000FF]die[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'illegal call'[/color][COLOR=#990000]);[/color]
[b][COLOR=#0000FF]endif[/color][/b][COLOR=#990000];[/color]
[COLOR=#990000]?>[/color]
[COLOR=#990000]<?php[/color] [b][COLOR=#000000]getHeader[/color][/b][COLOR=#990000]();[/color] [COLOR=#990000]?>[/color]
[COLOR=#990000]<[/color]div[COLOR=#990000]>[/color]
[COLOR=#990000]<[/color]div [b][COLOR=#0000FF]class[/color][/b][COLOR=#990000]=[/color][COLOR=#FF0000]"row"[/color][COLOR=#990000]>[/color]
[tab][COLOR=#990000]<[/color]div [b][COLOR=#0000FF]class[/color][/b][COLOR=#990000]=[/color][COLOR=#FF0000]"label"[/color][COLOR=#990000]>[/color]
[tab][tab]Employee ID
[tab][COLOR=#990000]</[/color]div[COLOR=#990000]>[/color]
[tab][COLOR=#990000]<[/color]div [b][COLOR=#0000FF]class[/color][/b][COLOR=#990000]=[/color][COLOR=#FF0000]"data"[/color][COLOR=#990000]>[/color]
[tab][tab][COLOR=#990000]<?=[/color][COLOR=#009900]$employee[/color][COLOR=#990000]->[/color][b][COLOR=#000000]getPrimary[/color][/b][COLOR=#990000]();?>[/color]
[tab][COLOR=#990000]</[/color]div[COLOR=#990000]>[/color]
[COLOR=#990000]</[/color]div[COLOR=#990000]>[/color]
[COLOR=#990000]<[/color]div [b][COLOR=#0000FF]class[/color][/b][COLOR=#990000]=[/color][COLOR=#FF0000]"row"[/color][COLOR=#990000]>[/color]
[tab][COLOR=#990000]<[/color]div [b][COLOR=#0000FF]class[/color][/b][COLOR=#990000]=[/color][COLOR=#FF0000]"label"[/color][COLOR=#990000]>[/color]
[tab][tab]Employee Name
[tab][COLOR=#990000]</[/color]div[COLOR=#990000]>[/color]
[tab][COLOR=#990000]<[/color]div [b][COLOR=#0000FF]class[/color][/b][COLOR=#990000]=[/color][COLOR=#FF0000]"data"[/color][COLOR=#990000]>[/color]
[tab][tab][COLOR=#990000]<?=[/color][COLOR=#009900]$employee[/color][COLOR=#990000]->[/color]employeeLastName[COLOR=#990000];?>,[/color] [COLOR=#990000]<?=[/color][COLOR=#009900]$employee[/color][COLOR=#990000]->[/color]employeeFirstName[COLOR=#990000];?>[/color]
[tab][COLOR=#990000]</[/color]div[COLOR=#990000]>[/color]
[COLOR=#990000]</[/color]div[COLOR=#990000]>[/color]
[COLOR=#990000]<[/color]div [b][COLOR=#0000FF]class[/color][/b][COLOR=#990000]=[/color][COLOR=#FF0000]"row"[/color][COLOR=#990000]>[/color]
[tab][COLOR=#990000]<[/color]div [b][COLOR=#0000FF]class[/color][/b][COLOR=#990000]=[/color][COLOR=#FF0000]"label"[/color][COLOR=#990000]>[/color]
[tab][tab]Employee Email
[tab][COLOR=#990000]</[/color]div[COLOR=#990000]>[/color]
[tab][COLOR=#990000]<[/color]div [b][COLOR=#0000FF]class[/color][/b][COLOR=#990000]=[/color][COLOR=#FF0000]"data"[/color][COLOR=#990000]>[/color]
[tab][tab][COLOR=#990000]<?=[/color][COLOR=#009900]$employee[/color][COLOR=#990000]->[/color]employeeEmailAddress[COLOR=#990000];?>[/color]
[tab][COLOR=#990000]</[/color]div[COLOR=#990000]>[/color]
[COLOR=#990000]</[/color]div[COLOR=#990000]>[/color]
[COLOR=#990000]</[/color]div[COLOR=#990000]>[/color]
[COLOR=#990000]<?php[/color] [b][COLOR=#000000]getFooter[/color][/b][COLOR=#990000]();[/color] [COLOR=#990000]?>[/color]

I prefer this method of template design. However there is nothing intrinsically wrong, for example, of adding more intelligence to the entity and using that to control the output.

For example, add this property to the employee class

Code:
public [COLOR=#009900]$fieldTypes[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color]
[tab][tab][COLOR=#FF0000]'employeeID'[/color][COLOR=#990000]=>[/color][b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'type'[/color][COLOR=#990000]=>[/color][COLOR=#FF0000]'text'[/color][COLOR=#990000],[/color][COLOR=#FF0000]'label'[/color][COLOR=#990000]=>[/color][COLOR=#FF0000]"Employee ID"[/color][COLOR=#990000]),[/color]
[tab][tab][COLOR=#FF0000]'employeeFirstName'[/color][COLOR=#990000]=>[/color][b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'type'[/color][COLOR=#990000]=>[/color][COLOR=#FF0000]'text'[/color][COLOR=#990000],[/color][COLOR=#FF0000]'label'[/color][COLOR=#990000]=>[/color][COLOR=#FF0000]'First Name'[/color][COLOR=#990000]),[/color]
[tab][tab][COLOR=#FF0000]'employeeLastName'[/color][COLOR=#990000]=>[/color][b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'type'[/color][COLOR=#990000]=>[/color][COLOR=#FF0000]'text'[/color][COLOR=#990000],[/color][COLOR=#FF0000]'label'[/color][COLOR=#990000]=>[/color][COLOR=#FF0000]'Last Name'[/color][COLOR=#990000]),[/color]
[tab][tab][COLOR=#FF0000]'employeeEmailAddress'[/color][COLOR=#990000]=>[/color][b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'type'[/color][COLOR=#990000]=>[/color][COLOR=#FF0000]'text'[/color][COLOR=#990000],[/color][COLOR=#FF0000]'label'[/color][COLOR=#990000]=>[/color][COLOR=#FF0000]'Email Address'[/color][COLOR=#990000])[/color]
[tab][COLOR=#990000]);[/color]

and then add these methods to the base inherited class

Code:
public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]output[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$static[/color] [COLOR=#990000]=[/color] true[COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab][COLOR=#009900]$template[/color] [COLOR=#990000]=[/color] [b][COLOR=#000000]file_get_contents[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'templates/genericForm.php'[/color][COLOR=#990000]);[/color]
[tab][tab][i][COLOR=#9A1900]/***[/color][/i]
[i][COLOR=#9A1900][tab][tab] * [/color][/i][b][COLOR=#0000FF]<div[/color][/b] [COLOR=#009900]class[/color][COLOR=#990000]=[/color][COLOR=#FF0000]"row"[/color][b][COLOR=#0000FF]>[/color][/b]
[i][COLOR=#9A1900][tab][tab] * [/color][/i][b][COLOR=#0000FF]<div[/color][/b] [COLOR=#009900]class[/color][COLOR=#990000]=[/color][COLOR=#FF0000]"label"[/color][b][COLOR=#0000FF]>[/color][/b]
[i][COLOR=#9A1900][tab][tab] * %s[/color][/i]
[i][COLOR=#9A1900][tab][tab] * [/color][/i][b][COLOR=#0000FF]</div>[/color][/b]
[i][COLOR=#9A1900][tab][tab] * [/color][/i][b][COLOR=#0000FF]<div[/color][/b] [COLOR=#009900]class[/color][COLOR=#990000]=[/color][COLOR=#FF0000]"field"[/color][b][COLOR=#0000FF]>[/color][/b]
[i][COLOR=#9A1900][tab][tab] * %s[/color][/i]
[i][COLOR=#9A1900][tab][tab] * [/color][/i][b][COLOR=#0000FF]</div>[/color][/b]
[i][COLOR=#9A1900][tab][tab] * [/color][/i][b][COLOR=#0000FF]</div>[/color][/b]
[i][COLOR=#9A1900][tab][tab] */[/color][/i]
[tab][tab][COLOR=#009900]$output[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]''[/color][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]foreach[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]fields [b][COLOR=#0000FF]as[/color][/b] [COLOR=#009900]$field[/color][COLOR=#990000]):[/color]
[tab][tab][tab][COLOR=#009900]$text[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$static[/color] [COLOR=#990000]?[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][COLOR=#009900]$field[/color] [COLOR=#990000]:[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]getField[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$field[/color][COLOR=#990000]);[/color] 
[tab][tab][tab][COLOR=#009900]$output[/color] [COLOR=#990000].=[/color] [b][COLOR=#000000]sprintf[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$template[/color][COLOR=#990000],[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]fieldTypes[COLOR=#990000][[/color][COLOR=#009900]$field[/color][COLOR=#990000]][[/color][COLOR=#FF0000]'label'[/color][COLOR=#990000]],[/color] [COLOR=#009900]$text[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]endforeach[/color][/b][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]return[/color][/b] [COLOR=#009900]$output[/color][COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]getField[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$field[/color][COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab][i][COLOR=#9A1900]//only for text fields at the moment[/color][/i]
[tab][tab][COLOR=#009900]$template[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]"<input type=\"%s\" name=\"%s\" value=\"%\" />"[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$type[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]fieldTypes[COLOR=#990000][[/color][COLOR=#009900]$field[/color][COLOR=#990000]][[/color][COLOR=#FF0000]'type'[/color][COLOR=#990000]];[/color]
[tab][tab][b][COLOR=#0000FF]return[/color][/b] [b][COLOR=#000000]sprintf[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$template[/color][COLOR=#990000],[/color] [COLOR=#009900]$type[/color][COLOR=#990000],[/color] [COLOR=#009900]$field[/color][COLOR=#990000],[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][COLOR=#009900]$field[/color][COLOR=#990000]);[/color]
[tab][COLOR=#FF0000]}[/color]

and now your display code could be just
Code:
[COLOR=#009900]$output[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$employee[/color][COLOR=#990000]->[/color][b][COLOR=#000000]output[/color][/b][COLOR=#990000]([/color]true[COLOR=#990000]);[/color]
[b][COLOR=#000080]require[/color][/b] [COLOR=#FF0000]'templates/generic.php'[/color][COLOR=#990000];[/color]

Code:
[COLOR=#990000]<?php[/color] [b][COLOR=#000000]getHeader[/color][/b][COLOR=#990000]();?>[/color]
[b][COLOR=#0000FF]echo[/color][/b] [b][COLOR=#0000FF]isset[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$output[/color][COLOR=#990000])[/color] [COLOR=#990000]?[/color] [COLOR=#009900]$output[/color] [COLOR=#990000]:[/color] [COLOR=#FF0000]''[/color][COLOR=#990000];[/color]
[COLOR=#990000]<?php[/color] [b][COLOR=#000000]getFooter[/color][/b][COLOR=#990000]();[/color]

so here we have now mixed logic for display AND database access in the same class (the base class). generally speaking an MVC no-no, but, if you like this route, it's handy and not really all that cumbersome. A good example of when I think you should regard it as just fine to ignore MVC purity.

of course you could adhere a bit more to purity and, instead of making the output methods part of the inherited base class, you could make them into a singleton. not my preference as then you are passing around lots of variables, but no reason why not.

typically you will want to add more complexity to the entity class too. like rules for dealing with subordinate data structures (like holidays for employees, access times etc). I would do all of this from the entity class itself, as that is my logical starting point. but sometimes I don't too. So I could do something like this

Code:
[COLOR=#009900]$employee[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]new[/color][/b] employee[COLOR=#990000];[/color]
[COLOR=#009900]$employee[/color][COLOR=#990000]->[/color][b][COLOR=#000000]loadFromID[/color][/b][COLOR=#990000]([/color] [COLOR=#993399]4[/color] [COLOR=#990000]);[/color]
[COLOR=#009900]$employee[/color][COLOR=#990000]->[/color][b][COLOR=#000000]bookHoliday[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'2013-02-01'[/color][COLOR=#990000],[/color] [COLOR=#993399]5[/color][COLOR=#990000]);[/color]
or I could do something like this instead

Code:
[COLOR=#009900]$holiday[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]new[/color][/b] Holiday[COLOR=#990000];[/color]
[COLOR=#009900]$holiday[/color][COLOR=#990000]->[/color]startDate [COLOR=#990000]=[/color] [COLOR=#FF0000]'2013-02-01'[/color][COLOR=#990000];[/color]
[COLOR=#009900]$holiday[/color][COLOR=#990000]->[/color]endDate [COLOR=#990000]=[/color] [b][COLOR=#000000]date[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'Y-m-d'[/color][COLOR=#990000],[/color] [b][COLOR=#000000]strtotime[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'+5 days'[/color][COLOR=#990000],[/color] [b][COLOR=#000000]strtotime[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$holiday[/color][COLOR=#990000]->[/color]startDate[COLOR=#990000])));[/color]
[COLOR=#009900]$holiday[/color][COLOR=#990000]->[/color]employeeID [COLOR=#990000]=[/color] [COLOR=#993399]4[/color][COLOR=#990000];[/color]
[COLOR=#009900]$holiday[/color][COLOR=#990000]->[/color][b][COLOR=#000000]save[/color][/b][COLOR=#990000]();[/color]

both are equally fine. and in either case you could simplify the procedural code (or abstract it) by providing a class method for accepting all those datapoints in one go.
Code:
[COLOR=#009900]$holiday[/color][COLOR=#990000]->[/color][b][COLOR=#0000FF]new[/color][/b] Holiday[COLOR=#990000];[/color]
[COLOR=#009900]$holiday[/color][COLOR=#990000]->[/color][b][COLOR=#000000]book[/color][/b][COLOR=#990000]([/color] [b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'employeeID'[/color][COLOR=#990000]=[/color][COLOR=#993399]4[/color][COLOR=#990000],[/color] [COLOR=#FF0000]'startDate'[/color][COLOR=#990000]=>[/color][COLOR=#FF0000]'2013-02-01'[/color][COLOR=#990000],[/color] [COLOR=#FF0000]'duration'[/color][COLOR=#990000]=>[/color][COLOR=#993399]5[/color][COLOR=#990000]));[/color]

Code:
[b][COLOR=#0000FF]class[/color][/b] holiday [b][COLOR=#0000FF]extends[/color][/b] base[COLOR=#FF0000]{[/color]
[tab]public [COLOR=#009900]$fields[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color]
[tab][tab][COLOR=#FF0000]'holidayID'[/color][COLOR=#990000],[/color]
[tab][tab][COLOR=#FF0000]'employeeID'[/color][COLOR=#990000],[/color]
[tab][tab][COLOR=#FF0000]'startDate'[/color][COLOR=#990000],[/color]
[tab][tab][COLOR=#FF0000]'endDate'[/color][COLOR=#990000],[/color]
[tab][tab][COLOR=#FF0000]'holidayDays'[/color]
[tab][COLOR=#990000]);[/color]
[tab]
[tab]public [COLOR=#009900]$primary[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]'holidayID'[/color][COLOR=#990000];[/color]
[tab]public [COLOR=#009900]$table[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]'holidayBookings'[/color][COLOR=#990000];[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]__construct[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab]parent[COLOR=#990000]::[/color][b][COLOR=#000000]__construct[/color][/b][COLOR=#990000]();[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]book[/color][/b][COLOR=#990000]([/color] [COLOR=#009900]$array[/color] [COLOR=#990000]=[/color] null [COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]is_null[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$array[/color][COLOR=#990000]))[/color] [b][COLOR=#0000FF]return[/color][/b] false[COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]load[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$array[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]return[/color][/b] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]save[/color][/b][COLOR=#990000]([/color] [COLOR=#009900]$array[/color] [COLOR=#990000]);[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]save[/color][/b][COLOR=#990000]([/color] [COLOR=#009900]$array[/color] [COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]holidayDays [COLOR=#990000]==[/color] [COLOR=#FF0000]''[/color][COLOR=#990000]):[/color]
[tab][tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]calculateHolidayDays[/color][/b][COLOR=#990000]([/color] [COLOR=#009900]$array[/color] [COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]endif[/color][/b][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]endDate [COLOR=#990000]==[/color] [COLOR=#FF0000]''[/color][COLOR=#990000]):[/color]
[tab][tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]calculateEndDate[/color][/b][COLOR=#990000]([/color] [COLOR=#009900]$array[/color] [COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]endif[/color][/b][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]return[/color][/b] parent[COLOR=#990000]::[/color][b][COLOR=#000000]save[/color][/b][COLOR=#990000]();[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]private [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]calculateHolidayDays[/color][/b][COLOR=#990000]([/color] [COLOR=#009900]$array[/color] [COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab][COLOR=#009900]$holidayDays[/color] [COLOR=#990000]=[/color] [COLOR=#993399]0[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$i[/color] [COLOR=#990000]=[/color] [COLOR=#993399]0[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$start[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]new[/color][/b] [b][COLOR=#000000]DateTime[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]startDate[COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]while[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$i[/color] [COLOR=#990000]<=[/color] [COLOR=#009900]$array[/color][COLOR=#990000][[/color][COLOR=#FF0000]'duration'[/color][COLOR=#990000]]):[/color]
[tab][tab][tab][COLOR=#009900]$i[/color][COLOR=#990000]++;[/color]
[tab][tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$start[/color][COLOR=#990000]->[/color][b][COLOR=#000000]format[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'N'[/color][COLOR=#990000])[/color] [COLOR=#990000]<[/color] [COLOR=#993399]6[/color][COLOR=#990000])[/color] [COLOR=#009900]$holidayDays[/color][COLOR=#990000]++;[/color] 
[tab][tab][tab][COLOR=#009900]$start[/color][COLOR=#990000]->[/color][b][COLOR=#000000]modify[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'+1 day'[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]endwhile[/color][/b][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]endDate [COLOR=#990000]==[/color] [COLOR=#FF0000]''[/color][COLOR=#990000])[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]endDate [COLOR=#990000]=[/color] [COLOR=#009900]$start[/color][COLOR=#990000]->[/color][b][COLOR=#000000]format[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'Y-m-d'[/color][COLOR=#990000]);[/color]
[tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]holidayDays [COLOR=#990000]=[/color] [COLOR=#009900]$holidayDays[/color][COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[COLOR=#FF0000]}[/color]
(you would want also to add a method of forcing recalculation of holidayDays if either the startDate or endDate changed, not dealt with here)

the point to make here is that there is no rule about how intelligent or dumb you want to make your entity classes (and inversely your procedural/controller code). Nor is there any rule about whether you put the intelligence into the base entity class or the subordinate entity. It's a coding preference. Often I give the basic entity intelligence AND provide helper functions in the subordinate data classes. Simply because as my code becomes more complex I might forget which approach i've used a few days later and can generally go either way. It's just a preference. And although neither of those approaches breaks the MVC 'guidelines', including the intelligence in the controller would. But if it is a one off then again, I would have no qualms in doing so. If there was a chance that the bookHoliday() function would be useful more than once, i'd go the other route. The lesson here is that purity isn't important, convenience and non-repetition is.

for completeness my index.php code typically looks like this

Code:
[b][COLOR=#000080]require_once[/color][/b] [COLOR=#FF0000]'config/config.php'[/color][COLOR=#990000];[/color] [i][COLOR=#9A1900]//establishes session and db connections[/color][/i]
[b][COLOR=#000080]require_once[/color][/b] [COLOR=#FF0000]'includes/includes.php'[/color][COLOR=#990000];[/color] [i][COLOR=#9A1900]//loads library and autoloaders also sets up some useful constants[/color][/i]
[COLOR=#009900]$despatch[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]new[/color][/b] despatch[COLOR=#990000];[/color]
[COLOR=#009900]$despatch[/color][COLOR=#990000]->[/color][b][COLOR=#000000]despatch[/color][/b][COLOR=#990000]();[/color]

and the despatch class typically looks like this

Code:
[b][COLOR=#0000FF]class[/color][/b] despatch[COLOR=#FF0000]{[/color]

[tab]public [COLOR=#009900]$action[/color][COLOR=#990000];[/color]
[tab]public [COLOR=#009900]$req[/color][COLOR=#990000];[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]__construct[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]determineAction[/color][/b][COLOR=#990000]();[/color]
[tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]req [COLOR=#990000]=[/color] [b][COLOR=#000000]array_merge[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$_GET[/color][COLOR=#990000],[/color] [COLOR=#009900]$_POST[/color][COLOR=#990000]);[/color] [i][COLOR=#9A1900]//bad idea but ... [/color][/i]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]private [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]determineAction[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#0000FF]isset[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]req[COLOR=#990000][[/color][COLOR=#FF0000]'action'[/color][COLOR=#990000]])):[/color]
[tab][tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]action [COLOR=#990000]=[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]req[COLOR=#990000][[/color][COLOR=#FF0000]'action'[/color][COLOR=#990000]];[/color]
[tab][tab][tab][b][COLOR=#0000FF]return[/color][/b][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]endif[/color][/b][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]action [COLOR=#990000]=[/color] [COLOR=#FF0000]''[/color][COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]despatch[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]switch[/color][/b] [COLOR=#990000]([/color][b][COLOR=#000000]strtolower[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]action[COLOR=#990000])):[/color]
[tab][tab] [i][COLOR=#9A1900]//actions go here[/color][/i]
[tab][tab][b][COLOR=#0000FF]endswitch[/color][/b][COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[COLOR=#FF0000]}[/color]

if you use a permalink structure such as
Code:
mydomain[COLOR=#990000].[/color]com[COLOR=#990000]/[/color]employees[COLOR=#990000]/[/color][b][COLOR=#0000FF]list[/color][/b] [i][COLOR=#9A1900]//list all[/color][/i]
mydomain[COLOR=#990000].[/color]com[COLOR=#990000]/[/color]employees[COLOR=#990000]/[/color]view[COLOR=#990000]/[/color][COLOR=#993399]5[/color] [i][COLOR=#9A1900]//used for viewing and saving depending on input type[/color][/i]
as opposed to encoding actions in the url or fields, then you would adjust the determineAction method. You could also use this intelligence to split your despatches into different types and files as this may help management (i have despatch switchboards running to thousands of lines which is a headache to maintain. would be easier if they were split into sub-files.).

just to finish on two topics.

1. you will want to search for employees on email address. and here you will probably break the MVC purity as you will need db stuff in the entity class.

Code:
public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]loadFromEmail[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$address[/color] [COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
  parent[COLOR=#990000]::[/color][b][COLOR=#000000]loadFrom[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'employeeEmailAddress'[/color][COLOR=#990000],[/color] [COLOR=#009900]$address[/color][COLOR=#990000]);[/color]
[COLOR=#FF0000]}[/color]
//and in the base class
Code:
public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]loadFrom[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$field[/color][COLOR=#990000],[/color] [COLOR=#009900]$data[/color][COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]global[/color][/b] [COLOR=#009900]$pdo[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$sql[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]"Select * from {$this->table} where {$field} = ?"[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$s[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$pdo[/color][COLOR=#990000]->[/color][b][COLOR=#000000]prepare[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$sql[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$s[/color] [COLOR=#990000]===[/color] false[COLOR=#990000])[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]bail[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$pdo[/color][COLOR=#990000]->[/color][b][COLOR=#000000]errorInfo[/color][/b][COLOR=#990000]());[/color]
[tab][tab][COLOR=#009900]$r[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]execute[/color][/b][COLOR=#990000]([/color][b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$data[/color][COLOR=#990000]));[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$r[/color] [COLOR=#990000]===[/color] false[COLOR=#990000])[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]bail[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]errorInfo[/color][/b][COLOR=#990000]());[/color]
[tab][tab][COLOR=#009900]$rows[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]fetchAll[/color][/b][COLOR=#990000]([/color] PDO[COLOR=#990000]::[/color]FETCH_OBJ [COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]count[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$rows[/color][COLOR=#990000])[/color] [COLOR=#990000]>[/color] [COLOR=#993399]1[/color] [COLOR=#990000])[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]bail[/color][/b][COLOR=#990000]([/color][b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'More than one row returned from LoadFrom'[/color][COLOR=#990000]));[/color]
[tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]load[/color][/b][COLOR=#990000]([/color] [COLOR=#009900]$row[/color][COLOR=#990000][[/color][COLOR=#993399]0[/color][COLOR=#990000]][/color] [COLOR=#990000]);[/color]
[tab][COLOR=#FF0000]}[/color]
it is often useful to list all the members of an entity class. you could do this by creating an employees class as well as an employee class, but that's a bit cumbersome. I typically use an odd design pattern like so

Code:
[b][COLOR=#0000FF]class[/color][/b] factory[COLOR=#FF0000]{[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]getAll[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$class[/color][COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab][COLOR=#009900]$return[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]();[/color]
[tab][tab][COLOR=#009900]$a[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]new[/color][/b] [COLOR=#009900]$class[/color][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]global[/color][/b] [COLOR=#009900]$pdo[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$sql[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]"select * from {$a->table}"[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$s[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$pdo[/color][COLOR=#990000]->[/color][b][COLOR=#000000]prepare[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$sql[/color][COLOR=#990000]);[/color]
[tab][tab][COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]execute[/color][/b][COLOR=#990000]();[/color]
[tab][tab][b][COLOR=#0000FF]while[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$row[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]fetchObject[/color][/b][COLOR=#990000]()):[/color]
[tab][tab][tab][COLOR=#009900]$a[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]new[/color][/b] [COLOR=#009900]$class[/color][COLOR=#990000];[/color]
[tab][tab][tab][COLOR=#009900]$a[/color][COLOR=#990000]->[/color][b][COLOR=#000000]load[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$row[/color][COLOR=#990000]);[/color]
[tab][tab][tab][COLOR=#009900]$return[/color][COLOR=#990000][][/color] [COLOR=#990000]=[/color] [COLOR=#009900]$a[/color][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]endwhile[/color][/b][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]return[/color][/b] [COLOR=#009900]$return[/color][COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[COLOR=#FF0000]}[/color]

which you would use like so

Code:
[COLOR=#009900]$employees[/color] [COLOR=#990000]=[/color] factory[COLOR=#990000]::[/color][b][COLOR=#000000]getAll[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'employee'[/color][COLOR=#990000]);[/color] [i][COLOR=#9A1900]//note you have to use the singular form here[/color][/i]

which you could then statically output like so
Code:
[COLOR=#009900]$output[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]''[/color][COLOR=#990000];[/color]
[b][COLOR=#0000FF]foreach[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$employees[/color] [b][COLOR=#0000FF]as[/color][/b] [COLOR=#009900]$employee[/color][COLOR=#990000]):[/color] 
 [COLOR=#009900]$output[/color] [COLOR=#990000].=[/color] [COLOR=#009900]$employee[/color][COLOR=#990000]->[/color][b][COLOR=#000000]output[/color][/b][COLOR=#990000]([/color] true [COLOR=#990000]);[/color]
[b][COLOR=#0000FF]endforeach[/color][/b][COLOR=#990000];[/color]
[b][COLOR=#000080]require[/color][/b] [COLOR=#FF0000]'templates/generic.php'[/color][COLOR=#990000];[/color]

or you might build a specific list template

Code:
[COLOR=#990000]<?php[/color] [b][COLOR=#000000]getHeader[/color][/b][COLOR=#990000]();?>[/color]
[COLOR=#990000]<[/color]table[COLOR=#990000]>[/color]
[COLOR=#990000]<[/color]thead[COLOR=#990000]>[/color]
[COLOR=#990000]<[/color]tr[COLOR=#990000]>[/color]
[COLOR=#990000]<[/color]th[COLOR=#990000]>[/color]Employee ID[COLOR=#990000]</[/color]th[COLOR=#990000]>[/color]
[COLOR=#990000]<[/color]th[COLOR=#990000]>[/color]First Name[COLOR=#990000]</[/color]th[COLOR=#990000]>[/color]
[COLOR=#990000]<[/color]th[COLOR=#990000]>[/color]Last Name[COLOR=#990000]</[/color]th[COLOR=#990000]>[/color]
[COLOR=#990000]<[/color]th[COLOR=#990000]>[/color]Email Address[COLOR=#990000]</[/color]th[COLOR=#990000]>[/color]
[COLOR=#990000]<[/color]th[COLOR=#990000]><[/color]a href[COLOR=#990000]=[/color][COLOR=#FF0000]"<?=INDEX;?>?action=newemployee"[/color][COLOR=#990000]>[/color]New[COLOR=#990000]</[/color]a[COLOR=#990000]></[/color]th[COLOR=#990000]>[/color]
[COLOR=#990000]</[/color]tr[COLOR=#990000]>[/color]
[COLOR=#990000]</[/color]thead[COLOR=#990000]>[/color]
[COLOR=#990000]<?php[/color] [b][COLOR=#0000FF]foreach[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$employees[/color] [b][COLOR=#0000FF]as[/color][/b] [COLOR=#009900]$employee[/color][COLOR=#990000]):?>[/color]
[COLOR=#990000]<[/color]tbody[COLOR=#990000]>[/color]
 [COLOR=#990000]<[/color]tr[COLOR=#990000]>[/color]
  [COLOR=#990000]<[/color]td[COLOR=#990000]><?=[/color][COLOR=#009900]$employee[/color][COLOR=#990000]->[/color][b][COLOR=#000000]employeeID[/color][/b][COLOR=#990000]();?></[/color]td[COLOR=#990000]>[/color]
  [COLOR=#990000]<[/color]td[COLOR=#990000]><?=[/color][b][COLOR=#000000]htmlspecialchars[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$employee[/color][COLOR=#990000]->[/color][b][COLOR=#000000]empoyeeFirstName[/color][/b][COLOR=#990000]());?></[/color]td[COLOR=#990000]>[/color]
  [COLOR=#990000]<[/color]td[COLOR=#990000]><?=[/color][b][COLOR=#000000]htmlspecialchars[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$employee[/color][COLOR=#990000]->[/color][b][COLOR=#000000]empoyeeLastName[/color][/b][COLOR=#990000]());?></[/color]td[COLOR=#990000]>[/color]
  [COLOR=#990000]<[/color]td[COLOR=#990000]><?=[/color][b][COLOR=#000000]htmlspecialchars[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$employee[/color][COLOR=#990000]->[/color][b][COLOR=#000000]empoyeeEmailAddress[/color][/b][COLOR=#990000]());?></[/color]td[COLOR=#990000]>[/color]
  [COLOR=#990000]<[/color]td[COLOR=#990000]><[/color]a href[COLOR=#990000]=[/color][COLOR=#FF0000]"<?=INDEX;?>?action=editemployee&employeeID=<?=urlencode($employee->employeeID);?>"[/color][COLOR=#990000]>[/color]Edit[COLOR=#990000]</[/color]a[COLOR=#990000]>[/color] [COLOR=#990000]&[/color]nbsp[COLOR=#990000];|&[/color]nbsp[COLOR=#990000];<[/color]a href[COLOR=#990000]=[/color][COLOR=#FF0000]"<?=INDEX;?>?action=deleteeemployee&employeeID=<?=urlencode($employee->employeeID);?>"[/color][COLOR=#990000]>[/color]Delete[COLOR=#990000]</[/color]a[COLOR=#990000]>[/color]
[COLOR=#990000]</[/color]td[COLOR=#990000]>[/color]
[COLOR=#990000]</[/color]tr[COLOR=#990000]>[/color]
[COLOR=#990000]</[/color]tbody[COLOR=#990000]>[/color]
[COLOR=#990000]<?php[/color] [b][COLOR=#0000FF]endforeach[/color][/b][COLOR=#990000];?>[/color]
[COLOR=#990000]</[/color]table[COLOR=#990000]>[/color]
[COLOR=#990000]<?php[/color] [b][COLOR=#000000]getFooter[/color][/b][COLOR=#990000]();?>[/color]

or ... of course you could build the output into the base class or wherever. They world's your oyster!
 
well. that's a very short despatch class. and a bunch of other stuff has also been missed off the post.

harrumph.

and I don't remember what I posted.

anyway. here is the despatch class
Code:
[b][COLOR=#0000FF]class[/color][/b] despatch[COLOR=#FF0000]{[/color]

[tab]public [COLOR=#009900]$action[/color][COLOR=#990000];[/color]
[tab]public [COLOR=#009900]$req[/color][COLOR=#990000];[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]__construct[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]determineAction[/color][/b][COLOR=#990000]();[/color]
[tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]req [COLOR=#990000]=[/color] [b][COLOR=#000000]array_merge[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$_GET[/color][COLOR=#990000],[/color] [COLOR=#009900]$_POST[/color][COLOR=#990000]);[/color] [i][COLOR=#9A1900]//bad idea but ... [/color][/i]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]private [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]determineAction[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#0000FF]isset[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]req[COLOR=#990000][[/color][COLOR=#FF0000]'action'[/color][COLOR=#990000]])):[/color]
[tab][tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]action [COLOR=#990000]=[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]req[COLOR=#990000][[/color][COLOR=#FF0000]'action'[/color][COLOR=#990000]];[/color]
[tab][tab][tab][b][COLOR=#0000FF]return[/color][/b][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]endif[/color][/b][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]action [COLOR=#990000]=[/color] [COLOR=#FF0000]''[/color][COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]despatch[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]switch[/color][/b] [COLOR=#990000]([/color][b][COLOR=#000000]strtolower[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$this[/color][COLOR=#990000]->[/color]action[COLOR=#990000])):[/color]
[tab][tab]
[tab][tab][b][COLOR=#0000FF]endswitch[/color][/b][COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[COLOR=#FF0000]}[/color]

and I think I posted a couple of other things.

like - you will want a way to retrieve employees by email address. so you have to build some intelligence into the employee class. as this is probably something that will be needed in other classes, best to build it into the base too.
Code:
public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]loadFromEmailAddress[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$address[/color][COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab]parent[COLOR=#990000]::[/color][b][COLOR=#000000]loadFrom[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'employeeEmailAddress'[/color][COLOR=#990000],[/color] [COLOR=#009900]$address[/color][COLOR=#990000]);[/color]
[tab][COLOR=#FF0000]}[/color]
Code:
public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]loadFrom[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$field[/color][COLOR=#990000],[/color] [COLOR=#009900]$data[/color][COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab][b][COLOR=#0000FF]global[/color][/b] [COLOR=#009900]$pdo[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$sql[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]"Select * from {$this->table} where {$field} = ?"[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$s[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$pdo[/color][COLOR=#990000]->[/color][b][COLOR=#000000]prepare[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$sql[/color][COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$s[/color] [COLOR=#990000]===[/color] false[COLOR=#990000])[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]bail[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$pdo[/color][COLOR=#990000]->[/color][b][COLOR=#000000]errorInfo[/color][/b][COLOR=#990000]());[/color]
[tab][tab][COLOR=#009900]$r[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]execute[/color][/b][COLOR=#990000]([/color][b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$data[/color][COLOR=#990000]));[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$r[/color] [COLOR=#990000]===[/color] false[COLOR=#990000])[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]bail[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]errorInfo[/color][/b][COLOR=#990000]());[/color]
[tab][tab][COLOR=#009900]$rows[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]fetchAll[/color][/b][COLOR=#990000]([/color] PDO[COLOR=#990000]::[/color]FETCH_OBJ [COLOR=#990000]);[/color]
[tab][tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]count[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$rows[/color][COLOR=#990000])[/color] [COLOR=#990000]>[/color] [COLOR=#993399]1[/color] [COLOR=#990000])[/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]bail[/color][/b][COLOR=#990000]([/color][b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'More than one row returned from LoadFrom'[/color][COLOR=#990000]));[/color]
[tab][tab][COLOR=#009900]$this[/color][COLOR=#990000]->[/color][b][COLOR=#000000]load[/color][/b][COLOR=#990000]([/color] [COLOR=#009900]$row[/color][COLOR=#990000][[/color][COLOR=#993399]0[/color][COLOR=#990000]][/color] [COLOR=#990000]);[/color]
[tab][COLOR=#FF0000]}[/color]

and lastly (I think, harrumph again), there is often a need to load all members of an entity class. I do it with a form of factory class.

Code:
[b][COLOR=#0000FF]class[/color][/b] factory[COLOR=#FF0000]{[/color]
[tab]
[tab]public [b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]getAll[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$class[/color][COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][tab][COLOR=#009900]$return[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]array[/color][/b][COLOR=#990000]();[/color]
[tab][tab][COLOR=#009900]$a[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]new[/color][/b] [COLOR=#009900]$class[/color][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]global[/color][/b] [COLOR=#009900]$pdo[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$sql[/color] [COLOR=#990000]=[/color] [COLOR=#FF0000]"select * from {$a->table}"[/color][COLOR=#990000];[/color]
[tab][tab][COLOR=#009900]$s[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$pdo[/color][COLOR=#990000]->[/color][b][COLOR=#000000]prepare[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$sql[/color][COLOR=#990000]);[/color]
[tab][tab][COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]execute[/color][/b][COLOR=#990000]();[/color]
[tab][tab][b][COLOR=#0000FF]while[/color][/b] [COLOR=#990000]([/color][COLOR=#009900]$row[/color] [COLOR=#990000]=[/color] [COLOR=#009900]$s[/color][COLOR=#990000]->[/color][b][COLOR=#000000]fetchObject[/color][/b][COLOR=#990000]()):[/color]
[tab][tab][tab][COLOR=#009900]$a[/color] [COLOR=#990000]=[/color] [b][COLOR=#0000FF]new[/color][/b] [COLOR=#009900]$class[/color][COLOR=#990000];[/color]
[tab][tab][tab][COLOR=#009900]$a[/color][COLOR=#990000]->[/color][b][COLOR=#000000]load[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$row[/color][COLOR=#990000]);[/color]
[tab][tab][tab][COLOR=#009900]$return[/color][COLOR=#990000][][/color] [COLOR=#990000]=[/color] [COLOR=#009900]$a[/color][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]endwhile[/color][/b][COLOR=#990000];[/color]
[tab][tab][b][COLOR=#0000FF]return[/color][/b] [COLOR=#009900]$return[/color][COLOR=#990000];[/color]
[tab][COLOR=#FF0000]}[/color]
[COLOR=#FF0000]}[/color]
used like this
Code:
[COLOR=#009900]$employees[/color] [COLOR=#990000]=[/color] factory[COLOR=#990000]::[/color][b][COLOR=#000000]getAll[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'employee'[/color][COLOR=#990000]);[/color]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top