Я делаю mvc crud с поисковой системой, но при запуске проекта отображается Fatal error: вызов неопределенного метода client :: buscame() в C:\xampp\htdocs\mvc\view\client\client.php в строке 56
это /view/cliente/cliente.php
<h1 class="page-header">CRUD con el patrón MVC en PHP POO y PDO </h1>
<a class="btn btn-primary pull-right" href="?c=cliente&a=agregar">Agregar</a>
<a class="btn btn-primary pull-right" href="?c=cliente&a=ardila">Ardila</a>
<a class="btn btn-primary pull-right" href="?c=cliente&a=mateus">Mateus</a>
<table class="table table-striped table-hover" id="tabla">
<thead>
<tr>
<th style="width:180px; background-color: #5DACCD; color:#fff">ID</th>
<th style="width:120px; background-color: #5DACCD; color:#fff">DNI</th>
<th style="width:180px; background-color: #5DACCD; color:#fff">Nombre</th>
<th style=" background-color: #5DACCD; color:#fff">Apellido</th>
<th style=" background-color: #5DACCD; color:#fff">Correo</th>
<th style="width:120px; background-color: #5DACCD; color:#fff">Telefono</th>
<th style="width:60px; background-color: #5DACCD; color:#fff"></th>
<th style="width:60px; background-color: #5DACCD; color:#fff"></th>
</tr>
</thead>
<tbody>
<?php foreach($this->model->Listar() as $r): ?>
<tr>
<td><?php echo $r->id; ?></td>
<td><?php echo $r->dni; ?></td>
<td><?php echo $r->Nombre; ?></td>
<td><?php echo $r->Apellido; ?></td>
<td><?php echo $r->Correo; ?></td>
<td><?php echo $r->Telefono; ?></td>
<td>
<a class="btn btn-warning" href="?c=cliente&a=agregar&id=<?php echo $r->id; ?>">Editar</a>
</td>
<td>
<a class="btn btn-danger" onclick="javascript:return confirm('¿Seguro de eliminar este registro?');" href="?c=cliente&a=Eliminar&id=<?php echo $r->id; ?>">Eliminar</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
<form action="?c=cliente&a=buscame" method="get" enctype="multipart/form-data">
<input type="text" name="dni" id="dni"/>
<input type="submit" name="boton" id="boton"/>
</form>
<?php while($f= $this->model->buscame()){
echo '<tr>';
echo '<td width="19">'.$f['id'].'</td>';
echo '<td width="61">'.$f['dni'].'</td>';
echo '<td width="157">'.$f['Nombre'].'</td>';
echo '<td width="221">'.$f['Apellido'].'</td>';
echo '<td width="176">'.$f['Correo'].'</td>';
echo '<td width="118">'.$f['Telefono'].'</td>';
echo '</tr>';
}
?>
</tbody>
и это cliente.controller.php
class clienteController {
private $model;
public function __CONSTRUCT(){
$this->model = new cliente();
}
public function Paginar(){
require_once 'view/header.php';
require_once 'view/cliente/cliente.php';
}
public function agregar(){
$cliente = new cliente();
if(isset($_REQUEST['id'])){
$cliente = $this->model->Obtener($_REQUEST['id']);
}
require_once 'view/header.php';
require_once 'view/cliente/cliente-editar.php';
}
public function buscame(){
$cliente = new cliente();
$dni=$_GET('dni');
if(isset($dni)){
$stm = $pdo->query('SELECT * FROM cliente WHERE id= :id');
$stm -> bindParam(':id', $id, PDO::PARAM_INT);
$stm -> execute();
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
if(empty($res) or $res == false){
return array();}
else{
return $res;}
}
require_once 'view/header.php';
require_once 'view/cliente/cliente.php';
}
public function ardila(){
$cliente = new cliente();
if(isset($_REQUEST['id'])){
$cliente = $this->model->ListarApellido($_REQUEST['id']);
}
require_once 'view/header.php';
require_once 'view/cliente/Lista.php';
}
public function mateus(){
$cliente = new cliente();
if(isset($_REQUEST['id'])){
$cliente = $this->model->ListarApellidoM($_REQUEST['id']);
}
require_once 'view/header.php';
require_once 'view/cliente/Lista.php';
}
public function Guardar(){
$cliente = new cliente();
$cliente->id = $_REQUEST['id'];
$cliente->dni = $_REQUEST['dni'];
$cliente->Nombre = $_REQUEST['Nombre'];
$cliente->Apellido = $_REQUEST['Apellido'];
$cliente->Correo = $_REQUEST['Correo'];
$cliente->telefono = $_REQUEST['telefono'];
if($cliente->id > 0){
$this->model->Actualizar($cliente);
}
else{
$this->model->Registrar($cliente);
}
header('Location: index.php');
}
public function Eliminar(){
$this->model->Eliminar($_REQUEST['id']);
header('Location: index.php');
}
}
когда я выполняю поиск, появляется фатальная ошибка:
Вызов неопределенного метода client :: buscame() в C:\xampp\htdocs\mvc\view\client\client.php в строке 56
Вы не предоставили весь свой код, но, похоже, у вас нет метода buscame()
для модели, которую вы вызываете в представлении.
$this->model->buscame()
Возможно ли, что вы хотите сделать что-то вроде
$this->client->buscame()
buscame
не объявлена в классеcliente
. Попробуйте изменить:$this->model->buscame()
- to -$this->buscame()
clienteController
внутри функцииbuscame()
измените две переменные с именем$dni
на$id
. Функция, скорее всего, не будет получать результаты без этого.