ok...
I have this already:
Dog.class.php
PHP Code:
Class Dog {
private $_id_dog;
private $_name_dog;
private $_id_vet;
//setters
public function setIdDog( $id_dog ){
$this->_id_dog = $id_dog;
}
public function setNameDog( $name_dog ){
$this->_name_dog = $name_dog;
}
public function setIdVet( Vet $id_vet ){
$this->_id_vet = $id_vet;
}
//getters
public function getIdDog ($id_dog) {
$this->_id_dog = $id_dog;
}
public function getNameDog ($name_dog) {
$this->_name_dog = $name_dog;
}
public function getIdVet (Vet $id_vet) {
$this->_id_vet = $id_vet;
}
} //end of dog class.
1) Since I don’t want to have a representation of the whole vet object here, but only the id, can I pass only the id here? Or this decision is to be made on the instances side?
2) We need to have a getter to the _id_vet; property to. Right? Because my objects will not
access the dog properties directly, instead the class must get the proprieties with methods, and that public methods will be accessible to my objects, so that the objects can access the class properties trough the methods. Is this correct?
DogDAO.class.php
PHP Code:
class DogDAO extends GeneralDAO {
public function insertDog(Dog $dog) {
$vetId = $dog->vet->getVetId();
$stmt = $this->_dbh->prepare("INSERT INTO DOG (name_dog, id_vet) VALUES (?, ?)");
$stmt->bindParam(1, $dog->getNameDog(), PDO::PARAM_STR );
$stmt->bindParam(2, $dog->vet->getVetId(), PDO::PARAM_INT);
$stmt->execute();
}
}//end of DogDAO class.
3) This is a correct approach?
PHP Code:
$stmt->bindParam(2, $dog->vet->getVetId(), PDO::PARAM_INT);
4) If so, do I need to declare $vetId on this line?
PHP Code:
$vetId = $dog->vet->getVetId();
?
Vet.class.php
PHP Code:
class Vet {
private _id_vet;
private _name_vet;
//setters
public function setIdVet( $id_vet ){
$this->_id_vet = $id_vet;
}
public function setNameVet( $name_vet ){
$this->_name_vet = $name_vet;
}
//getters
public function getIdVet ($id_vet) {
$this->_id_vet = $id_vet;
}
public function getNameVet ($name_vet) {
$this->_name_vet = $name_vet;
}
} // end of Vet class.
VetDAO.class.php
PHP Code:
class VetDAO extends GeneralDAO {
public function listVets() {
$stmt = null;
$stmt = $this->_dbh->query("SELECT * FROM VETS");
$rows = $stmt->fetchAll(PDO::FETCH_OBJ);
return $rows;
}
} //end of VetDAO class.
Thanks a lot,
Márcio
Bookmarks