How to create pagination with letters using codeigniter - codeigniter

Agent controller:
public function index() {
if (!empty($_SESSION['admin'])) {
$data = array(
'page_title' => 'Agent',
'page_name' => 'agent/index',
'result' => $this->agent_model->list_all()
);
$this->load->view('template', $data);
} else {
redirect('login');
}
}
Agent model:
public function list_all() {
$data = 'agent.id,agent.name,agent.mobile,agent.vehicle,agent.address,agent.img_url,agent.category,agent.status,agent.login_status,vehicle.id AS vehicle_id,vehicle.name AS vehicle_name';
$this->db->select($data);
$this->db->from('agent');
$this->db->join('vehicle', 'agent.vehicle=vehicle.id');
return $this->db->get()->result_array();
}
View:
<?php foreach ($result as $value): ?>
<div class="col-md-4 col-sm-4 col-xs-12 profile_details">
<div class="well profile_view">
<div class="col-sm-12">
<h4 class="brief"><i>Digital Strategist</i></h4>
<div class="left col-xs-7">
<p><i class="fa fa-user"></i> Name: <?= $value['name']; ?></p>
<ul class="list-unstyled">
<li><i class="fa fa-building"></i> Vehicle: <?= $value['vehicle_name']; ?></li>
<li><i class="fa fa-phone"></i> Mobile: <?= $value['mobile']; ?> </li><br/>
<div class="onoffswitch">
<input type="hidden" value="<?= $value["id"]; ?>"/>
<input type="checkbox" class="js-switch"
<?php if ($value['status'] == 1) {
echo "checked";
} ?>>
</div>
</ul>
</div>
<div class="right col-xs-5 text-center">
<img src="/<?= $value['img_url']; ?>" alt="" class="img-circle img-responsive" style="height: 120px; width: 120px;">
</div>
</div>
<div class="col-xs-12 bottom text-center">
<div class="col-xs-12 col-sm-6 emphasis">
<p class="ratings">
<a>4.0</a>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star-o"></span>
</p>
</div>
<div class="col-xs-12 col-sm-6 emphasis btn-group">
<?php if ($value['status'] == 1): ?>
<i class="glyphicon glyphicon-pencil"> </i> Edit
<?php else: ?>
<i class="glyphicon glyphicon-pencil"> </i> Edit
<?php endif; ?>
<a href="<?= base_url("agent/detail/{$value['id']}"); ?>" class="btn btn-primary btn-xs">
<i class="fa fa-user"> </i> View Profile </a>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
Below Screenshot:
Screenshot
MY Question: How to create pagination with letters in codeigniter.
MY Question: I create agent module and i apply pagination with letters in above Screenshot. so how to apply pagination with letters in above view.

Related

search in PHP Array, similar to MySQL Like %var% search with livewire

