Hoi,
Ik heb onlangs mijn eigen php ActiveRecord wrapper geschreven. Voorbeeldje van hoe het allemaal werkt:
Die User class stelt dan een database table voor, en die class ziet er zo uit:
Jij hoeft dus op zich bijna geen werk te verrichten, dat doet de DbTable class.
Heeft iemand hier interesse in? Het verminderd zelf SQL typen echt wel.
Grt
Ik heb onlangs mijn eigen php ActiveRecord wrapper geschreven. Voorbeeldje van hoe het allemaal werkt:
[COLOR= #0000BB]<?php
$db_table[/COLOR] [COLOR= #007700]= new[/COLOR] User[COLOR= #007700]([/COLOR]Database[COLOR= #007700]::[/COLOR]getDatabaseWithDefaultAdapter[COLOR= #007700]());[/COLOR]
[COLOR= #0000BB]$usr[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$db_table[/COLOR][COLOR= #007700]->[/COLOR]find[COLOR= #007700]([/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]// find user met id = 1[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$usr[/COLOR][COLOR= #007700]->[/COLOR]username[COLOR= #007700];[/COLOR] [COLOR= #FF8000]// output => raoul[/COLOR]
[COLOR= #0000BB]$usr[/COLOR][COLOR= #007700]->[/COLOR]username [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]Piet[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$usr[/COLOR][COLOR= #007700]->[/COLOR]username[COLOR= #007700];[/COLOR] [COLOR= #FF8000]// output => Piet[/COLOR]
[COLOR= #0000BB]$db_table[/COLOR][COLOR= #007700]->[/COLOR]save[COLOR= #007700]([/COLOR][COLOR= #0000BB]$usr[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]// wijzig de db table[/COLOR]
?> Die User class stelt dan een database table voor, en die class ziet er zo uit:
[COLOR= #0000BB]<?php[/COLOR]
namespace ApplicationModelDbTable[COLOR= #007700];[/COLOR]
use FrameworkDatabaseDbTableDbTable[COLOR= #007700];[/COLOR]
[URL="http://www.php.net/class"]class[/URL] User extends DbTable
[COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [COLOR= #0000BB]$tableName[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]user[/COLOR][COLOR= #007700];
}[/COLOR]
?> Jij hoeft dus op zich bijna geen werk te verrichten, dat doet de DbTable class.
Heeft iemand hier interesse in? Het verminderd zelf SQL typen echt wel.
Grt
Maar die find methode, die kan je wss overschrijven neem ik aan ?
En ja gebruik nogal vaak JOINS 