Google_Maps_V3_API Geo Location Issue - codeigniter

There is Some issue with code and not getting geo location through this library
$this->load->library('googlemaps');
$config = array();
$config['center'] = 'auto';
$config['onboundschanged'] = 'if (!centreGot) {
var mapCentre = map.getCenter();
marker_0.setOptions({
position: new google.maps.LatLng(mapCentre.lat(), mapCentre.lng())
});
}
centreGot = true;';
$this->googlemaps->initialize($config);
// set up the marker ready for positioning
// once we know the users location
$marker = array();
$this->googlemaps->add_marker($marker);
$data['map'] = $this->googlemaps->create_map();

Related

pagination is not working in codeignitor framework

I am new in Codeigniter. I am creating pagination in codeigniter, but paging number not working.
This is my record where i want pagination
when i click on paging link i got this type error.
Here is my controller code
public function benadharStatus($rowno=0) {
$this->load->library("pagination");
if ($this->session->userdata('session_name')) {
$data = array();
$data = array('title' => 'Beneficiaries Aadhaar Status', 'pageTitle' => 'Beneficiaries Aadhaar Status');
$obj = new Admin_model;
$obj1 = new Reporting_model;
$data['states'] = $obj->getState();
if($_POST){
// Row per page
$rowperpage = 25;
// Row position
if($rowno != 0){
$rowno = ($rowno-1) * $rowperpage;
}
// All records count
$allcount = $obj1->getBenficzReportOLD($_POST);
// Get records
$users_record = $obj1->getBenficzReports($_POST,'1',$rowno,$rowperpage);
// Pagination Configuration
$config['base_url'] = base_url().'benadharStatus';
$config['use_page_numbers'] = TRUE;
$config['total_rows'] = $allcount;
$config['per_page'] = $rowperpage;
$config['uri_segment'] = 5;
// Initialize
$this->pagination->initialize($config);
$data['links'] = $this->pagination->create_links();
$data['benficirz'] = $users_record;
$data['row'] = $rowno;
$data['passed_state']=$this->input->post('ben_state');
$data['passed_district']=$this->input->post('ben_district');
$data['passed_awc']=$this->input->post('ben_awc');
$data['flag']=1;
}else{
$data['flag']=2;
}
$this->load->view('reports/benadharStatus', $data);
} else {
redirect('admin');
}
}
Guys please help... Thanks in advance
Please try this replace this code:
public function benadharStatus($rowno=0) {
$this->load->library("pagination");
if ($this->session->userdata('session_name')) {
$data = array();
$data = array('title' => 'Beneficiaries Aadhaar Status', 'pageTitle' => 'Beneficiaries Aadhaar Status');
$obj = new Admin_model;
$obj1 = new Reporting_model;
$data['states'] = $obj->getState();
if($_POST){
// Row per page
$rowperpage = 25;
// Row position
if($rowno != 0){
$rowno = ($rowno-1) * $rowperpage;
}
// All records count
$allcount = $obj1->getBenficzReportOLD($_POST);
// Get records
$users_record = $obj1->getBenficzReports($_POST,'1',$rowno,$rowperpage);
// Pagination Configuration
$controler_name = $this->router->fetch_class();
$config['base_url'] = base_url().'/'.$controler_name.'/benadharStatus';
$config['use_page_numbers'] = TRUE;
$config['total_rows'] = $allcount;
$config['per_page'] = $rowperpage;
$config['uri_segment'] = 5;
// Initialize
$this->pagination->initialize($config);
$data['links'] = $this->pagination->create_links();
$data['benficirz'] = $users_record;
$data['row'] = $rowno;
$data['passed_state']=$this->input->post('ben_state');
$data['passed_district']=$this->input->post('ben_district');
$data['passed_awc']=$this->input->post('ben_awc');
$data['flag']=1;
}else{
$data['flag']=2;
}
$this->load->view('reports/benadharStatus', $data);
} else {
redirect('admin');
}
}

