I`m using codeigniter3 on my website, i try to make a search button for users but i always get Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster. Error 404 localhost Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30
here is the code:
mycontroller.php
<?php
defined ('BASEPATH') OR exit('No direct script access allowed');
class Mycontroller extends CI_Controller {
public function index()
{
$this->load->library('pagination');
$this->load->model('mymodel');
$config = array();
$config['base_url'] = base_url(). 'mycontroller/index';
$config['total_rows'] = $this->mymodel->count_actor();
$config['per_page'] = 10;
$config['num_links'] = 3;
//$config['uri_segment'] = 3;
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$this->pagination->initialize($config);
$page = $this->uri->segment(3);
$data['actor'] = $this->mymodel->fetch_actor($config['per_page'], $page);
$data['links'] = $this->pagination->create_links();
$this->load->view('actor_lists',$data);
}
public function search_actor() {
$this->load->model('mymodel');
$firstname = $this->input->post('search');
if(isset($firstname) and !empty($firstname)){
$data['actor'] = $this->mymodel->search_actor($firstname);
$data['links'] = '';
$this->load->view('actor_lists', $data);
}
else
{
redirect($this->index());
}
}
}
?>
mymodel.php
<?php
defined ('BASEPATH') OR exit('No direct script access allowed');
class Mymodel extends CI_Model {
public function count_actor() {
return $this->db->count_all('actor');
}
public function fetch_actor($limit, $offset) {
$this->db->limit($limit, $offset);
$query = $this->db->get('actor');
if($query->num_rows() > 0 ) {
return $query->result();
}
else {
return $query->result();
}
}
public function search_actor($firstname) {
$this->db->select('*');
$this->db->from('actor');
$this->db->like('firstname', $firstname);
$query = $this->db->get();
if($query->num_rows > 0 )
{
return $query->result();
}
else
{
return $query->result();
}
}
}
?>
actor_lists.php
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="http://bootswatch.com/readable/bootstrap.css">
</head>
<div align="center" id="container">
<h1>Actor Lists</h1>
<form class="form-inline" role="form" action="<?php echo base_url().'mycontroller/search_actor'; ?>" method="post">
<div class="form-group">
<input type="text" class="form-control" name="search" id="search" placeholder="Cauta dupa nume">
</div>
<button type="submit" class="btn btn-info" name="submit">Submit</button>
</form><br/>
<table style="width: 978px"; class="table table-striped">
<thead style="background-color: #2aabd2;">
<tr>
<th>Actor ID</th>
<th>Last Name</th>
<th>First Name</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php foreach ($actor as $row) { ?>
<tr>
<td><?php echo $row->actorid; ?></td>
<td><?php echo $row->lastname; ?></td>
<td><?php echo $row->firstname; ?></td>
<td><?php echo $row->date; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php echo $links ?>
</div>