how to style pagination links without config - codeigniter - codeigniter

I have the following pagination style
<ul class="pagination">
<li><i class="fa fa-long-arrow-left"></i>Previous Page</li>
<li class="active">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>Next Page<i class="fa fa-long-arrow-right"></i></li>
</ul><!--/.pagination-->
i want to make the above static code dynamic without using config
<ul class="pagination">
<?php echo $this->pagination->create_links(); ?>
</ul><!--/.pagination-->
Controller
$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);

Ok i have tried, This Controller code works fine
$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="active"><a href="#">';
$config['cur_tag_close'] = '</a></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>';
$config['prev_link'] = '<i class="fa fa-long-arrow-left"></i>Previous Page';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = 'Next Page<i class="fa fa-long-arrow-right"></i>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$this->pagination->initialize($config);
View
<?php echo $this->pagination->create_links(); ?>

In your controller add this config.
$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="active"><a href="#">';
$config['cur_tag_close'] = '</a></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>';
$config['next_link'] = 'Next Page';
$config['next_tag_open'] = '<li><i class="fa fa-long-arrow-right"></i>';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = 'Previous Page';
$config['prev_tag_open'] = '<li><i class="fa fa-long-arrow-left"></i>';
$config['prev_tag_close'] = '</li>';
$this->pagination->initialize($config);
and in your view just only echo pagination
<?php echo $this->pagination->create_links(); ?>
remove the ul

controller
public function moreNews($pid = 0){ $config['base_url'] =
base_url('index.php/MainController/morenews'); $config['total_rows']
= 200; $config['per_page'] = 5; $config['full_tag_open'] = '<ul class="pagination">'; $config['full_tag_close'] = '</ul>';
$config['first_tag_open'] = "<li class='page-item'>";
$config['first_tag_close'] = "</li>"; $config['prev_tag_open'] =
"<li class='page-item'>"; $config['prev_tag_close'] = "</li>";
$config['next_tag_open'] = "<li class='page-item'>";
$config['next_tag_close'] = "</li>"; $config['last_tag_open'] = "<li
class='page-item'>"; $config['last_tag_close'] = "</li>";
$config['cur_tag_open'] = "<li class='page-item'><a class='page-link
active' href=''>"; $config['cur_tag_close'] = "</a></li>";
$config['num_tag_open'] = "<li class='page-item'>";
$config['num_tag_close'] = "</li>"; $config['attributes'] =
array('class' => 'page-link');
$this->pagination->initialize($config); $data['pagination'] =
$this->pagination->create_links(); $data['news'] =
$this->MainModel->paginationpage($pid); $data['news']=
$this->MainModel->get_news(); //echo '<pre>'; // print_r($data);
$this->load->view('morenews', $data); }`.
model
function paginationpage($pid){ $count=1;
$this->db->select('*')->from('_news')->limit($count, $pid,
$pid+$count); $query=$this->db->get(); return
$query->result_array(); }`.

Related

Pagination with Search Filter in CodeIgniter

