|
Method setData_object( $sName, $oValue ) |
|
Written by Hidalgo Emmanuel
|
Description : This method addition an object “has” with another object “B” which contains a collection of the type implicitly “B”. For example, in a site of real classifieds, a house (produced) will be attached to a person (user). Parameters : $sName, string : Indicate the name of the fields which will identify the attached object $oValue, object : Indicate the object to be attached Value of return : Turn over “true” if the addition were carried out successfully Turn over “false” if the object could not be added
The example following addition a product to one “tuser”: <?php //total instanciation include_once( 'phpsimpledb.class.php' ); Global $oBDD; $oBDD = new PHPSIMPLEDB(); //recovery of "user" $oUser = $oBDD->getObject( "users" ); $oUser->load( 21 ); //creation of the product $oProduit = $oBDD->getObject( "produits" ); $oProduit->setData_field( "name", "jolie maison" ); //addition of the product to "user" $oProduit->setData_object( "users_id", $oUser ); //safeguard product $oProduit->save();
?>
| Note: If you try to safeguard a new object in base, you ensure that all the obligatory values are indicated. If you forget to inform the obligatory fields, your attempt at safeguard will fail.
|