I saw other questions that usually use preg_grep but my problem was not solved
In the LiveWire component, I receive information from the web service and display it in a table.
Now the user does the search and I want to display the items that look like the searched phrase
I wrote the code like this:
class Cryptolist extends Component
{
use WithPagination;
public bool $loadData = false;
protected $paginationTheme = 'bootstrap';
public $perPage = 10;
public $search = '';
public function init()
{
$this->loadData = true;
}
public function getBalance($asset)
{
$this->dispatchBrowserEvent('setPrice' ,[
'asset' => $asset,
'price' => getCryptoBalance($asset)
]);
}
public function setPerPage(int $page)
{
$this->perPage = $page;
}
public function render()
{
try {
if ($this->loadData == true) {
$api = new \Binance\API('','');
$coins = $api->coins();
} else {
$coins = [];
}
return view('livewire.backend.crypto.cryptolist')->with('coins' , collect(preg_grep('~'.$this->search.'~i', $coins))->paginate($this->perPage));
}catch(\Exception $e)
{
return view('wrong')->with('e' , $e);
}
}
}
and this is view:
<div class="nk-block" id="loadesh1" >
<div class="card card-bordered card-stretch">
<div class="card-inner-group">
<div class="card-inner position-relative card-tools-toggle">
<div class="card-title-group">
<div class="card-tools mr-n1">
<ul class="btn-toolbar gx-1">
<li>
<a class="btn btn-icon search-toggle toggle-search" data-target="search" href="#"><em class="icon ni ni-search"></em></a>
</li>
<li class="btn-toolbar-sep"></li>
<li>
<div class="toggle-wrap">
<a class="btn btn-icon btn-trigger toggle" data-target="cardTools" href="#"><em class="icon ni ni-menu-right"></em></a>
<div class="toggle-content" data-content="cardTools">
<ul class="btn-toolbar gx-1">
<li class="toggle-close">
<a class="btn btn-icon btn-trigger toggle" data-target="cardTools" href="#"><em class="icon ni ni-arrow-left"></em></a>
</li>
<li>
<div class="dropdown">
<a class="btn btn-trigger btn-icon dropdown-toggle" data-toggle="dropdown" href="#"><em class="icon ni ni-setting"></em></a>
<div class="dropdown-menu dropdown-menu-xs dropdown-menu-right">
<ul class="link-check">
<li><span>show</span></li>
<li #if($perPage === 10) class="active" #endif>
10
</li>
<li #if($perPage === 20) class="active" #endif>
20
</li>
<li #if($perPage === 50) class="active" #endif>
50
</li>
</ul>
</div>
</div>
</li>
</ul>
</div>
</div>
</li>
</ul>
</div>
</div>
<div class="card-search search-wrap" data-search="search">
<div class="card-body">
<div class="search-content">
<a class="search-back btn btn-icon toggle-search" data-target="search" href="#"><em class="icon ni ni-arrow-left"></em></a><input wire:model="search" class="form-control border-transparent form-focus-none" placeholder="type for search" type="text"><button class="search-submit btn btn-icon"><em class="icon ni ni-search"></em></button>
</div>
</div>
</div>
</div>
<div class="card-inner p-0" wire:init="init">
<div class="nk-tb-list nk-tb-ulist">
<div class="nk-tb-item nk-tb-head">
<div class="nk-tb-col">
<span class="sub-text">name</span>
</div>
<div class="nk-tb-col tb-col-mb">
<span class="sub-text">balance</span>
</div>
</div>
#foreach ($coins as $item => $value)
<div class="nk-tb-item">
<div class="nk-tb-col">
<a href="/demo5/user-details-regular.html">
<div class="user-card">
<div class="user-avatar d-none d-sm-flex">
#if(file_exists(public_path() . '/img/crypto/'.strtolower($value['coin'].".svg")))
<img style="border-radius: 0" src="{{asset('/img/crypto/'.strtolower($value['coin']))}}.svg" class="img-fluid" alt="">
#else
<img style="border-radius: 0" src="https://demo.rayanscript.ir/-/vendor/cryptocurrency-icons/32/color/noimage.png" class="img-fluid" alt="">
#endif
</div>
<div class="user-info">
<span class="tb-lead english" style="font-weight: bolder">{{$value['name']}}</span>
<span class="english">{{$value['coin']}}</span>
</div>
</div>
</a>
</div>
<div class="nk-tb-col tb-col-mb">
<div class="btn-group" aria-label="Basic example">
<button type="button" class="btn btn-sm btn-dim btn-light" wire:click="getBalance('{{$value['coin']}}')">
<div wire:loading wire:target="getBalance('{{$value['coin']}}')">
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
</div>
<span class="w-120px" id="coin-{{$value['coin']}}">get balance</span>
</button>
<button type="button" class="btn btn-sm btn-dim btn-primary">add coin</button>
</div>
</div>
</div>
#endforeach
</div>
</div>
</div>
</div>
</div>
But this error is given. Is my search method correct?
Array to string conversion

intigrate wysiwyg with codeigniter