When I search a keyword and paginate it, it returns data that matches the like query in the database.
A PHP Error was encountered
Severity: Warning
Message: count(): Parameter must be an array or an object that implements Countable
Filename: admin/view_member.php
Line Number: 105
Backtrace:
File: C:\xampp\htdocs\cms_new\application\views\admin\view_member.php
Line: 105
Function: _error_handler
File: C:\xampp\htdocs\cms_new\application\controllers\admin\Member.php
Line: 63
Function: view
File: C:\xampp\htdocs\cms_new\index.php
Line: 315
Function: require_once
MY Controller
$search = ($this->input->post("member_name"))? $this->input->post("member_name") : "NIL";
$search = ($this->uri->segment(3)) ? $this->uri->segment(3) : $search;
// pagination settings
$config = array();
$config['base_url'] = site_url("admin/member/index/$search");
$config['total_rows'] = $this->Model_member->record_count($search);
$config['per_page'] = "3";
$config["uri_segment"] = 4;
$choice = $config["total_rows"]/$config["per_page"];
$config["num_links"] = floor($choice);
// integrate bootstrap pagination
$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'] = 'Prev';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = 'Next';
$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(4)) ? $this->uri->segment(4) : 0;
// get books list
$data['users'] = $this->Model_member->fetch_data($config['per_page'], $data['page'], $search);
$data['pagination'] = $this->pagination->create_links();
$this->load->view('admin/view_header',$data);
$this->load->view('admin/view_member',$data);
$this->load->view('admin/view_footer');
My Model
function fetch_data($limit, $start, $st = NULL)
{
if($st == "NIL")
$st = "";
$this->db->select('*');
$this->db->from('tbl_member');
$this->db->like('member_name', $st);
$this->db->or_like('member_email', $st);
$this->db->limit($limit, $start);
$query = $this->db->get();
if ($query->num_rows() > 0) {
//var_dump($query->result());
foreach ($query->result() as $row) {
$data[] = $row;
}
//print_r($query);
return $data;
}
if ($query->num_rows() == 0) {
$this->session->set_flashdata('recoard','<div class="alert alert-danger text-center">Record Not Found! </div>');
}
return false;
}
function record_count($st = NULL)
{
if($st == "NIL")
$st = "";
$this->db->select('*');
$this->db->from('tbl_member');
$this->db->like('member_name', $st);
$this->db->or_like('member_email', $st);
$query = $this->db->get();
return $query->num_rows();
var_dump($query->num_rows());
}
My View
<?php
$user = count($users);
var_dump($user);
for ($i = 0; $i < $user; ++$i) {
if(! $users ){
// Faild Message
echo $this->session->flashdata('recoard');
}
else {
?>
<tbody>
<tr>
<td class="text-center"><img class="rounded-circle img-fluid avatar-40" src="<?php echo base_url();; ?>public/uploads/<?php echo $users[$i]->member_photo; ?>" alt="profile"></td>
<td><?php echo $users[$i]->member_name; ?></td>
<td><?php echo $users[$i]->member_email; ?><br>
<?php echo $users[$i]->member_mobile; ?></td>
<td><?php echo $users[$i]->member_city; ?><br>
<?php echo $users[$i]->member_state; ?><br>
<?php echo $users[$i]->member_country; ?></td>
<td><?php echo $users[$i]->member_address; ?></td>
<td>
<?php
if($users[$i]->member_access == 1)
{
echo '<span class="badge iq-bg-primary">Active</span></td>';
}
else
{
echo '<span class="badge iq-bg-warning">Inactive</span></td>';
}
?>
</td>
<td>
<div class="flex align-items-center list-user-action">
<a data-toggle="tooltip" data-placement="top" title="" data-original-title="Change Status" href="<?php echo base_url(); ?>admin/member/change_status/<?php echo $users[$i]->member_id; ?>" onClick="return confirm('Are you sure?');"><i class="ri-user-add-line"></i></a>
<a data-toggle="tooltip" data-placement="top" title="" data-original-title="Edit" href="<?php echo base_url(); ?>admin/member/edit/<?php echo $users[$i]->member_id; ?>"><i class="ri-pencil-line"></i></a>
<a data-toggle="tooltip" data-placement="top" title="" data-original-title="Delete" href="<?php echo base_url(); ?>admin/member/delete/<?php $users[$i]->member_id; ?>" onClick="return confirm('Are you sure?');"><i class="iq-bg-danger ri-delete-bin-line"></i></a>
</div>
</td>
</tr>
</tbody>
<?php } } ?>
you seem to not be returning an array to count & loop over, this is why you have the warning.
Also you have the failed message inside your loop that will make more errors later on.
Hope this helps & works for you
<?php
if (!$users || !is_array($users)) {
// Faild Message
echo $this->session->flashdata('recoard');
} else {
foreach ($users as $user) { ?>
<tbody>
<tr>
<td class="text-center"><img class="rounded-circle img-fluid avatar-40" src="<?php echo base_url("public/uploads/"); ?><?php echo $user->member_photo; ?>" alt="profile"></td>
<td><?php echo $user->member_name; ?></td>
<td><?php echo $user->member_email; ?><br>
<?php echo $user->member_mobile; ?></td>
<td><?php echo $user->member_city; ?><br>
<?php echo $user->member_state; ?><br>
<?php echo $user->member_country; ?></td>
<td><?php echo $user->member_address; ?></td>
<td>
<?php
if ($user->member_access == 1) {
echo '<span class="badge iq-bg-primary">Active</span></td>';
} else {
echo '<span class="badge iq-bg-warning">Inactive</span></td>';
}
?>
</td>
<td>
<div class="flex align-items-center list-user-action">
<a data-toggle="tooltip" data-placement="top" title="" data-original-title="Change Status" href="<?php echo base_url(); ?>admin/member/change_status/<?php echo $user->member_id; ?>" onClick="return confirm('Are you sure?');"><i class="ri-user-add-line"></i></a>
<a data-toggle="tooltip" data-placement="top" title="" data-original-title="Edit" href="<?php echo base_url(); ?>admin/member/edit/<?php echo $user->member_id; ?>"><i class="ri-pencil-line"></i></a>
<a data-toggle="tooltip" data-placement="top" title="" data-original-title="Delete" href="<?php echo base_url(); ?>admin/member/delete/<?php $user->member_id; ?>" onClick="return confirm('Are you sure?');"><i class="iq-bg-danger ri-delete-bin-line"></i></a>
</div>
</td>
</tr>
</tbody>
<?php }
} ?>

