I'm trying to access the getters that refer to an object, however this object is in an array, and by no means do you want to access them. Here is the class DAO (where you are giving the mess and I am doing test) and class VO:
DAO:
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
define('CONFIG', dirname(dirname(__DIR__)). '/config'. DIRECTORY_SEPARATOR);
define('MODEL_VO', dirname(dirname(__DIR__)). '/model/vo'. DIRECTORY_SEPARATOR);
include(CONFIG . 'conexao.php');
include(MODEL_VO . 'prioridade.php');
Class PrioridadeDao{
private $conexao;
private $prioridadeObj;
private $prioridadeArrayObj = array();
public function __construct(){
$this->conexao = new Conexao();
}
public function teste(){
echo "teste";
}
public function selectAll(){
if(!$this->conexao->conecta()){
exit;
} else {
$result = pg_query($this->conexao->conecta(), "SELECT * FROM prioridade");
while ($consulta = @pg_fetch_array($result)){
$this->prioridadeObj = new Prioridade($consulta['id'], $consulta['nivel'], $consulta['nome']);
$this->prioridadeArrayObj[] = $this->prioridadeObj;
}
#### Aqui onde a coisa ocorre, no cast aparentemente está certo não consigo é acessar as coisas após ele
#### por isso usei o var_dump para ver o que tem na saida.
$this->prioridadeArrayObj = (object) $this->prioridadeArrayObj;
var_dump($this->prioridadeArrayObj);
$this->conexao->encerra();
}
}
}
Model VO:
<?php
Class Prioridade{
private $id;
private $nivel;
private $nome;
//public function __construct(){
//}
public function __construct($id, $nivel, $nome){
$this->setId($id);
$this->setNivel($nivel);
$this->setNome($nome);
}
#GETTERS AND SETTERS
public function setId($id){
$this->id = $id;
}
public function setNivel($nivel){
$this->nivel = $nivel;
}
public function setNome($nome){
$this->nome = $nome;
}
public function getId(){
return $this->id;
}
public function getNivel(){
return $this->nivel;
}
public function getNome(){
return $this->nome;
}
}
As I'm doing in MVC I want to correctly use the interactions between classes. (If anyone has a legal mvc tutorial PHP thank you then the references I have found are making me confused). I have spent a lot of time programming with Java (Desktop) and to access the methods is super easy, in PHP I'm having a lot of difficulties.
Another question, how do I do 2 methods constructors in a class that neither is possible in Java? Ex:
1 - public function __construct () {}
2 - public function __construct ($ param1, $ param2) {}
Thanks in advance.
Home
If I change the "var_dump" to "print_r" I have the following result:
stdClass Object ([0] => Priority Object ([id: Priority: private] => 1 [level: Priority: private] => 1 [name: Priority: private] = > => Priority Object ([id: Priority: private] => 2 [level: Priority: private] => 2 [name: Priority: private] = > 3 [level: Priority: private] => 3 [name: Priority: private] = > 4 [level: Priority: private] => 4 [name: Priority: private] => HIGH [4] = & : private] = > 5 [name: Priority: private] => VERY HIGH))