I have to connect multiple markers points to show direction in google map. I have used codeigniter. I have referred this link
There is no such example of connecting routes between markers. Kindly help me out.
Controller:
public function geoLocation(){
$this->load->library('googlemaps');
$config['center'] = '37.4419, -122.1419';
$config['zoom'] = 'auto';
$config['directions'] = TRUE;
$config['directionsStart'] = 'Hadapsar, Pune, India';
//$config['directionsDivID'] = 'swargate, Pune, India';
$config['directionsEnd'] = 'Bavdhan, Pune, India';
$this->googlemaps->initialize($config);
$data['map'] = $this->googlemaps->create_map();
$this->load->view('google-map', $data);
}
my updated controller method:
public function index()
{
$this->load->library('googlemaps');
$config['center'] = 'Pune, India';
$config['zoom'] = 'auto';
$config['directionsMode']="WALKING";
$config['directionsWaypointArray'] = array('Hadapsar, Pune, India','Swargate, Pune, India','Bavdhan, Pune, India');
$this->googlemaps->initialize($config);
$marker = array();
$marker['position'] = 'Hadapsar, Pune, India';
//$marker['onmouseover'] = 'ahssdfsdf';
$marker['infowindow_open']= true;
$this->googlemaps->add_marker($marker);
$marker['position'] = 'Bavdhan, Pune, India';
$this->googlemaps->add_marker($marker);
$data['map'] = $this->googlemaps->create_map();
$this->load->view('welcome_message', $data);
}
}
This is my html code:
<?php echo $map['js']; ?>
<div id="nevi">
<div id="menu">
<div id="TabbedPanels1" class="TabbedPanels">
<ul class="TabbedPanelsTabGroup">
<li class="TabbedPanelsTab" tabindex="0" style="font-size:14px" id="today_st">Today's status </li>
<li class="TabbedPanelsTab" id="report" tabindex="0" style="font-size:14px">Reports</li>
</ul>
<div class="TabbedPanelsContentGroup" style="margin-top:74px;">
<div class="TabbedPanelsContent">
<?php echo $map['html']; ?>
</div>
</div>
</div>
</div>
</div>
You need to specify this:
directionsWaypointArray
According to the code:
var $directionsWaypointArray = array(); // An array of waypoints. eg array("Boston, MA", "Times Square, NY");
Waypoints are the bits between your start and end points, so I assume you'd just need to do:
$config['directionsStart'] = 'Hadapsar, Pune, India';
$config['directionsEnd'] = 'Bavdhan, Pune, India';
$config['directionsWaypointArray'] = array("swargate, Pune, India");
Related
Upload image without form action using dropzone in CodeIgniter. I need to upload an image without the form action in dropzone. that means, there are one form, dropzone image and other fields are in the form. First when we selecting an image, automatically upload the image and save in the database. And add other fields then submit the form action.
you can Upload image using AJAX with button but a button must be under the form tag with id
View
<form action="<?php echo SURL; ?>admin/registered_students/" id="file_completion_form" class="form-horizontal" method="post" enctype="multipart/form-data">
<td>
<input type="file" data-validation="" style="display: inline" name="undertaking" id="undertaking" value="" placeholder="" multiple="">
</td>
<td>
<input type="hidden" id="student_id" name="student_id" value="<?=$student_id;?>">
<button type="button" class="btn btn-info chk2" id="upload_undertaking">
<i class="fa fa-upload"></i>
</button>
</td>
<td>
<span class="alert" style="display: none" id="msg">Updated</span>
</td>
<td id="download_undertaking">
<a href="<?php echo SURL.'file/download/'.$files[0]['undertaking'];?>">
<button type="button" class="btn btn-info chk2" id=""><i class="fa fa-download"></i></button>
</a>
</td>
</form>
JS
$('#upload_undertaking').click(function(e)
{
e.preventDefault();
var data = new FormData();
var form_data = $('#file_completion_form').serializeArray();
$.each(form_data, function (key, input)
{
data.append(input.name, input.value);
});
//input quatation
var quotation_wip = $('input[name="undertaking"]')[0].files;
if(quotation_wip.length>0)
{
for (var i = 0; i < quotation_wip.length; i++)
{
data.append("undertaking[]", quotation_wip[i]);
}
}
else
{
return 0;
exit;
}
data.append('key', 'value');
var student_id = $('#student_id').val();
$.ajax(
{
url:URL+'file_completion/'+student_id,
type:'POST',
data:data,
cache:false,
contentType: false,
processData: false,
success:function(data)
{
if(data==2)
{
window.location.href=URL+'index/'+student_id;
}
else
{
var obj = jQuery.parseJSON(data);
// alert( obj.undertaking );
$("#undertaking span").html(obj.undertaking);
$("#download_undertaking").html('<button type="button" class="btn btn-info chk2" id=""><i class="fa fa-upload"></i></button>');
$("#msg").show();
setTimeout(function()
{
$("#msg").hide();
},
10000);
}
}
});
});
Controller
public function file_completion1($student_id='',$document_name='')
{
// if($this->input->post('student_id'))
// {
// echo $this->input->post($student_id);
// echo($student_id).'-';
// echo($document_name);
// exit();
$filename=array();
if(count($_FILES['copy_of_paid_fee_challan']['name']) > 0 && $_FILES['copy_of_paid_fee_challan']['name'] !='')
{
$files = $_FILES['copy_of_paid_fee_challan'];
$count = count($_FILES['copy_of_paid_fee_challan']['name']);
//echo $_FILES['file']['name'];exit();
for($i=0; $i<$count;$i++)
{
$config = array();
$projects_folder_path = './assets/uploads/';
$thumb = $projects_folder_path . 'thumb';
$_FILES['copy_of_paid_fee_challan']['name'] = $files['name'][$i];
$_FILES['copy_of_paid_fee_challan']['type'] = $files['type'][$i];
$_FILES['copy_of_paid_fee_challan']['tmp_name'] = $files['tmp_name'][$i];
$_FILES['copy_of_paid_fee_challan']['error'] = $files['error'][$i];
$_FILES['copy_of_paid_fee_challan']['size'] = $files['size'][$i];
// $file_ext = ltrim(strtolower(strrchr($_FILES['copy_of_paid_fee_challan']['name'],'.')),'.');
// $file_name = 'oppein-'.date('YmdGis').'.'.$file_ext;
$config['upload_path'] = $projects_folder_path;
$config['allowed_types'] = '*';
$config['encrypt_name'] = TRUE;
$config['overwrite'] = TRUE;
$config['file_name'] = $_FILES['copy_of_paid_fee_challan']['name'];
$this->load->library('upload', $config);
$this->upload->initialize($config);
if(!$this->upload->do_upload('copy_of_paid_fee_challan'))
{
$error_file_arr = array('error' => $this->upload->display_errors());
$this->session->set_flashdata('err_message', $error_file_arr['error']);
$r=2;
echo json_encode($r);
exit();
}
else
{
$data['delete_record'] = $this->Common_model->select_single_records('uploads',$where=array('student_id'=>$student_id));
if(file_exists($projects_folder_path.$data['delete_record']['undertaking']))
{
unlink($projects_folder_path.$data['delete_record']['undertaking']);
}
$data_image_upload = array('upload_image_data' => $this->upload->data());
$image_name =$data_image_upload['upload_image_data']['file_name'];
$full_path = $data_image_upload['upload_image_data']['full_path'];
// ------------------------------------------------------------------------
$this->load->library('image_lib');
$config['image_library'] = 'GD2';
$config['source_image'] = './assets/uploads/' . $image_name;
$config['maintain_ratio'] = TRUE;
$config['master_dim'] = 'auto';
$config['quality'] = 70;
$config['width'] = 1024;
$config['height'] = 768;
$config['new_image'] = './assets/uploads/' . $image_name;
$this->image_lib->initialize($config);
$this->image_lib->resize();
// ------------------------------------------------------------------------
}
$filename[] = $image_name;
} // end for loop
}
foreach ($filename as $key => $value)
{
$insert_image=array(
'copy_of_paid_fee_challan'=> $value,
// 'student_id' => $student_id,
// 'stage_id' => $stage_id,
'update_date' => date("Y-m-d g:i:s"),
// 'category_status' => 1,
// 'user_id' =>$this->session->userdata('user_id'),
);
// echo "<pre>";
// print_r ($insert_image);
// echo "</pre>";
// exit();
$add_image = $this->Common_model->update_table('uploads',$where=array('student_id'=>$student_id),$insert_image);
}
if ($add_image)
{
$record = $this->Common_model->select_single_records('uploads',$where=array('student_id'=>$student_id));
echo json_encode($record);
}
// }
// else
// {
// $data['active']='registered_students';
// $this->load->view('admin/header',$data);
// $data['student_id']=$student_id;
// $data['error']='';
// $this->load->view('registration/file_completion',$data);
// $this->load->view('admin/footer',$data);
// }
}
Okay I have a small problem.
When user clicks on a link it goes to website/create/business which is fine however if nothing is done but the link is clicked again, it goes to website/create/business/create/business for whatever reason.
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
Profile
Add Business
<a href="{{ url('/logout') }}" onclick="event.preventDefault(); document.getElementById('logout-form').submit();">
Logout
</a>
<form id="logout-form" <a href="{{ url('home') }}" action="{{ url('/logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</li>
</ul>
</li>
Routes:
Route::get('profile/{user_id}', 'ProfileController#checkid');
Route::post('update', 'ProfileController#updateProfile');
Route::get('create/business', 'BusinessController#addBusiness');
Route::post('create', 'BusinessController#createBusiness');
ProfileController:
public function checkid($user_id) {
if (Auth::check())
{
$user_id = Auth::id();
return view('profile', [
'id' => $user_id
]);
}
}
function updateProfile(Request $request) {
$user = $request->user();
$twitter = $request->input('twitter');
$facebook = $request->input('facebook');
$instagram = $request->input('instagram');
$telephone = $request->input('telephone');
$user->twitter_personal = $twitter;
$user->facebook_personal = $facebook;
$user->instagram_personal = $instagram;
$user->telephone = $telephone;
$result = $user->save();
if($result) {
$message = 'success';
}else{
$message = 'error';
}
return redirect()->back()->withInput()->with('message', $message);
}
BusinessController:
function addBusiness() {
return view('addBusiness');
}
function createBusiness(Request $request) {
$name = $request->input('name');
$type = $request->input('type');
$email = $request->input('email');
$user_id = Auth::id();
$business = new Business();
$business->name = $name;
$business->type = $type;
$business->email = $email;
$business->user_id = $user_id;
$business->save();
$address1 = $request->input('address1');
$address2 = $request->input('address2');
$town = $request->input('town');
$city = $request->input('city');
$postcode = $request->input('postcode');
$telephone = $request->input('telephone');
$address = new Address();
$address->firstline_address = $address1;
$address->secondline_address = $address2;
$address->town = $town;
$address->city = $city;
$address->postcode = $postcode;
$address->telephone = $telephone;
$address->save();
$result = $business->save();
$result2 = $address->save();
$business_id = $business->id;
$address_id = $address->id;
DB::table('business_address')->insert(array('business_id' => $business_id, 'address_id' => $address_id));
DB::table('user_business')->insert(array('user_id' => $user_id, 'business_id' => $business_id));
if($result && $result2) {
$message = 'success';
}else{
$message = 'error';
}
return redirect()->back()->withInput()->with('message', $message);
}
<a href="create/business/"> must be <a href="/create/business/"> to solve this, because your current link is relative, not absolute, so when you click it again, the same reference is added at the end of your current URL.
Anyway, you should generate links in the Laravel way to avoid other issues in the future:
Route::get('create/business', 'BusinessController#addBusiness');
<a href="{{ url('create/business') }}">
or
Route::get('create/business', 'BusinessController#addBusiness')->name('createBusiness');
<a href="{{ route('createBusiness') }}">
Personally I prefer the second one, so if I change the route URL the links will still work, but it requires to add name('yourRoute') on your route definition.
Try to use the route() function. For this example: Add Business. When your route changes it is automatically changed throughout the application.
You can name your routes like this:
Route::get('create/bussiness', [
'as' => 'my_route_name',
'uses' => 'BusinessController#createBusiness'
]);
I have a page with search functionality.
In order to continue the search parameters when pagination is required, I have to pass the search term to the pagination links.
$config['reuse_query_string'] = FALSE;
By default your Query String arguments (nothing to do with other query string options) will be ignored. Setting this config to TRUE will add existing query string arguments back into the URL after the URI segment and before the suffix.:
http://example.com/index.php/test/page/20?query=search%term
This helps you mix together normal URI Segments as well as query string arguments, which until 3.0 was not possible.
But setting this to TRUE does not automatically add the search query after the URI offset segment (after a search is performed).
However, I did manage to use
$config['suffix'] = "?my_search_input=$my_query_value";
to create pagination links that look something like /method/controller/20/?my_search_input=hello
But my question is...
Is this the best way to do it, and why didn't $config['reuse_query_string'] = TRUE; append this back to the URL automatically?
Am I not understanding the documentation correctly?
Thanks.
try this change code with your requirment and your table
set controller this way
<?php
class pagination extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('form');
$this->load->helper('url');
$this->load->database();
$this->load->library('pagination');
$this->load->model('pagination_model');
}
public function index()
{
//pagination settings
$config['base_url'] = site_url('pagination/index');
$config['total_rows'] = $this->db->count_all('tbl_books');
$config['per_page'] = "3";
$config["uri_segment"] = 3;
$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'] = '«';
$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(3)) ? $this->uri->segment(3) : 0;
// get books list
$data['booklist'] = $this->pagination_model->get_books($config["per_page"], $data['page'], NULL);
$data['pagination'] = $this->pagination->create_links();
// load view
$this->load->view('pagination_view',$data);
}
function search()
{
// get search string
$search = ($this->input->post("book_name"))? $this->input->post("book_name") : "NIL";
$search = ($this->uri->segment(3)) ? $this->uri->segment(3) : $search;
// pagination settings
$config = array();
$config['base_url'] = site_url("pagination/search/$search");
$config['total_rows'] = $this->pagination_model->get_books_count($search);
$config['per_page'] = "5";
$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['booklist'] = $this->pagination_model->get_books($config['per_page'], $data['page'], $search);
$data['pagination'] = $this->pagination->create_links();
//Load view
$this->load->view('pagination_view',$data);
}
}
?>
set model this way
<?php
class pagination_model extends CI_Model{
function __construct()
{
parent::__construct();
}
//fetch books
function get_books($limit, $start, $st = NULL)
{
if ($st == "NIL") $st = "";
$sql = "select * from tbl_books where name like '%$st%' limit " . $start . ", " . $limit;
$query = $this->db->query($sql);
return $query->result();
}
function get_books_count($st = NULL)
{
if ($st == "NIL") $st = "";
$sql = "select * from tbl_books where name like '%$st%'";
$query = $this->db->query($sql);
return $query->num_rows();
}
}
?>
view look like this
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CodeIgniter Pagination Example with Search Query Filter</title>
<link rel="stylesheet" href="<?php echo base_url("bootstrap/css/bootstrap.css"); ?>">
<style type="text/css">
.bg-border {
border: 1px solid #ddd;
border-radius: 4px 4px;
padding: 15px 15px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2 well">
<?php
$attr = array("class" => "form-horizontal", "role" => "form", "id" => "form1", "name" => "form1");
echo form_open("pagination/search", $attr);?>
<div class="form-group">
<div class="col-md-6">
<input class="form-control" id="book_name" name="book_name" placeholder="Search for Book Name..." type="text" value="<?php echo set_value('book_name'); ?>" />
</div>
<div class="col-md-6">
<input id="btn_search" name="btn_search" type="submit" class="btn btn-danger" value="Search" />
Show All
</div>
</div>
<?php echo form_close(); ?>
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-2 bg-border">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>#</th>
<th>Book Name</th>
<th>Author Name</th>
<th>ISBN</th>
</tr>
</thead>
<tbody>
<?php for ($i = 0; $i < count($booklist); ++$i) { ?>
<tr>
<td><?php echo ($page+$i+1); ?></td>
<td><?php echo $booklist[$i]->name; ?></td>
<td><?php echo $booklist[$i]->author; ?></td>
<td><?php echo $booklist[$i]->isbn; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<?php echo $pagination; ?>
</div>
</div>
</div>
</body>
</html>
I want to display one fact per page using pagination but it displays all facts in one page.
Here is the controller am using
$config = array();
$config["base_url"] = base_url() . "Admin/news/index";
$config["total_rows"] = $this->news_model->record_count();
$config["per_page"] = 2;
$config["uri_segment"] = 1;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->news_model->fetch_countries($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
And this is model
public function record_count() {
return $this->db->count_all("knowbank");
}
public function fetch_countries($limit, $start) {
$this->db->limit($limit, $start);
$query = $this->db->get("knowbank");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
Finally my view
<?php foreach ($news as $news_item): ?>
<div class="col1"><?php echo $news_item['title'] ?></div>
<img src="<?php echo base_url('image/' .$news_item['picture']);?>" style="max-width:210px; max-height:180px;"><br />
<p><?php echo $news_item['body'] ?></p>
<p>Category: <?php echo $news_item['category']?><br /><br />
Posted on: <?php echo $news_item['date']?>
</p>
View article<br /><br />
<?php endforeach ?>
<?php echo $links; ?>
Change the following and try, your page offset is the last segment of the url, so its 4
$config["per_page"] = 1;
$config["uri_segment"] = 4;
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
I have this problem:
the links form codeigniter pagination class does not show last entry,
e.g. if the total number of rows returned is 2, it will display on one results and the links to the last entry would be greyed out.
Here is the Controller:
function productlisting () {
$ids=$this->uri->segment(3);
$this->load->library('pagination');
$config['base_url'] = base_url().'index.php/listing_category/productlisting/'.$ids;
$config['per_page'] = '1';
$this->load->model('product_model');
$config['total_rows'] =$this->load->model('product_model')->get_num_product();
$this->pagination->initialize($config);
//load the model and get results
$pages = $this->uri->segment(3);//? $this->uri->segment(4) : 0;
$query['products']=$this->load->model('product_model')->get_specific_product($config['per_page'],$pages);
$query['paginated']=$this->pagination->create_links();
// load the view
echo $config['base_url'].'<br/>';
echo 'total rows:'. $config['total_rows'];
$this->template->build('product_display',$query);
}
Here is my model
//query to get the total number of rows
function get_num_product(){
$listingcategory = $this->uri->segment(3);
$this->db->select('default_listings.listing_id_unique,manufacturer,imagename,item_location,thumbnail,default_listings.item_category_id,product_name,item_serial_number,item_description,size,accessories,othercharacteristics,product_age');
$this->db->where('default_listings.item_category_id',$listingcategory);
$this->db->from('default_listings');
$this->db->join('default_listings_pics', 'default_listings.listing_id_unique=default_listings_pics.listing_id_unique', 'left');
$this->db->distinct('listing_id_unique');
$this->db->group_by('default_listings.listing_id_unique');
$queried= $this->db->get();
$rowcount = $queried->num_rows();
return $rowcount;
}
// Query to get the actual entries
function get_specific_product($num, $offset){
$listingcategory = $this->uri->segment(3);
$this->db->select('default_listings.listing_id_unique,manufacturer,imagename,item_location,thumbnail,default_listings.item_category_id,product_name,item_serial_number,item_description,size,accessories,othercharacteristics,product_age');
$this->db->where('default_listings.item_category_id',$listingcategory);
$this->db->from('default_listings');
$this->db->join('default_listings_pics', 'default_listings.listing_id_unique=default_listings_pics.listing_id_unique', 'left');
$this->db->distinct('listing_id_unique');
$this->db->group_by('default_listings.listing_id_unique');
$this->db->limit($num, $offset);
$query= $this->db->get()->result();
return $query;
}
and finally my view
<div id="catetogorylisitngcover">
<h1>Products</h1>
<?php foreach ( $products as $productdetail):?>
<div class="eachproducts">
<div class="productimage">
<?php if($productdetail->thumbnail):?>
<img src="<?php echo base_url();?>pictures/<?php echo $productdetail->thumbnail;?>"/>
<?php else :?>
<img src="<?php echo base_url();?>img/noimage.png"/>
</div>
<div class="productcover">
<div><span >Category Id:</span><span class="producttext"><?php echo $productdetail->item_category_id ;?></span></div>
<div><span >Product Name:</span><span class="producttext"><?php echo $productdetail->product_name;?></pan></div>
<div><span >Manufacturer :</span><span class="producttext"><?php echo $productdetail->manufacturer;?></span></div>
<div><span >Location :</span><span class="producttext"><?php echo $productdetail->item_location;?></span></div>
<div><span >Listing Id :</span><span class="producttext"><?php echo $productdetail->listing_id_unique;?></span></div>
<div class="learmoreproduct"><img src="<?php echo base_url();?>img/prodreadmore.png"/></div>
</div>
</div>
<?php endforeach;?>
<?php echo $this->pagination->create_links(); ?>
</div>
Help needed!
use it as
$this->load->library('pagination');
$config['base_url'] = your base url without offset in your case // base_url().'index.php/listing_category/productlisting/';
$config['total_rows'] = your total number of rows;
$config['per_page'] = number of rows you want to display;
$config['uri_segment'] = uri segment which will be used as offset;
$this->pagination->initialize($config);