One View for Edit and Add in controller function itself using CodeIgniter

I am using in the Below code for edit data as shown below but not working for me.
$tbody .= '<input placeholder="Start Date" id="ed" type="text" class="form-control hasDatepicker" name="start_date" value="'if($config->metrcsettingconf_master_id == $store_products->master_id){ echo $config->metrcsettingconf_startdate} else{ echo ""}'">';
In the code value="" in the input field of form. Add is working fine but after adding data, i want to edit form same company and store selection.
function get_master() {
$store_id = $this->input->post('store_id');
$get_store = $this->common->get_row(array(
'store_id' => $store_id
), DBPREFIX . "store");
$store = $get_store->store_state_id;
$company = $get_store->store_company_id;
$this->session->set_userdata('store', $store);
$this->session->set_userdata('company', $company);
$data['master'] = $master = $this->common->get_whereresult(DBPREFIX . 'apimaster', array('master_status' => 1, 'master_state' => $store), 'master_name');
$tbody = '';
foreach ($master as $store_products) {
$config = $this->common->get_whereresult(DBPREFIX . 'metrcsetting_conf', array('metrcsettingconf_status' => 1, 'metrcsettingconf_master_id' => $store_products->master_id, 'metrcsettingconf_company_id' => $company, 'metrcsettingconf_store_id' => $store_id));
$tbody .= '<div class="row">';
$tbody .= '<div class="form-group col-md-12 col-sm-12 col-xs-12">';
$tbody .= '<div class="panel panel-default">';
$tbody .= '<div class="panel-heading" role="tab" id="headingOne">';
$tbody .= '<h4 class="panel-title" style="height:18px;">';
$tbody .= '<form action="add_metrcsettingmaster/' . $store_products->master_id . '" method="post">';
$tbody .= '<div class="form-group col-md-2 col-sm-2 col-xs-12">';
$tbody .= '<a data-toggle="collapse" data-parent="#accordion" id="master_id" href="#collapseOne'. $store_products->master_id .'" aria-expanded="true" aria-controls="collapseOne'. $store_products->master_id .'">' . $store_products->master_name . '</a>';
$tbody .= '<input id="master_idd" type="hidden" value="' . $store_products->master_id . '">';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-sm-2 col-xs-12 start_date" style="margin-top:-8px;">';
$tbody .= '<input placeholder="Start Date" id="ed" type="text" class="form-control hasDatepicker" name="start_date" value="">';
$tbody .= '<span class="start_datetext">Sync Active</span>';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-sm-2 col-xs-12 end_date" style="margin-top:-8px;">';
$tbody .= '<input placeholder="End Date" id="jd" type="text" class="form-control hasDatepicker" name="end_date" value="">';
$tbody .= '<span class="end_datetext">Sync Expire</span>';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-lg-2 col-sm-2 col-xs-12 time" style="margin-top:-5px;">';
$tbody .= '<input type="time" name="time" class="form-control" value="">';
$tbody .= '<span class="timetext">Sync Time</span>';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-sm-2 col-xs-12" style="margin-top: -5px">';
$tbody .= '<select name="days[]" class="form-control status chosen-select" multiple="multiple">';
$tbody .= '<option value="Monday">Monday</option>';
$tbody .= '<option value="Tuesday">Tuesday</option>';
$tbody .= '<option value="Wednesday">Wednesday</option>';
$tbody .= '<option value="Thursday">Thursday</option>';
$tbody .= '<option value="Friday">Friday</option>';
$tbody .= '<option value="Saturday">Saturday</option>';
$tbody .= '<option value="Sunday">Sunday</option>';
$tbody .= '</select>';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-lg-2 col-sm-2 col-xs-12" style="margin-top:-8px;text-align:center;">';
$tbody .= '<label class="switch">';
$tbody .= '<p style="margin-top:10px;margin-left:-60px;"> Manual </p>';
$tbody .= '<p style="margin-top:-27px;margin-left:60px;"> Auto </p>';
$tbody .= '<input type="checkbox" name="manauto" id="chkPassportt" value="">';
$tbody .= '<span class="slider round"></span>';
//$tbody .= 'form_error('"manauto"');';
$tbody .= '</label>';
$tbody .= '</div>';
$tbody .= '<div class="col-md-2 col-lg-2 col-sm-2 col-xs-12 pull-right" style="margin-top:-8px;">';
$tbody .= '<input class="btn btn-danger" type="submit" name="submit" value="Submit">';
$tbody .= '</div>';
$tbody .= '</form>';
$tbody .= '</h4>';
$tbody .= '</div>';
$tbody .= '<div id="collapseOne'. $store_products->master_id .'" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">';
$tbody .= '<div class="panel-body">';
$tbody .= '<div id="childdata">';
$master_id = $store_products->master_id;
$data['child'] = $child = $this->common->get_whereresult(DBPREFIX . 'apichild', array('child_status' => 1, 'child_master' => $master_id), 'child_apiname');
foreach ($child as $store_products) {
$tbody .= '<div class="row">';
$tbody .= '<div class="form-group col-md-12 col-sm-12 col-xs-12">';
$tbody .= '<div class="panel panel-default">';
$tbody .= '<div class="panel-heading" role="tab" id="headingOne">';
$tbody .= '<h4 class="panel-title" style="height:18px;">';
$tbody .= '<form action="add_metrcsettingchild/' . $store_products->child_id . '" method="post">';
$tbody .= '<div class="form-group col-md-2 col-sm-2 col-xs-12">';
$tbody .= '<a data-toggle="collapse" data-parent="#accordion" id="child_id" href="#collapseOne'. $store_products->child_id .'" aria-expanded="true" aria-controls="collapseOne'. $store_products->child_id .'">' . $store_products->child_apiname . '</a>';
$tbody .= '<input id="child_idd" type="hidden" value="' . $store_products->child_id . '">';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-sm-2 col-xs-12 start_date" style="margin-top:-8px;">';
$tbody .= '<input placeholder="Start Date" id="ed" type="text" class="form-control hasDatepicker" name="start_date" value="">';
$tbody .= '<span class="start_datetext">Sync Active</span>';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-sm-2 col-xs-12 end_date" style="margin-top:-8px;">';
$tbody .= '<input placeholder="End Date" id="jd" type="text" class="form-control hasDatepicker" name="end_date" value="">';
$tbody .= '<span class="end_datetext">Sync Expire</span>';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-lg-2 col-sm-2 col-xs-12 time" style="margin-top:-5px;">';
$tbody .= '<input type="time" name="time">';
$tbody .= '<span class="timetext">Sync Time</span>';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-sm-2 col-xs-12" style="margin-top: -5px">';
$tbody .= '<select name="days[]" class="form-control status chosen-select" multiple="multiple">';
$tbody .= '<option value="Monday">Monday</option>';
$tbody .= '<option value="Tuesday">Tuesday</option>';
$tbody .= '<option value="Wednesday">Wednesday</option>';
$tbody .= '<option value="Thursday">Thursday</option>';
$tbody .= '<option value="Friday">Friday</option>';
$tbody .= '<option value="Saturday">Saturday</option>';
$tbody .= '<option value="Sunday">Sunday</option>';
$tbody .= '</select>';
$tbody .= '</div>';
$tbody .= '<div class="form-group col-md-2 col-lg-2 col-sm-2 col-xs-12" style="margin-top:-8px;text-align:center;">';
$tbody .= '<label class="switch">';
$tbody .= '<p style="margin-top:10px;margin-left:-60px;"> Manual </p>';
$tbody .= '<p style="margin-top:-27px;margin-left:60px;"> Auto </p>';
$tbody .= '<input type="checkbox" name="manauto" id="chkPassportt">';
$tbody .= '<span class="slider round"></span>';
//$tbody .= 'form_error('"manauto"');';
$tbody .= '</label>';
$tbody .= '</div>';
$tbody .= '<div class="col-md-2 col-lg-2 col-sm-2 col-xs-12 pull-right" style="margin-top:-8px;">';
$tbody .= '<input class="btn btn-danger" type="submit" name="submit" value="Submit">';
$tbody .= '</div>';
$tbody .= '</form>';
$tbody .= '</h4>';
$tbody .= '</div>';
$tbody .= '<div id="collapseOne'. $store_products->child_id .'" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">';
$tbody .= '<div class="panel-body">';
$tbody .= '<div id="childdata"></div>';
$tbody .= '</div>';
$tbody .= '</div>';
$tbody .= '</div>';
$tbody .= '</div>';
$tbody .= '</div>';
}
$tbody .= '</div>';
$tbody .= '</div>';
$tbody .= '</div>';
$tbody .= '</div>';
$tbody .= '</div>';
$tbody .= '</div>';
}
echo $tbody;
}
In the code value="" in the input field of form. Add is working fine but after adding data, i want to edit form.