I'm using codeigniter and trying to pass content to the database using the WYSIWYG editor.
I installed the WYSIWYG into my VIEW like the below code.
<div class="blank">
<div class="blank-page">
<!------------- syam bek-------------->
<?php if(!empty($error)): ?>
<div class="alert alert-warning">
<strong>Warning!</strong> <?php echo $error; ?>
</div>
<?php endif;?>
<?php if(!empty($products)):?>
<?php $ver=array('id'=>'try','name'=>'try','class'=>'form-horizontal'); ?>
<?php echo form_open_multipart(base_url().'editproduct/edit',$ver);?>
<label>المنتج
<br>
<select class="selectpicker" data-show-subtext="true" data-live-search="true" name="select_product" onchange="[document.try.action='editproduct/show',document.try.submit()]">
<?php
if (count($products)>1) {
echo '<option selected></option>';
foreach ($products as $p):
echo "<option value ='$p->p_id'>" . $p->p_name . "</option>";
endforeach;
}
elseif(count($products)==1){
foreach ($products as $p):
echo "<option selected value ='$p->p_id'>" . $p->p_name . "</option>";
endforeach;
}
?>
</select>
<?php if(count($products)==1){
$name=$p->p_name;
$details=$p->details;
$price=$p->p_price;
}else{
$name="";
$details="";
$price="";
}
?>
</label>
</br>
<label>اسم المنتج
<input type="text" name="name" value="<?php echo $name;?>" class="form-control"/>
</label>
<br>
<label>تفاصيل للمنتج
<input type="text" name="details" value="<?php echo $details;?>" class="form-control" />
</label>
<br>
<label>سعر المنتج
<input type="text" name="price" value="<?php echo $price;?>" class="form-control" />
</label>
<br>
<br>
<br>
<div class="container">
<div class="hero-unit">
<div id="alerts"></div>
<div class="btn-toolbar" data-role="editor-toolbar" data-target="#editor">
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" title="Font"><i class="icon-font"></i><b class="caret"></b></a>
<ul class="dropdown-menu">
</ul>
</div>
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" title="Font Size"><i class="icon-text-height"></i> <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a data-edit="fontSize 5"><font size="5">Huge</font></a></li>
<li><a data-edit="fontSize 3"><font size="3">Normal</font></a></li>
<li><a data-edit="fontSize 1"><font size="1">Small</font></a></li>
</ul>
</div>
<div class="btn-group">
<a class="btn" data-edit="bold" title="Bold (Ctrl/Cmd+B)"><i class="icon-bold"></i></a>
<a class="btn" data-edit="italic" title="Italic (Ctrl/Cmd+I)"><i class="icon-italic"></i></a>
<a class="btn" data-edit="strikethrough" title="Strikethrough"><i class="icon-strikethrough"></i></a>
<a class="btn" data-edit="underline" title="Underline (Ctrl/Cmd+U)"><i class="icon-underline"></i></a>
</div>
<div class="btn-group">
<a class="btn" data-edit="insertunorderedlist" title="Bullet list"><i class="icon-list-ul"></i></a>
<a class="btn" data-edit="insertorderedlist" title="Number list"><i class="icon-list-ol"></i></a>
<a class="btn" data-edit="outdent" title="Reduce indent (Shift+Tab)"><i class="icon-indent-left"></i></a>
<a class="btn" data-edit="indent" title="Indent (Tab)"><i class="icon-indent-right"></i></a>
</div>
<div class="btn-group">
<a class="btn" data-edit="justifyleft" title="Align Left (Ctrl/Cmd+L)"><i class="icon-align-left"></i></a>
<a class="btn" data-edit="justifycenter" title="Center (Ctrl/Cmd+E)"><i class="icon-align-center"></i></a>
<a class="btn" data-edit="justifyright" title="Align Right (Ctrl/Cmd+R)"><i class="icon-align-right"></i></a>
<a class="btn" data-edit="justifyfull" title="Justify (Ctrl/Cmd+J)"><i class="icon-align-justify"></i></a>
</div>
<div class="btn-group">
<a class="btn" title="Insert picture (or just drag & drop)" id="pictureBtn"><i class="icon-picture"></i></a>
<input type="file" data-role="magic-overlay" data-target="#pictureBtn" data-edit="insertImage" />
</div>
<div class="btn-group">
<a class="btn" data-edit="undo" title="Undo (Ctrl/Cmd+Z)"><i class="icon-undo"></i></a>
<a class="btn" data-edit="redo" title="Redo (Ctrl/Cmd+Y)"><i class="icon-repeat"></i></a>
</div>
<input type="text" data-edit="inserttext" id="voiceBtn" x-webkit-speech="">
</div>
<div id="editor">
</div>
</div>
</div>
<button class="btn btn-warning" name="cancel" >الغاء</button>
<button type="submit" name="save" class="btn btn-primary">حفظ</button>
<button type="submit" name="del" class="btn btn-danger">حذف المنتج</button>
<?php echo form_close();?>
<?php else :?>
<?php echo "لايوجد منتجات ليتم التعديل عليها";?>
<?php endif;?>
</div>
</div>
check i trace the inspector from the broswer i found insertion happens in the <div id="editor">HERE</div>
i don't know to pass the DIV contents to the database, especially the DIV element not identified by name like other elements.
Thanks
You can use javascript and ajax to submit your form, this is rough outline of jquery solution
// listen for submit event on your form
$( "#try" ).submit(function( event ) {
event.preventDefault();
let content = $('#editor').val(); // get the value from the editor
let details = $("input[name='details']").val() // get the value of input with the name of 'details'
... // do the same for all other inputs
// validate inputs if desired
if(content == '') {
// for example do something if content is empty
return;
}
// collect all input data into one object
var data = {
content: content,
details: details,
...
}
// send ajax request to the server
$.ajax({
url : 'urlToYourBackendEndpoint',
type : 'POST',
data : data,
success : function(response) {
// check the response and redirect or show notice after submit here
},
error : function(request,error)
{
alert("Request: "+JSON.stringify(request));
}
});
});

