I'm studying POO in php and I'm having a hard time making a simple platform that uses CRUD (just to train).
I created my class and views and anyway I am not able to do insert , if I do in pure as old method it works , already in object orientation not
I do not know what's going on, could anyone help me?
Follow the code
Model / UserInternal
class UserInterno{
private $nome;
private $sobrenome;
// private $tipo;
private $email;
private $login;
private $senha;
public function getNome(){
return $this->nome;
}
public function setNome($nome){
$this->nome = $nome;
}
public function getSobrenome(){
return $this->sobrenome;
}
public function setSobrenome($sobrenome){
$this->sobrenome = $sobrenome;
}
// public function getTipo(){
// return $this->tipo;
// }
// public function setTipo($tipo){
// $this->tipo = $tipo;
// }
public function getEmail(){
return $this->email;
}
public function setEmail($email){
$this->email = $email;
}
public function getLogin(){
return $this->login;
}
public function setLogin($login){
$this->login = $login;
}
public function getSenha(){
return $this->senha;
}
public function setSenha($senha){
$this->senha = $senha;
}
}
Controller / ServiceUserInternal
class ServiceUserInterno{
//atributos
private $db;
private $user;
function __construct(Mysqli $mysqli, UserInterno $user){
//ja recebendo a conexao do banco
$this->db = $mysqli;
$this->user = $user;
}
public function insert(){
$stmt = $this->db->stmt_init();
$stmt->prepare("INSERT INTO tb_user_master (nome, sobrenome, email, login, senha) VALUES(?,?,?,?,?)");
$nome_user = $this->user->getName();
$sobrenome_user = $this->user->getSobrenome();
// $tipo_user = $this->user->getTipo();
$email_user = $this->user->getEmail();
$login_user = $this->user->getLogin();
$senha_user = $this->user->getSenha();
$stmt->bind_param("ssisss", $nome_user, $sobrenome_user, $email_user, $login_user, $senha_user);
$stmt->execute();
}
}
Controller / registerInternal_User
<?php
include('libs/conexao.php');
require_once ("Model/UserInterno.php");
require_once ("Controller/ServiceUserInterno.php");
$nome = $_POST['nome'];
$sobrenome = $_POST['sobrenome'];
$email = $_POST['email'];
$login = $_POST['login'];
$senha = $_POST['senha'];
$user = new UserInterno();
$ServiceUser = new ServiceUserInterno($mysqli, $user);
$ServiceUser->setNome($nome);
$ServiceUser->setSobrenome($sobrenome);
$ServiceUser->setEmail($email);
$ServiceUser->setLogin($login);
$ServiceUser->setSenha($senha);
$ServiceUser->insert();
?>
Views / view_internal_user
<div class="row linha_form">
<form action="../Controller/cadastrarUser_interno.php" method="POST">
<div class="col-lg-12">
<input type="text" name="nome" placeholder="Nome*" class="input_user">
<input type="text" name="sobrenome" placeholder="Sobrenome" class="input_user">
<!-- <input type="text" name="tipo_area" placeholder="Formação profissional*" class="input_user"> -->
<input type="email" name="email" placeholder="E-mail*" class="input_user">
<input type="text" name="login" placeholder="Login*" class="input_user">
<input type="password" name="senha" placeholder="Senha*" class="input_user">
<br>
<input type="submit" name="cadastrar" value="Cadastrar" class="btn_cadastrar_user">
</div>
</form>
</div>
ERROR: Uncaught Error: Call to undefined method ServiceUserInternal :: setNome () in /opt/lampp/htdocs/curso_php_mysql/system_KeM/Controller/stayUser_interno.php:17 Stack trace: # 0 {main} thrown in /opt/lampp/htdocs/curso_php_mysql/KeM/Controller/supportUser_interno.php on line 17
NOTE: the file registerUser_internal it receives the data of the post that was sent from the form and makes the insert