У меня возникли проблемы при создании поиска форму в CodeIgniter - он показывает ошибки, как:Форма поиска в CodeIgniter
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Login::$membership_model
Filename: controllers/login.php
Line Number: 12
Backtrace:
File: C:\xampp\htdocs\Project5_1\CodeIgniter\application\controllers\login.php Line: 12 Function: _error_handler
File: C:\xampp\htdocs\Project5_1\CodeIgniter\index.php Line: 315 Function: require_once
Fatal error: Call to a member function getSearchBook() on null in C:\xampp\htdocs\Project5_1\CodeIgniter\application\controllers\login.php on line 12 A PHP Error was encountered
Severity: Error
Message: Call to a member function getSearchBook() on null
Filename: controllers/login.php
Line Number: 12
Backtrace:
Мой контроллер страницы:
<?php
class Login extends CI_Controller{
function search(){
$searchBook = $this->input->post('searchBook');
$data = $this->membership_model->getSearchBook($seachBook);
$this->load->view('main_content',$data);
}
?>
Моя страница Модель :
class Membership_model extends CI_Model{
function getSearchBook($searchBook) {
$this->db->select('*');
$this->db->from('book');
$this->db->like('author',$searchBook);
return $query->result();
}
}
Мой main_content.php является:
<?php
echo form_open('login/search');
echo form_input('searchBook','Search Book', 'id="searchBook"');
echo form_submit('submit', 'Search');
echo form_close();
?>
<table><th>Title</th></table>
<div>
<?php
// List up all results.
foreach ($results as $val)
{
echo $val['title'];
}
?>
</div>
</body>
Спасибо, это сработало. –