How can fixed the codeigniter cart update issue

I am unable to update cart on checkout page. I do not know what is Happen.
Here is my code.
function update_cart()
{
$rowid =$this->input->post('rowid');
$price =$this->input->post('price');
$qty = $this->input->post('qty');
$pr = preg_replace( '/,/', '', $price);
$amount = $pr * $qty;
$data = array(
'rowid' => $rowid,
'price' => $price,
'amount' => $amount,
'qty' => $qty
);
$this->cart->update($data);
redirect('checkout');
}
Here is my car view code .I am trying to update cart value here.No error showing. I unable to solve .Any help .Only update cart is not working . Other functionality is working good .add to cart delete to cart but update to cart does not working . I create session table and also try other suggestion and solution form stack overflow.
<form action="<?=base_url()?>cart/update_cart" method="post">
<div class="panel panel-info">
<div class="panel-heading">
<div class="panel-title">
<div class="row">
<div class="col-xs-6">
<h5><span class="glyphicon glyphicon-shopping-cart"></span> Shopping Cart</h5>
</div>
<div class="col-xs-6">
<a href="<?=base_url()?>">
<button type="button" class="btn btn-primary btn-sm btn-block">
<span class="glyphicon glyphicon-share-alt"></span> Continue shopping
</button>
</a>
</div>
</div>
</div>
</div>
<div class="panel-body">
<?php $i = 1; ?>
<?php
//print_r($this->cart->contents() );
//die;
foreach ($this->cart->contents() as $items): ?>
<?php echo form_hidden($i.'[rowid]', $items['rowid']); ?>
<div class="row">
<div class="col-xs-2">
<img class="img-responsive" src="<?=base_url()?>uploads/product/<?=$items['image'];?>" />
</div>
<div class="col-xs-4">
<h5 class="product-name">
<strong><?php echo $items['name']; ?>
</strong>
<?=$items['options'];?>
</h5>
</div>
<div class="col-xs-6">
<div class="col-xs-6 text-right">
<h6><strong><?= $this->cart->format_number($items['price']); ?>
<span class="text-muted">x</span></strong></h6>
</div>
<div class="col-xs-4">
<?php //echo form_input(array('name' => $i.'[qty]', 'value' => $items['qty'], 'size' => '1')); ?>
<input type="text" name="qty" min="1" value="<?=$items['qty'] ?>" maxlength="1" style="width: 50%;">
<input type="hidden" name="price" value="<?=$items['price'] ?>">
<input type="hidden" name="name" value="<?=$items['name'] ?>">
<input type="hidden" name="description" value="<?=$items['description'] ?>">
</div>
<div class="col-xs-2">
<a href="<?=base_url()?>cart/remove/<?=$items['rowid']?>">
<button type="button" class="btn btn-link btn-xs">
<span class="glyphicon glyphicon-trash" onclick="confirm('Are you sure want to delete')";> </span>
</button>
</a>
</div>
</div>
</div>
<hr>
<?php $i++; ?>
<?php endforeach; ?>
at view .... use only two input
<input type="text" name="qty[]" min="1" value="<?=$items['qty'] ?>" maxlength="1" style="width: 50%;">
<input type="hidden" name="rowid[]" value="<?=$items['rowid'] ?>">
at controller
you only need to change qty if you are going to update a cart
function update_cart()
{
for ($i=0; $i < count($_POST) - 1; $i++) {
$data = array(
'rowid' => $_POST['rowid'][$i],
'qty' => $_POST['qty'][$i]
);
$this->cart->update($data);
}
redirect('checkout');
}

why does $this->form_validation->run() always return false in codeigniter 3.0.0 with php7.1 on ubuntu 16.04?

