|
Datei: /pages/tutorials/database/database-06.php
<?php class Database06 extends Page { public function InitializeComponent() { parent::$PAGE_TITLE = "Tutorial : Table loaded by a query with features add, update, delete and foreign key"; // Create table $this->render = new Table(); $this->render->setId("user_table_6"); $this->render->activateAdvanceTable(); // Defined header $header = $this->render->addRowColumns( "Id", "Name", "Birthday", "Sex", "Page", "Actif" ); $header->setHeaderClass(0); // Define table properties (width, align, ...) // You need to configure foreign key to display // the foreign key value (and not the id) $properties = array( UserDbTable::FIELD_NAME => array( "width" => 80, "strip_tags" => true, "allowable_tags" => "<b><i>" ), UserDbTable::FIELD_BIRTHDAY => array( "width" => 80 ), UserDbTable::FIELD_SEX_ID => array( "fk_attribute" => SexDbTable::FIELD_VALUE, "width" => 70, "align" => RowTable::ALIGN_LEFT ), UserDbTable::FIELD_FAVORITE_PAGE_ID => array( "fk_attribute" => FavoritePageDbTable::FIELD_NAME, "fk_where" => UserDbTable::FIELD_ACTIF." = 1", "fk_orderby" => UserDbTable::FIELD_NAME, "width" => 120, ) ); // Load data from query $sql = new SqlDataView(new UserDbTable()); $this->render->loadFromSqlDataView($sql, $properties, // Defined properties true, // Insert activate true, // Update activate true // Delete activate ); } // You need to add this method to trigger the table's events. // All kind of events (Insert, Update or Delete) are managed by // the method onChangeTableFromSqlDataView of the Table object. public function onChangeTableFromSqlDataView($sender) { $this->render->onChangeTableFromSqlDataView($sender); } } ?>
Zurück zum Tutorial der Komponente Database
|
drop table if exists `user`; drop table if exists `sex`; drop table if exists `favorite_page`;
/*==============================================================*/ /* table: `user` */ /*==============================================================*/ create table `user` ( user_id int not null auto_increment, name varchar(50), birthday date, sex_id int, favorite_page_id int, actif boolean, primary key (user_id) ) engine = innodb;
/*==============================================================*/ /* table: `sex` */ /*==============================================================*/ create table `sex` ( sex_id int not null auto_increment, value varchar(20), primary key (sex_id) ) engine = innodb;
insert into `sex` (value) values('Man'); insert into `sex` (value) values('Woman');
/*==============================================================*/ /* table: `favorite_page` */ /*==============================================================*/ create table `favorite_page` ( favorite_page_id int not null auto_increment, name varchar(20), url varchar(255), actif boolean, primary key (favorite_page_id) ) engine = innodb;
insert into `favorite_page` (name, url, actif) values('WebSite-PHP', 'http://www.website-php.com', true); insert into `favorite_page` (name, url, actif) values('Meteo Europ', 'http://www.meteo-europ.com', true); insert into `favorite_page` (name, url, actif) values('OracleRef', 'http://www.oracleref.com', true); insert into `favorite_page` (name, url, actif) values('WebSite-PHP', 'http://www.website-php.com', false); insert into `favorite_page` (name, url, actif) values('Meteo Europ', 'http://www.meteo-europ.com', false); insert into `favorite_page` (name, url, actif) values('OracleRef', 'http://www.oracleref.com', false);
alter table `user` add constraint fk_ref_user_sex foreign key (sex_id) references `sex` (sex_id);
alter table `user` add constraint fk_ref_user_favorite foreign key (favorite_page_id) references `favorite_page` (favorite_page_id);
|
|
|
|
|