i want to be able to access this variable on controller that i had make before
this is my code in my view
<tbody>
<?php foreach ($data->result() as $row):?>
<tr>
<td><?php echo $row->nama; ?></td>
<td><?php echo $row->email; ?></td>
<td><?php echo $row->username; ?></td>
<td><?php echo $row->password; ?></td>
<td>
Edit |
DELETE |
</td>
</tr>
<?php endforeach; ?>
</tbody>
i put some method that contain that variable on controller name Login, but i set my default controller as News. And i want to access that variable from Login Controller.
and this is my Login Controller
public function index()
{
$this->$data['login'] = $this->Login_Model->get_news();
$this->$data['title']= 'Data Pendaftaran';
// konfigurasi pagination//
$config['base_url'] = site_url('Login/index');
$config['total_rows'] = $this->db->count_all('anggota');
$config['per_page'] =4;
$config["uri_segment"] =3;
$choice = $config["total_rows"]/ $config["per_page"];
$config["num_links"] =floor($choice);
// style pagination untuk bootstrap v4//
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Prev';
$config['full_tag_open'] = '<div class="pagging text-center"><nav><ul class = "pagination justify-content-center">';
$config['full_tag_close'] = '</ul></nav></div>';
$config['num_tag_open'] ='<li class="page-item"><span class ="page-link">';
$config['num_tag_close'] ='</span></li>';
$config['cur_tag_open'] ='<li class="page-item active"><span class="page-link">';
$config['cur_tag_close'] ='<span class="sr-only">(current)</span></span></li>';
$config['next_tag_open'] ='<li class="page-item"><span class="page-link">';
$config['next_tagl_close'] ='<span aria-hidden="true">»</span></span></li>';
$config['prev_tag_open'] ='<li class="page-item"><span class="page-link">';
$config['prev_tagl_close'] ='</span>Next</li>';
$config['first_tag_open'] ='<li class="page-item"><span class="page-link">';
$config['first_tagl_close'] = '</span></li>';
$config['last_tag_open'] ='<li class="page-item"><span class="page-link">';
$config['last_tagl_close'] ='</span></li>';
$this->pagination->initialize($config);
$data['page']=($this->uri->segment(3))? $this->uri->segment(3) : 0;
$data['data'] = $this->Login_Model->get_data_list($config["per_page"],$data['page']);
$data['pagination'] = $this->pagination->create_links();
$this->load->view('anggotapendaftaran',$data);
}
im sorry for my bad language
You can do it in the following way:
On Controller, after you all code where you load view:
$data = array();
$data['title'] = 'Data Pendaftaran';
$this->load->view("yourviewname_view", $data);
on View, when you want to get title, you can get it like $data
example:
echo $data; //will give you "Data Pendaftaran"
If it's array, you can access it like:
echo $data['arrayKey'];
or
echo $data['pagination'];
I hope this will help
Related
I have set the pagination to the page. but it doesn't recognize the variable that represent the pagination link from the controller. How can I solve it?
This is View "member_list.php"
<table class="table table-hover table-striped table-bordered">
<tr>
<th class="text-center">ID</th>
<th class="text-center">Name</th>
<th class="text-center">Number</th>
<th class="text-center">Type</th>
<th class="text-center">Unit</th>
<th class="text-center">Date</th>
<th class="text-center">Action</th>
</tr>
<tr>
<td class="text-center"><?php echo $member->ID; ?></td>
<td><?php echo $member->Name; ?></td>
<td><?php echo $member->Letter_Number; ?></td>
<td><?php echo $member->Letter_Type; ?></td>
<td><?php echo $member->Unit; ?></td>
<td><?php echo $member->Date; ?></td>
<tr>
<div class="pagination "><?php echo "<li>". $links."</li>";?></div> // it doesn't defined $links variable
Here is controller "Main.php"
class Main extends CI_Controller {
public function index ()
{
redirect('member_list');
}
public function pagination1() {
$this->load->model('members');
$this->load->library('pagination');
$config = array();
$config["base_url"] = base_url()."main/pagination1";
$config["num_links"]= $this->members->record_count();
$config["per_page"] = 5;
$config["total_rows"] = $this->members->record_count(); //method in controller
$config["use_page_numbers"] = TRUE;
$config['cur_tag_open'] = ' <a class="current">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["members"] = $this->members->fetch_data1($config["per_page"],$page);
$pa_links = $this->pagination->create_links();
$data["links"] = $this->pagination->create_links(); //explode(' ',$pa_links );
$data["u_connect"] = $user_connect;
$this->display('members_list',$data);
}
Here is model "members.php"
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Members extends CI_Model {
public function record_count() {
return $this->db->count_all("in_list");
}
public function fetch_data1($limit, $id) {
$this->db->limit($limit);
$this->db->where('id', $id);
$query = $this->db->get("in_list");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
}
I will just post one of mine and you can adapt it
public function index()
{
$config['base_url'] = base_url() . '/pages/index/';
$config['total_rows'] = $this->db->count_all_results('posts');
$config['per_page'] = 4;
$config['num_links'] = 4;
$config['uri_segment'] = 3;
$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = "<div class='pagination'>";
$config['full_tag_close'] = "</div>";
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$this->pagination->initialize($config);
$parent = "main";
$this->db->select("title, content, date, last_date, slug")->where('parent', $parent)->where('status', 'publish')->order_by("id", "asc");
$query = $this->db->get('posts', $config['per_page'],$this->uri->segment(3));
if($query->result()){
$data["mainContent"] = $query->result();
}
$data['title'] = "title";
$data['main_content'] = 'pages/prime';
$this->load->view('pages/includes/template', $data);
}
You are using a model, but its little different than mine that doesnt use a model.
In your view, this is all you need AFTER your foreach
<?php echo $this->pagination->create_links();?>
try this
<p><?php echo $links;?></p>
insted of this line <div class="pagination "><?php echo "<li>". $links."</li>";?></div>
you can also set this configaration in your function
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
I have a datatable with pagination and I have just added a search function. At the moment my search results do not have pagination. I have tried to add the configurations from my index to the search function but it hasn't worked. I'm wondering if I'm missing something. I'd appreciate it if someone can take a look at it?
Controller
public function index(){
$config['base_url'] = base_url('/Control/Users');
$config['total_rows'] = $this->UserModel->countUsers();
$config['per_page'] = 30;
$config['uri_segment'] = 3;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['prev_link'] = '<';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="current"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['first_link'] = '<<';
$config['last_link'] = '>>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['datatable'] = $this->UserModel->getAllUsers($config["per_page"], $page);
$data['links'] = $this->pagination->create_links();
$data['counter'] = $config['total_rows'];
$data['message']='';
$this->load->view('control/controlMenu/navigationLink');
$this->load->view('control/controlUsers/manageUsers',$data);
$this->load->view('control/controlMenu/navigationJquery');
}
public function searchUser(){
$inputsearchterm = $this->input->post('inputsearchterm');
if($inputsearchterm!=""){
$data['datatable'] = $this->UserModel->searchUser($inputsearchterm);
$data['links'] = '';
$data['counter'] = $this->UserModel->countSearchUser($inputsearchterm);
$data['message']='';
$this->load->view('control/controlMenu/navigationLink');
$this->load->view('control/controlUsers/manageUsers',$data);
$this->load->view('control/controlMenu/navigationJquery');
}else{
redirect('Control/Users');
}
}
View
<?php echo form_open_multipart('Control/Users/searchUser','class="inputform"');?>
<div class="form-group">
<label for="inputsearchterm">Search</label>
<input type="text" class="form-control" id="inputsearchterm" name="inputsearchterm" placeholder="Search">
</div>
<button type="submit" class="btn btn-primary">Search</button>
<?php echo form_close(); ?>
<table class="table">
<thead>
<tr>
<td>Name</td>
<td>IC Number</td>
<td>Passport Number</td>
<td>Email</td>
<td>Phone</td>
</tr>
</thead>
<tbody>
<?php
if(!empty($datatable)){
foreach ($datatable as $dataitem):
$id = $dataitem->id;
?>
<tr>
<td class="name"><?php echo $dataitem->firstname." "; ?><?php echo $dataitem->lastname; ?></td>
<td class="icnumber"><?php echo $dataitem->icNumber; ?></td>
<td class="passportnumber"><?php echo $dataitem->passportNumber; ?></td>
<td class="email"><?php echo $dataitem->email; ?></td>
<td class="phone"><?php echo $dataitem->phone; ?></td>
<td><a class="edituser" href="<?php echo base_url();?>Control/UserDetail/<?php echo $id; ?>/<?php echo "true"; ?>"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>Edit</a></td>
<td><a class="deleteuser" href="<?php echo base_url();?>Control/Users/Users/deleteUser/<?php echo $id; ?>"><i class="fa fa-trash" aria-hidden="true"></i>Delete</a></td>
</tr>
<?php
endforeach;
}
?>
</tbody>
</table>
<p><?php echo $this->session->flashdata('Table'); ?></p>
<?php echo $links; ?>
<p><?php echo $this->session->flashdata('Form'); ?></p>
</div>
Model
public function searchUser($userdetail){
$this->db->select('*');
$this->db->from('Users');
$this->db->like('firstname',$userdetail);
$this->db->or_like('lastname',$userdetail);
$this->db->or_like('email',$userdetail);
$this->db->or_like('phone',$userdetail);
$this->db->or_like('icNumber',$userdetail);
$this->db->or_like('passportNumber',$userdetail);
$query = $this->db->get();
if($query->num_rows()>0){
return $query->result();
}else{
return $query->result();
}
}
public function countSearchUser($userdetail){
$this->db->select('*');
$this->db->from('Users');
$this->db->like('firstname',$userdetail);
$this->db->or_like('lastname',$userdetail);
$this->db->or_like('email',$userdetail);
$this->db->or_like('phone',$userdetail);
$this->db->or_like('icNumber',$userdetail);
$this->db->or_like('passportNumber',$userdetail);
$query = $this->db->count_all_results();
if($query>0){
return $query;
}else{
return 0;
}
}
i think you should add pagination library or check your active query in model
i am searching for 2 days now but still no luck. my problem with my CodeIgniter Pagination is i have set my controller to show 1 data per page i have 2 data which means i have the 1,2 pagination. the [1] page is currently showing the correct data, but when i try to click [2] it still shows the data from the [1] page plus the url is page=1.
here is my Controller
class Campaign extends CI_Controller
{
public function __construct() {
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->model('campaign_model');
$this->load->database();
$this->load->library('pagination');
}
function index() {
$this->load->view('campaign_view');
}
function submit() {
$this->form_validation->set_rules('campaignName', 'Campaign Name', 'trim|required|is_unique[ch_campaigns.c_campaign_name]');
if($this->form_validation->run() == FALSE) {
echo validation_errors();
} else {
$campaignName = $this->input->post('campaignName');
$data = array (
'c_campaign_name' => $campaignName
);
$this->db->insert('ch_campaigns', $data);
echo "YES";
}
}
public function campaigns() {
$data = array();
//pagination settings
$config['base_url'] = site_url('campaigns');
$config['total_rows'] = $this->db->count_all('ch_campaigns');
$config['per_page'] = "1";
$config["uri_segment"] = 3;
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = floor($choice);
//config for bootstrap pagination class integration
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$data['page'] = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
//call the model function to get the department data
$data['campaignlist'] = $this->campaign_model->get_campaign_list($config["per_page"], $data['page']);
//$data['campaignInfo'] = $this->campaign_model->get_campaign_list();
$data['pagination'] = $this->pagination->create_links();
//load the department_view
//print var_export($data, true);
$this->load->view('campaign_view',$data);
}
}
here is my Model
public function __construct() {
parent::__construct();
}
public function get_campaign_list($limit, $start) {
$this->db->select('*');
$this->db->from('ch_campaigns');
$this->db->limit($limit, $start);
$query = $this->db->get();
if($query->num_rows() > 0 ) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
}
lastly my Views
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Campaign Name</th>
<th>Owner</th>
<th>Status</th>
<th>Start Date</th>
<th>End Date</th>
<th>Total Leads</th>
<th> </th>
</tr>
</thead>
<tbody>
<?php foreach($campaignlist as $list) { ?>
<tr>
<td><?php echo $list->c_campaign_name; ?></td>
<td><?php echo $list->c_customer_name; ?></td>
<td><?php echo $list->c_status; ?></td>
<td><?php echo $list->c_start_date; ?></td>
<td><?php echo $list->c_end_date; ?></td>
<td></td>
<td><span class="fa fa-caret-square-o-down"></span>
<ul class="dropdown-menu">
<li>Edit</li>
<li>Delete</li>
</ul>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="main-container-footer text-center">
<?php echo $pagination; ?>
</div>
How can I make this code to list only the sales of the respective vendors? Currently it is displaying all orders.
It is not properly listing the data coming from the database, does not filter properly.
Controller:
function index(){
$this->gerenciar();}
function gerenciar(){
$this->load->library('pagination');
$config['base_url'] = base_url().'index.php/os/gerenciar/';
$config['total_rows'] = $this->os_model->count('os');
$config['per_page'] = 10;
$config['next_link'] = 'Próxima';
$config['prev_link'] = 'Anterior';
$config['full_tag_open'] = '<div class="pagination alternate"><ul>';
$config['full_tag_close'] = '</ul></div>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li><a style="color: #2D335B"><b>';
$config['cur_tag_close'] = '</b></a></li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['first_link'] = 'Primeira';
$config['last_link'] = 'Última';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$this->pagination->initialize($config);
$this->data['results'] = $this->os_model->get('os','idOs,dataInicial,garantia,descricaoProduto,defeito,usuarios_id,status,observacoes,desconto,trocas','',$config['per_page'],$this->uri->segment(3));
$this->data['view'] = 'os/os';
$this->load->view('tema/topo',$this->data);
}
MODEL:
function get($table,$fields,$where='',$perpage=0,$start=0,$one=false,$array='array'){
$this->db->select($fields.',clientes.nomeCliente, clientes.tabelaPreco');
$this->db->from($table);
$this->db->join('clientes','clientes.idClientes = os.clientes_id');
$this->db->limit($perpage,$start);
$this->db->order_by('idOs','desc');
if($where){
$this->db->where($where);
}
$query = $this->db->get();
$result = !$one ? $query->result() : $query->row();
return $result;
}
VIEW:
<?php
foreach ($results as $r) {
if ($this->session->userdata('id') == $r->usuarios_id || $this->session->userdata('id') == '1') {
$dataInicial = date(('d/m/Y'),strtotime($r->dataInicial));
echo '<tr>';
echo '<td>'.$r->idOs.' -'.$r->usuarios_id.'</td>';
echo '<td>'.$r->nomeCliente.'</td>';
echo '<td>'.$dataInicial.'</td>';
echo '<td>'.$r->status.'</td>';
echo '<td>';
if($this->permission->checkPermission($this->session->userdata('permissao'),'vOs')){
echo '<a style="margin-right: 1%" href="'.base_url().'index.php/os/visualizar/'.$r->idOs.'" class="btn tip-top" title="Ver mais detalhes"><i class="icon-eye-open"></i></a>';
}
if($this->permission->checkPermission($this->session->userdata('permissao'),'eOs')){
echo '<a style="margin-right: 1%" href="'.base_url().'index.php/os/editar/'.$r->idOs.'" class="btn btn-info tip-top" title="Editar OS"><i class="icon-pencil icon-white"></i></a>';
}
if($this->permission->checkPermission($this->session->userdata('permissao'),'dOs')){
echo '<i class="icon-remove icon-white"></i> ';
}
echo '</td>';
echo '</tr>';
}
}?>
You are not filtering the records in your model. your $where is empty so the sql will return all the records.
you should get the vendor id from session or parameter and then pass it to your model with a where condition.
why my pagination won't work?
Stuck for 24 hour just for this function. Am i wrong in the database query? I don't understand what's wrong with my code.
Here's the controller:
function search()
{
$category_type = $this->input->post('category_type');
$data['result'] = $this->Grabber_model->get_data($category_type);
$config = array();
$config['base_url'] = base_url() . "grabber/search/index/";
$config['total_rows'] = $this->Grabber_model->count();
$config['per_page'] = 20;
$config['uri_segment'] = 4;
$config['num_links'] = 2;
$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] ="</ul>";
$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_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
$data["links"] = $this->pagination->create_links();
$this->load->view('global_h');
$this->load->view('grabber_view', $data);
$this->load->view('global_f');
}
Heres the model:
function get_data($category_type) {
$this->load->database();
$this->db->select('*');
$this->db->from('products');
$this->db->where('category_type', $category_type);
$this->db->order_by('create_at','desc');
$this->db->limit(50);
$query = $this->db->get();
return $query->result();
}
And this is the view:
<div class="center">
<?php foreach($result as $row){ ?>
<div style="margin:0 10px 10px 0;float:left;width:250px" class="img-thumbnail" >
<img data-original="http://static04-id.zalora.com<?php echo $row->image_full; ?>" width="240px" height="346px" class="lazy" /><br>
Brand: <?php echo $row->brand; ?><br>
SKU: <?php echo $row->sku; ?><br>
</div>
<?php } ?>
<div style="clear:both;text-align:center;"><?php echo $links; ?></div>
</div>
Hope you guys can solve my problem, thank you!
don't know pagination not working means what (Please explain more if you can) but as per my observation you have not added offset in $config array like
$config['offset'] = 'uri_segment or 0'
which you have to use in your query in limit method like
limit(50, $offset);