gpt4 book ai didi

php - pdo搜索麻烦未定义的方法

转载 作者:行者123 更新时间:2023-11-29 17:47:31 24 4
gpt4 key购买 nike

我正在使用搜索引擎进行 mvc crud,但是当我运行该项目时显示 fatal error :调用未定义的方法 client::buscame() in 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

类 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');
}

}

当我进行搜索时,出现 fatal error :

Call to undefined method client::buscame() in C: \ xampp \ htdocs \ mvc \ view \ client \ client.php on line 56

最佳答案

您尚未提供所有代码,但在 View 中调用的模型上似乎没有 buscame() 方法。

$this->model->buscame()

您是否有可能想做诸如

之类的事情

$this->client->buscame()

关于php - pdo搜索麻烦未定义的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49685721/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com