retrive two uploaded images in two separate pages of a same web page

This is my controller with index function and index2 function to upload two images
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Upload_Files extends CI_Controller
{
function __construct() {
parent::__construct();
$this->load->model('file');
}
function index(){
$data = array();
if($this->input->post('fileSubmit') && !empty($_FILES['userFiles']['name'])){
$filesCount = count($_FILES['userFiles']['name']);
for($i = 0; $i < $filesCount; $i++){
$_FILES['userFile']['name'] = $_FILES['userFiles']['name'][$i];
$_FILES['userFile']['type'] = $_FILES['userFiles']['type'][$i];
$_FILES['userFile']['tmp_name'] = $_FILES['userFiles']['tmp_name'][$i];
$_FILES['userFile']['error'] = $_FILES['userFiles']['error'][$i];
$_FILES['userFile']['size'] = $_FILES['userFiles']['size'][$i];
$uploadPath = 'uploads/files/';
$config['upload_path'] = $uploadPath;
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if($this->upload->do_upload('userFile')){
$fileData = $this->upload->data();
$uploadData[$i]['file_name'] = $fileData['file_name'];
$uploadData[$i]['created'] = date("Y-m-d H:i:s");
$uploadData[$i]['modified'] = date("Y-m-d H:i:s");
}
}
if(!empty($uploadData)){
//Insert file information into the database
$insert = $this->file->insert($uploadData);
$statusMsg = $insert?'Files uploaded successfully.':'Some problem occurred, please try again.';
$this->session->set_flashdata('statusMsg',$statusMsg);
}
}
//Get files data from database
$data['files'] = $this->file->getRows();
//Pass the files data to view
$this->load->view('upload_files', $data);
}
function index2(){
$data = array();
if($this->input->post('fileSubmit2') && !empty($_FILES['userFiles']['name'])){
$filesCount = count($_FILES['userFiles']['name']);
for($i = 0; $i < $filesCount; $i++){
$_FILES['userFile']['name'] = $_FILES['userFiles']['name'][$i];
$_FILES['userFile']['type'] = $_FILES['userFiles']['type'][$i];
$_FILES['userFile']['tmp_name'] = $_FILES['userFiles']['tmp_name'][$i];
$_FILES['userFile']['error'] = $_FILES['userFiles']['error'][$i];
$_FILES['userFile']['size'] = $_FILES['userFiles']['size'][$i];
$uploadPath = 'uploads/index2/';
$config['upload_path'] = $uploadPath;
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if($this->upload->do_upload('userFile')){
$fileData = $this->upload->data();
$uploadData[$i]['file_name'] = $fileData['file_name'];
$uploadData[$i]['created'] = date("Y-m-d H:i:s");
$uploadData[$i]['modified'] = date("Y-m-d H:i:s");
$uploadData[$i]['divid'] =2;
}
}
if(!empty($uploadData)){
//Insert file information into the database
$insert = $this->file->insert($uploadData);
$statusMsg = $insert?'Files uploaded successfully.':'Some problem occurred, please try again.';
$this->session->set_flashdata('statusMsg',$statusMsg);
}
}
//Get files data from database
$data['files'] = $this->file->getRows2();
//Pass the files data to view
$this->load->view('upload_files', $data);
}
}
This is my model to retrieve images from databases
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class File extends CI_Model{
public function getRows($id = ''){
$this->db->select('id,file_name,created');
$this->db->from('files');
if($id){
$this->db->where('divid',1);
$query = $this->db->get();
$result = $query->row_array();
}else{
$this->db->order_by('created','desc');
$query = $this->db->get();
$result = $query->result_array();
}
return !empty($result)?$result:false;
}
public function insert($data = array()){
$insert = $this->db->insert_batch('files',$data);
return $insert?true:false;
}
public function getRows2($id = ''){
$this->db->select('id,file_name,created');
$this->db->from('files');
if($id){
$this->db->where('divid',2);
$query = $this->db->get();
$result = $query->row_array();
}else{
$this->db->order_by('created','desc');
$query = $this->db->get();
$result = $query->result_array();
}
return !empty($result)?$result:false;
}
public function insert2($data = array()){
$insert = $this->db->insert_batch('files',$data);
return $insert?true:false;
}
}
This is my view to upload 2 images and view those 2 images
<div class="container">
<div class="row">
<p><?php echo $this->session->flashdata('statusMsg'); ?></p>
<form enctype="multipart/form-data" action="<?php echo site_url('Upload_Files/index'); ?>" method="post">
<div class="form-group">
<label>Choose Files1</label>
<input type="file" class="form-control" name="userFiles[]" multiple/>
</div>
<div class="form-group">
<input class="form-control" type="submit" name="fileSubmit" value="UPLOAD"/>
</div>
</form>
</div>
<div class="row">
<ul class="gallery">
<?php if(!empty($files)): foreach($files as $file): ?>
<li class="item">
<img src="<?php echo base_url('uploads/files/'.$file['file_name']); ?>" alt="" >
<p>Uploaded On <?php echo date("j M Y",strtotime($file['created'])); ?></p>
</li>
<?php endforeach; else: ?>
<p>Image(s) not found.....</p>
<?php endif; ?>
</ul>
</div>
</div>
<div class="container">
<div class="row">
<p><?php echo $this->session->flashdata('statusMsg'); ?></p>
<form enctype="multipart/form-data" action="<?php echo site_url('Upload_Files/index2'); ?>" method="post">
<div class="form-group">
<label>Choose Files1</label>
<input type="file" class="form-control" name="userFiles[]" multiple/>
</div>
<div class="form-group">
<input class="form-control" type="submit" name="fileSubmit2" value="UPLOAD"/>
</div>
</form>
</div>
<div class="row">
<ul class="gallery">
<?php if(!empty($files)): foreach($files as $file): ?>
<li class="item">
<img src="<?php echo base_url('uploads/index2/'.$file['file_name']); ?>" alt="" >
<p>Uploaded On <?php echo date("j M Y",strtotime($file['created'])); ?></p>
</li>
<?php endforeach; else: ?>
<p>Image(s) not found.....</p>
<?php endif; ?>
</ul>
</div>
</div>
My problem is when I upload one image it appears in the other image view also. I tried so hard and put this question 2 times in stackoverflow. If someone helps me It will be a great thing