This is part of the code, it made me cannot login, i don't know where is the problem. When i tried to log in, it has no effect. Sorry for my bad english.
public function login()
{
if ($this->identity->is_admin())
redirect('admin/dashboard');
if ($this->identity->is_contestant())
redirect('contestant/dashboard');
$this->form_validation->set_rules('form[username]', $this->lang->line('username'), 'trim|required|max_length[50]');
$this->form_validation->set_rules('form[password]', $this->lang->line('password'), 'trim|required|max_length[50]');
if ($this->form_validation->run())
{
$credentials = $this->input->post('form');
if ($this->identity->login($credentials))
{
if ($this->identity->is_admin())
redirect('admin/dashboard');
else
redirect('contestant/dashboard');
}
else
{
$this->session->set_flashdata('error', $this->lang->line('wrong_credentials'));
redirect('site/login');
}
}
else
{
$this->ui['header']['title'] = $this->lang->line('login');
$this->ui['header']['page'] = 'login';
$this->load->view('site/header', $this->ui['header']);
$this->load->view('site/login', $this->ui['content']);
$this->load->view('footer', $this->ui['footer']);
}
}
Here are the login site source code.
<div class="container">
<div class="row">
<div class="col-md-12">
<ul class="breadcrumb">
<li>
<i class="glyphicon glyphicon-off"></i> <?php echo $this->lang->line('please_login'); ?>
</li>
</ul>
</div>
</div>
<?php if ($this->session->flashdata('error')) : ?>
<div class="row">
<div class="col-md-5">
<div class="alert alert-danger">
<?php echo $this->session->flashdata('error'); ?>
</div>
</div>
</div>
<?php endif; ?>
<div class="row">
<div class="col-md-12">
<form class="form-horizontal" action="" method="post">
<div class="form-group<?php echo form_error('form[username]') ? ' has-error' : ''; ?>">
<label class="col-sm-1 control-label"><?php echo $this->lang->line('username'); ?>:</label>
<div class="col-sm-4">
<input name="form[username]" type="text" maxlength="30" class="form-control" value="<?php echo set_value('form[username]'); ?>" autofocus="on"/>
<span class="help-block"><?php echo form_error('form[username]'); ?></span>
</div>
</div>
<div class="form-group<?php echo form_error('form[password]') ? ' has-error' : ''; ?>">
<label class="col-sm-1 control-label"><?php echo $this->lang->line('password'); ?>:</label>
<div class="col-sm-4">
<input name="form[password]" type="password" maxlength="30" class="form-control"/>
<span class="help-block"><?php echo form_error('form[password]'); ?></span>
</div>
</div>
<div class="form-actions col-sm-offset-1">
<button type="submit" class="btn btn-danger col-sm-3"><i class="glyphicon glyphicon-user"></i> <?php echo $this->lang->line('login'); ?></button>
</div>
</form>
</div>
</div>
is it true that php7.1 is not supported by CI 3.0.0 so the error happened by this?

i want to add bootsnipp slider in codeigniter

Here is my main view page :
the first class: item active ,
and another is only class: item
but i want foreach only class="col-sm-6" with two class item active and item ...
<div class="carousel-inner">
<div class="item active">
<div class="row">
<div class="col-sm-6">
<div class="col-item">
<div class="photo">
<img src="img/a.jpg" />
</div>
<div class="info">
<div class="row">
<div class="price col-md-6">
<h5>title</h5>
<h5 class="price-text-color">
Contact for price</h5>
</div>
<div class="rating hidden-sm col-md-6">
<i class="fa fa-bed"></i> <b>3</b>
<i class="fa fa-bath"></i> <b>2</b>
</div>
</div>
<div class="separator clear-left">
<p class="btn-details">
<i class="fa fa-list"></i>More details</p>
</div>
<div class="clearfix">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="item">
<div class="row">
<div class="col-sm-6">
<div class="col-item">
<div class="photo">
<img src="2.jpg" />
</div>
<div class="info">
<div class="row">
<div class="price col-md-6">
<h5>title</h5>
<h5 class="price-text-color">
Contact for price</h5>
</div>
<div class="rating hidden-sm col-md-6">
<i class="fa fa-bed"></i> <b>5</b>
<i class="fa fa-bath"></i> <b>3</b>
</div>
</div>
<div class="separator clear-left">
<p class="btn-details">
<i class="fa fa-list"></i>More details</p>
</div>
<div class="clearfix">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
but when i foreach the div one is active class but i want one div is active but another is not . actually i want to foreach col-sm-6 class.. how to do this. first
I assume that you want the following:
for there to be one active item
for each item to contain several col-sm-6 elements, created via a php foreach loop
create item via a php foreach loop
<!-- language: lang-php -->
<?php $active_item = "active" ?>
<?php foreach($itemlist as $item): ?>
<div class="item <?php echo $active_item ?>">
<?php $active_item = "" ?>
<div class="row">
<?php foreach($item as $column): ?>
<div class="col-sm-6">
<!-- insert your logic here for creating your columns in a carousel -->
</div>
<?php endforeach ?>
</div>
</div>
<?php endforeach ?>
$active will append the active class to only the first instance of your carousel items.
I avoided using foreach($array as $key=>$value) and checking the key for whether the item is to be active, as your array may not have numerical keys that begin with 0.

Resources