Image resize in codeigniter

I want to upload multiple images using two file input as well as resize them.
1. original image
2. 100 x 100
3. 400 x 200
All works fine but image lib not resize properly.It uploads images in original size.I have check following things.
1. Image lib load only once. which i load in __construct().
2. before initializing clear the image lib. $this->image_lib->clear();
function do_upload($name,$shop_code) {
$files = $_FILES;
if ($name == 'pre_photo_array') {
$photo_name = 'pre_photo_array';
} else {
$photo_name = 'post_photo_array';
}
$cpt = count($_FILES[$name]['name']);
--$cpt;
for ($i = 0; $i < $cpt; $i++) {
$_FILES[$photo_name]['name'] = $files[$photo_name]['name'][$i];
$_FILES[$photo_name]['type'] = $files[$photo_name]['type'][$i];
$_FILES[$photo_name]['tmp_name'] = $files[$photo_name]['tmp_name'][$i];
$_FILES[$photo_name]['error'] = $files[$photo_name]['error'][$i];
$_FILES[$photo_name]['size'] = $files[$photo_name]['size'][$i];
if ($photo_name == 'pre_photo_array') {
$config['upload_path'] = './assets/images/shop_images/pre_pic/';
} else {
$config['upload_path'] = './assets/images/shop_images/post_pic/';
}
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['overwrite'] = FALSE;
$config['file_name'] = $shop_code.'_'.time();
$this->upload->initialize($config);
if (!$this->upload->do_upload($photo_name)) {
$error = array('error' => $this->upload->display_errors());
$file_path[] = ' ';
} else {
$upload_data = $this->upload->data();
if ($name == 'pre_photo_array') {
$imgdata=exif_read_data('assets/images/shop_images/pre_pic/'.$upload_data['file_name'], 'IFD0');
$source_image_path = getimagesize('assets/images/shop_images/pre_pic/'.$upload_data['file_name']);
$source_image = 'assets/images/shop_images/pre_pic/'.$upload_data['file_name'];
$Pre_Thumbnail_new_image = 'assets/images/shop_images/pre_pic/Thumbnail/'.$upload_data['file_name'];
$Pre_ppt_new_image = 'assets/images/shop_images/pre_pic/PPT/'.$upload_data['file_name'];
} else {
$imgdata=exif_read_data('assets/images/shop_images/post_pic/'.$upload_data['file_name'], 'IFD0');
$source_image_path = getimagesize('assets/images/shop_images/post_pic/'.$upload_data['file_name']);
$source_image = 'assets/images/shop_images/post_pic/'.$upload_data['file_name'];
$Post_Thumbnail_new_image = 'assets/images/shop_images/post_pic/Thumbnail/'.$upload_data['file_name'];
$Post_ppt_new_image = 'assets/images/shop_images/post_pic/PPT/'.$upload_data['file_name'];
}
$rotation_angle = 0;
switch(isset($imgdata['Orientation'])) {
case 3:
$rotation_angle='180';
break;
case 6:
$rotation_angle='90';
break;
case 8:
$rotation_angle='90';
break;
}
if($name == 'pre_photo_array') {
$Thumbnail_new_image = $Pre_Thumbnail_new_image;
$ppt_new_image = $Pre_ppt_new_image;
} else {
$Thumbnail_new_image = $Post_Thumbnail_new_image;
$ppt_new_image = $Post_ppt_new_image;
}
// Create Thumbnail
$Thumbnail['image_library'] = 'gd2';
$Thumbnail['source_image'] = $source_image;
$Thumbnail['new_image'] = $Thumbnail_new_image;
$Thumbnail['create_thumb'] = TRUE;
$Thumbnail['thumb_marker'] = FALSE;
$Thumbnail['maintain_ratio'] = TRUE;
$Thumbnail['width'] = 100;
$Thumbnail['height'] = 100;
$Thumbnail['rotation_angle'] = $rotation_angle;
$this->image_lib->clear();
$this->image_lib->initialize($Thumbnail);
// resize image
$this->image_lib->resize();
$this->image_lib->rotate();
// handle if there is any problem
if(!$this->image_lib->resize()) {
echo "if";
echo $this->image_lib->display_errors();exit;
}
if($source_image_path[0] > $source_image_path[1]){
$width = 400;
$height = 200;
}else{
$width = 200;
$height = 400;
}
// Create PPt image
$ppt['image_library'] = 'gd2';
$ppt['source_image'] = $source_image;
$ppt['new_image'] = $ppt_new_image;
$ppt['create_thumb'] = FALSE;
$ppt['thumb_marker'] = FALSE;
$ppt['maintain_ratio'] = TRUE;
$ppt['width'] = 400;
$ppt['height'] = 200;
$ppt['rotation_angle']=$rotation_angle;
$this->image_lib->clear();
$this->image_lib->initialize($ppt);
// resize image
$this->image_lib->resize();
$this->image_lib->rotate();
// handle if there is any problem
if(!$this->image_lib->resize()) {
echo $this->image_lib->display_errors();exit;
}
if($photo_name == 'pre_photo_array') {
$path = 'assets/images/shop_images/pre_pic/';
} else {
$path = 'assets/images/shop_images/post_pic/';
}
$file_path[] = $path.$upload_data['file_name'];
}
}
return $file_path;
}
}
I am adding my Upload Image and Create Multiple Thumbnail Sizes in CodeIgniter Example. Hope it helps you.
//initialize the path where you want to save your images
function __construct(){
parent::__construct();
//return the full path of the directory
//make sure these directories have read and write permessions
$this->original_path = realpath(APPPATH.'../uploads/original');
$this->resized_path = realpath(APPPATH.'../uploads/resized');
$this->thumbs_path = realpath(APPPATH.'../uploads/thumbs');
}
function do_upload(){
$this->load->library('image_lib');
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png', //only accept these file types
'max_size' => 2048, //2MB max
'upload_path' => $this->original_path //upload directory
);
$this->load->library('upload', $config);
$image_data = $this->upload->data(); //upload the image
//your desired config for the resize() function
$config = array(
'source_image' => $image_data['full_path'], //path to the uploaded image
'new_image' => $this->resized_path, //path to
'maintain_ratio' => true,
'width' => 128,
'height' => 128
);
//this is the magic line that enables you generate multiple thumbnails
//you have to call the initialize() function each time you call the resize()
//otherwise it will not work and only generate one thumbnail
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
$config = array(
'source_image' => $image_data['full_path'],
'new_image' => $this->thumbs_path,
'maintain_ratio' => true,
'width' => 36,
'height' => 36
);
//here is the second thumbnail, notice the call for the initialize() function again
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
}