Error: Syntax error, unrecognized expression: javascript:TagPopup_OpenForm(

I am getting this error.It is running perfectly on localhost.
Error: Syntax error, unrecognized expression: javascript:TagPopup_OpenForm("TagPopup_FormContainer1","TagPopup_FormContainerBody1","TagPopup_FormContainerFooter1");
This is my shortcode function in wordpress plugin
$siteurl = "'" . home_url() . "'";
$close = 'javascript:TagPopup_HideForm("TagPopup_FormContainer1","TagPopup_FormContainerFooter1");';
$open = 'javascript:TagPopup_OpenForm("TagPopup_FormContainer1","TagPopup_FormContainerBody1","TagPopup_FormContainerFooter1");';
$html = "<a href='" . $open . "'><div class='login-user'>login</div></a>";
$html .= "<div style='display: none;' id='TagPopup_FormContainer1'>";
$html .= "<div id='TagPopup_FormContainerHeader'>";
$html .= '<div id="TagPopup_FormClose">' . __('X', 'tag-popup') . '</div>';
$html .= '<div id="TagPopup_FormTitle"> ' . __('', 'tag-popup') . wpautop(wp_kses_post($pull_atts['title']));
$html .= '</div>';
$html .= '</div>';
$html .= '<br><hr>';
$html .= '<div id="TagPopup_FormContainerBody1">';
$html .= '<form method="post" action="" name="single_form" id="id_single_Form" onsubmit="return validation_login(this)">';
$html .= '<div id="username-div">';
$html .= '<input name="username" class="username" type="text" id="id_username_login" Placeholder="Username" maxlength="120">';
$html .= '</div>';
$html .= '<div id="password-div">';
$html .= '<input name="password" class="password" type="password" id="id_password_login" Placeholder="Password" maxlength="120">';
$html .= '</div>';
$html .= '<div id="TagPopup_FormLabel_Page">';
$html .= '<input type="submit" name="login" class="login_submit" value="Login" >';
if (!is_home()) {
$html .= ' < Homepage';
}
$html .= 'New user?';
$html .= '</div>';
$html .= '</form>';
$html .= '</div>';
$html .= '</div>';
$html .= '<div style="display: none;" id="TagPopup_FormContainerFooter1"></div>';
return $html;
}

