0
I have a model called Usuariomodel that only works the find and findAll option, but in my test step a Where so the method does not connect at the base: below follows the function call and the result:
Model:
class UsuarioModel extends Model
{
protected $table = 'usuarios';
protected $primaryKey = 'id';
protected $allowedFields = ['nome', 'login', 'senha', 'tipoUsuario'];
protected $returnType = 'array';
protected $useSoftDeletes = true;
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
public function get($id = null)
{
if($id <> null)
{
return $this->find($id);
}
$exibe = $this->find();
var_dump($exibe);
exit();
}
public function pesquisar($busca = null)
{
$exibe = $this->where('id', 1);
var_dump($exibe);
exit();
}
}
Controller:
class Usuario extends Controller
{
public function __construct()
{
$this->model = new UsuarioModel();
}
public function index()
{
$busca = $this->request->getVar('busca');
if(!empty($busca))
{
$this->data = [
'table' => $this->model->pesquisar($busca)
];
}
else
{
$this->data = [
'table' => $this->model->get()
];
}
echo view('template/header');
echo view('usuario/index', $this->data);
echo view('template/footer');
}
}
you speak the method
pesquisar
?– novic
That’s right. This is the result of the search method var_dump: https://uploaddeimagens.com.br/imagens/XypRnfs
– Lucas Rondon
And this is the result of the get: https://uploaddeimagens.com.br/imagens/Bd90u-4method
– Lucas Rondon
it connects yes at the base
– novic
So what can it be? It does not bring the result of Where. Actually in this test I put Where passing an id directly, but the method will do a like in the Name field. But none of the functions work, nor directly pass the controller.
– Lucas Rondon
You are not asking for the result to be executed and mounted because of this need to use find or findAll at the end
– novic
It worked out the way you said, I really appreciate your help.
– Lucas Rondon
@Lucas Rondon. I recommend the doc. I gave a quick read and found very good https://codeigniter.com/user_guide/models/model.html#finding-data
– Marcos Xavier