codeiginter upload and resize

I have a problem with CI class image, image does not resize...
for example :
controller
private function _do_upload(){
$config['upload_path'] = 'upload/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1000; //set max size allowed in Kilobyte
$config['max_width'] = 1000; // set max width image allowed
$config['max_height'] = 1000; // set max height allowed
$config['file_name'] = round(microtime(true) * 1000);
$this->load->library('upload', $config);
if($this->upload->do_upload('photo')) //upload and validate{
$config2['image_library'] = 'gd2';
$config2['source_image'] = $this->upload->upload_path;
$config2['create_thumb'] = TRUE;
$config2['maintain_ratio'] = TRUE;
$config2['width'] = 450;
$config2['height'] = 500;
$this->load->library('image_lib', $config2);
if(!$this->image_lib->resize()){
$data['inputerror'][] = 'photo';
$data['error_string'][] = 'Upload error: '.$this->upload->display_errors('','');
$data['status'] = FALSE;
}
return $this->upload->data('file_name');
}else{
$data['inputerror'][] = 'photo';
$data['error_string'][] = 'Upload error: '.$this->upload->display_errors('',''); //show ajax error
$data['status'] = FALSE;
echo json_encode($data);
exit();
}
}
But i got no error, I dont know where is the mistake?
Well you have a few issues...
1. You have commented out your opening { which would break your code.
if($this->upload->do_upload('photo')) //upload and validate {
Should be
if($this->upload->do_upload('photo')) { //upload and validate
2. The next part: If you do have a resize error you are not doing anything with your messages... So...
if(!$this->image_lib->resize()){
$data['inputerror'][] = 'photo';
$data['error_string'][] = 'Upload error: '.$this->upload->display_errors('','');
$data['status'] = FALSE;
}
Needs the added json_encode like..
if(!$this->image_lib->resize()){
$data['inputerror'][] = 'photo';
$data['error_string'][] = 'Upload error: '.$this->upload->display_errors('','');
$data['status'] = FALSE;
echo json_encode($data);
exit();
}
In reference to your resizing, you do need to supply the images full filename and not just the path where "files" live...
Your source_image is a Path to where the files are uploaded to. Not the Path/Filename of the image you want to resize...
$config2['source_image'] = $this->upload->upload_path;
So if you add this line that gives you the full path and filename and use it...
$file_data = $this->upload->data();
$config2['source_image'] = $file_data['full_path'];
Does that work better?

readreplica implementation with codigniter

I'm developing PHP application with codigniter framework. And using amazon read replica setup. I need a way to handle all select query through read only DB and all update related query through master DB. Following is the current usage I use in my script.
database config file
$db['default']['hostname'] = 'master_db_host';
$db['default']['username'] = 'dbuser';
$db['default']['password'] = 'dbpassword';
$db['default']['database'] = 'db_name';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
model script
class replica_model extends CI_Model {
function __construct()
{
parent::__construct();
}
public function write($data)
{
$this->db->insert('dumy', $data);
return $this->db->insert_id();
}
public function read()
{
$query = $this->db->get("dumy");
return $query->result();
}
}
Can any one help me to alter the script to access master and replica based on read and write?
We can handle multiple DB with codeigniter. So first we can see how the config file need to be set.
$active_group = 'default';
$active_record = TRUE;
//Master DB config values
$db['default']['hostname'] = 'master_db_host';
$db['default']['username'] = 'db_user';
$db['default']['password'] = 'db_pass';
$db['default']['database'] = 'db_name';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
//Replica DB config values
$db['read_replica']['hostname'] = 'replica_db_host';
$db['read_replica']['username'] = 'db_user';
$db['read_replica']['password'] = 'db_password';
$db['read_replica']['database'] = 'db_name';
$db['read_replica']['dbdriver'] = 'mysql';
$db['read_replica']['dbprefix'] = '';
$db['read_replica']['pconnect'] = FALSE;
$db['read_replica']['db_debug'] = TRUE;
$db['read_replica']['cache_on'] = FALSE;
$db['read_replica']['cachedir'] = '';
$db['read_replica']['char_set'] = 'utf8';
$db['read_replica']['dbcollat'] = 'utf8_general_ci';
$db['read_replica']['swap_pre'] = '';
$db['read_replica']['autoinit'] = TRUE;
$db['read_replica']['stricton'] = FALSE;
Parameter "$db['read_replica']['pconnect']" should be true on master db config and it should be false on replica config. Other wise when we enable replica db master db config also overwritten by replica config.
Then model usage will be like follows.
class Replica_model extends CI_Model {
function __construct()
{
parent::__construct();
$this->db_replica = $this->load->database('read_replica',TRUE);
}
public function write($data)
{
$this->db->insert('dumy', $data);
return $this->db->insert_id();
}
public function read()
{
$query = $this->db_replica->get("dumy");
return $query->result();
}
}
CI allows you to connect to multiple databases via groups.
This is directly from their site:
https://ellislab.com/codeigniter/user-guide/database/connecting.html
$DB1 = $this->load->database('read', TRUE);
$DB2 = $this->load->database('write', TRUE);
hen you connect this way, you will use your object name to issue commands rather than the syntax used throughout this guide. In other words, rather than issuing commands with:
$this->db->query();
$this->db->result();
etc...
You will instead use:
$DB1->query();
$DB1->result();
etc...
In you will have a multi-dimensional array for your db
$db['read']['hostname'] = ...
$db['write']['hostname'] = ...
So when you read, you would use $DB1, when you write, you'd use $DB2 ...
I haven't used this exact setup. But that's the gist of it.

Why my Codeigniter unable to connect multiple database?

I am junior of codeigniter, what I want to do is connect multiple database to retrieve the database data, but it is not working for me, keep return me 404 error page
here is my code
config/database.php
$active_group = 'qm';
$active_record = TRUE;
$db['qm']['hostname'] = '192.168.0.128';
$db['qm']['username'] = 'callcenter';
$db['qm']['password'] = 'ca11c3nt3r';
$db['qm']['database'] = 'qm';
$db['qm']['dbdriver'] = 'mysql';
$db['qm']['dbprefix'] = '';
$db['qm']['pconnect'] = TRUE;
$db['qm']['db_debug'] = TRUE;
$db['qm']['cache_on'] = FALSE;
$db['qm']['cachedir'] = '';
$db['qm']['char_set'] = 'utf8';
$db['qm']['dbcollat'] = 'utf8_general_ci';
$db['qm']['swap_pre'] = '';
$db['qm']['autoinit'] = TRUE;
$db['qm']['stricton'] = FALSE;
/* call contact detail table */
$active_group = "reportcallcenter";
$active_record = TRUE;
$db['reportcallcenter']['hostname'] = '192.168.0.128';
$db['reportcallcenter']['username'] = 'callcenter';
$db['reportcallcenter']['password'] = 'ca11c3nt3r';
$db['reportcallcenter']['database'] = 'reportcallcenter';
$db['reportcallcenter']['dbdriver'] = 'mysql';
$db['reportcallcenter']['dbprefix'] = "";
$db['reportcallcenter']['pconnect'] = TRUE;
$db['reportcallcenter']['db_debug'] = TRUE;
$db['reportcallcenter']['cache_on'] = FALSE;
$db['reportcallcenter']['cachedir'] = "";
$db['reportcallcenter']['char_set'] = "utf8";
$db['reportcallcenter']['dbcollat'] = "utf8_general_ci";
$db['reportcallcenter']['swap_pre'] = '';
$db['reportcallcenter']['autoinit'] = TRUE;
$db['reportcallcenter']['stricton'] = FALSE;
Controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Qm extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->permission->is_logged_in();
//load model
$this->load->helper('url');
$this->load->model('callcontactsdetails_model');
$this->load->database('qm', TRUE);
$this->load->database('reportcallcenter', TRUE);
}
function qm_form()
{
$data = array();
$data['page'] = 'qm_form';
if($query = $this->callcontactsdetails_model->get_all())
{
$data['recordings_record'] = $query;
}
$data['main'] = 'qm/qm_form';
$data['js_function'] = array('qm');
$this->load->view('template/template',$data);
}
}//end of class
?>
Model (I using My_model)
<?php
class Callcontactsdetails_model extends MY_Model {
protected $_table = 'callcontactsdetails';
protected $primary_key = 'id';
}
?>
My Screen Return Result
Any Idea how to solve my problem or any mistake I did ?
Load your database like this
$this->db_report = $this->CI->load->database('reportcallcenter', TRUE);
assumed that 'qm' db will be set as default
or you can try like this
$DB1 = $this->load->database('qm', TRUE);
$DB2 = $this->load->database('reportcallcenter', TRUE);
then you can use like
$DB1->query();
$DB1->result();
and
$DB2->query();
$DB2->result();
in your case try like
if($query = $DB2->get_all())
{
$data['recordings_record'] = $query;
}

Resources