How to show children's subcategorie's of current categorie in Magento

I am trying to get my big catalog somewhat tablet friendly by offering an selection of tabs with sublevel links for my seperate categories. So if a user clicks a (1st level)head category it needs to display a nr of blocks which hold the picture, description and url of each direct child and a list of all the underlying (3rd level) child categories of the shown (2nd level) categorie. Would any off you guys be so kind to check my code?
<?php
$layer = Mage::getSingleton('catalog/layer');
$_category = $layer->getCurrentCategory();
$_categories = $_category->getCollection()
->addAttributeToSelect(array('url_key','name','image','all_children','is_anchor','description'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($_category->getChildren())
->setOrder('position', 'ASC')
->joinUrlRewrite();
?>
<?php $children = explode( ",", $this->getCurrentCategory()->getChildren() ); ?>
<ul class="category-grid">
<div class="category-list">
<?php foreach( $children as $child ): ?>
<?php $_child = Mage::getModel( 'catalog/category' )->load( $child ); ?>
<li class="item">
<img title="<?php echo $this->htmlEscape($_child->getName()) ?>" src="<?php echo $this->htmlEscape($_child->getImageUrl()) ?>" alt="<?php echo $this->htmlEscape($_child->getName()) ?>" />
<div class="subcategory-title">
<?php echo $this->htmlEscape($_child->getName()) ?>
</div>
<div class="description-block"> <?php echo $_child->getDescription(); ?></div>
<div class="children-links"><?php
$_helper = Mage::helper("catalog/category");
$rootCat = Mage::app()->getStore()->getRootCategoryId();
$current = Mage::registry('current_category');
if ($child){
//look for anchestor
$parentid = $child->getParentId();
$parent = Mage::getModel("catalog/category")->load($parentid);
if($parentid != $rootCat)
{
//find the anchestor
show_cat($parent,$_helper,$rootCat);
}else{
//is root
$_subcategories = $child->getChildrenCategories();
echo $_child->getAll_Children();
if(count($_subcategories)>0){
echo '<ul>';
foreach($_subcategories as $_category){
echo '<li>';
echo ''.$_category->getName().'';
if($child->getId() == $_category->getId()){
$current = Mage::registry('current_category');
if ($current){
//handle current
$_current_subcategories = $current->getChildrenCategories();
if(count($_current_subcategories)>0){
//the current cat has childrens
echo '<ul>';
foreach($_current_subcategories as $_sub_category){
echo '<li>';
echo ''.$_sub_category->getName().'';
echo '</li>';
}
echo '</ul>';
}else{
//the current cat has no childrens
$current_parent = $current->getParentId();
$current_parent = Mage::getModel("catalog/category")->load($current_parent );
$_current_subcategories = $current_parent ->getChildrenCategories();
echo '<ul>';
foreach($_current_subcategories as $_sub_category){
echo '<li>';
echo ''.$_sub_category->getName().'';
echo '</li>';
}
echo '</ul>';
}
}
}
echo '</li>';
}
echo '</ul>';
}
}
}
?>
</div>
</li>
<?php endforeach ?>
</div>
</ul>
you can this by the below code and also refer link at bottom
you could be go with this
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<ul class="category">
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
<?php if ($currentCategory->getId() && $currentCategory->getId() == $_category->getId()): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<?php if (count($_subcategories) > 0): ?>
<ul class="subcategory">
<?php foreach($_subcategories as $_subcategory): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
<?php echo $_subcategory->getName() ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
EDIT
<ul class="subcategory">
<? foreach ($_categories as $_category):?>
<? if($_category->getIsActive()):
$cur_subcategory=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_subcategory);
?>
<li> <?php echo $_category->getName()?></li>
<? endif;?>
<?endforeach?>
</ul>
Or you can go throw this Detail documentation, i am sure that would be really helpful to you.
// get current category
$current_category = $layer->getCurrentCategory();
// get sub categories of current category
$parent_categories = Mage::getModel('catalog/category')->getCategories($current_category->getId());
// go through each sub category and get their sub categories.
foreach($parent_categories as $child_category)
{
$child_category_id = $child_category->getId();
$grandchild_categories = Mage::getModel('catalog/category')->getCategories($child_category_id);
}
Here is the tested code for showing sub categories. Just put this code above "Toolbar" code in your custom theme "Magento_catalog/templet/product/list.phtml"
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category
$subcats = $category->getChildrenCategories();
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$imageHelper = \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Catalog\Helper\Image::class);
if(count ($subcats) > 0)
{
?>
<div class = "sub-cat-div">
<ul class = "sub-cat-main">
<?php
foreach ($subcats as $subcat) {
if ($subcat->getIsActive()) {
$_category = $objectManager->create('Magento\Catalog\Model\Category')->load($subcat->getId());
$_outputhelper = $this->helper('Magento\Catalog\Helper\Output');
$subcaturl = $_category->getUrl();
$_imgHtml = '';
if ($_imgUrl = $_category->getImageUrl()) {
$_imgHtml = '<img src="' . $_imgUrl . '" />';
$_imgHtml = $_outputhelper->categoryAttribute($_category, $_imgHtml, 'image');
echo '<li class="sub-cat-image">' . $_imgHtml . '<span style="background-color: rgba(255,255,255,0.9)" class="content bg-white"><strong>' . $_category->getName() . '</strong></span></li>';
}
else{
$_imgUrl = $imageHelper->getDefaultPlaceholderUrl('image');
$_imgHtml = '<img src="' . $_imgUrl . '" />';
$_imgHtml = $_outputhelper->categoryAttribute($_category, $_imgHtml, 'image');
echo '<li class="sub-cat-image">' . $_imgHtml . '<span style="background-color: rgba(255,255,255,0.9)" class="content bg-white"><strong>' . $_category->getName() . '</strong></span></li>';
}
}
} ?>
</ul>
</div>
<?php
}
?>

Resources