CodeIgniter : dependent dropdown not working - php

my controller :-
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cnewincident extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->database();
}
public function index()
{
$this->load->model('users/supervisor/Mnewincident');
$data['category'] = $this->Mnewincident->getCatgories();
//loads up the view with the query results
$this->load->view('users/supervisor/vnewincident',$data);
if($this->input->post('addrequest'))
{
$this->load->model('users/supervisor/Mnewincident');
// to get the username from table who is creating this request
$session_data = $this->session->userdata('emailid');
$firstname = $this->Mnewincident->get_firstname($session_data);
// passing that usename in newincident table
if($this->Mnewincident->add_request($firstname))
{
$this->session->set_flashdata( 'message', 'Request added successfully.' );
redirect('users/supervisor/Cnewincident');
}
else
{
$this->session->set_flashdata( 'message', 'Failed to add the request. Try again' );
redirect('users/supervisor/Cnewincident');
}
}
}
//call to fill the second dropdown with the subcategories
public function loadsubcat()
{
echo $category_id = $this->input->post('id',TRUE);
$subcatData['subcatDrop']=$this->Mnewincident->getSubcatgories($category_id);
$output = null;
foreach ($subcatData['subcatDrop'] as $row)
{
$output .= "<option value='".$row->subcategory_description."'>".$row->subcategory_description."</option>";
}
echo $output;
}
}
?>
My model :-
class Mnewincident extends CI_Model
{
public function __construct()
{
$this->load->database();
}
public function getCatgories()
{
$this->db->select('category_id,category_description');
$this->db->from('tbl_categorymaster');
$query = $this->db->get();
foreach($query->result_array() as $row)
{
$data[$row['category_id']]=$row['category_description'];
}
return $data;
}
public function getSubcatgories($category_id=string)
{
$this->db->select('srno,subcategory_description');
$this->db->from('tbl_subcategorymaster');
$this->db->where('category_id',$category_id);
$query = $this->db->get();
return $query->result();
}
}
My view code :-
$(document).ready(function() {
$("#category").change(function(){
$.ajax({
url:"<?php echo base_url()."users/supervisor/Cnewincident/loadsubcat"?>",
data: {id:$(this).val()},
type: "POST",
success:function(data){
$("#subcategory").html(data);
}
});
});
});

1.Remove the echo from loadsubcat()
public function loadsubcat()
{
**echo** $category_id = $this->input->post('id',TRUE);
..........
.................
}
Hope it works.....

Related

How to pass an array to the model from the controller in codeIgniter

I am trying to pass an array to the model from the controller in codeIgnitor I know this question have some answers but I tried all of them and no solution works with me. So this my code:
Controller:
<?php
if(! defined('BASEPATH')) exit('No direct script access allowed');
class SearchController extends CI_Controller{
var $controller = "user";
public function index(){
$this->home();
}
public function home(){
$this->load->view("search_view");
}
public function search(){
if(isset($_POST['submit'])){
$data['type']=$this->input->post('type');
$data['value']=$this->input->post('value');
$this->load->model("SearchModel");
$this->load->SearchModel->getCadre($data);
}
}
}
?>
Model:
<?php
class SearchModel extends CI_Model{
function construct(){
parent::__construct();
$this->getCadre();
}
function getCadre(){
$query = $this->db->get('cadres');
$query = $this->db->where($type,$value);//the argument witch i want to take from array
if($query->num_rows()>0){
$values = result();
return $query->result();
}
else{
return NULL;
}
}
}
?>
Try below code in your model::
class SearchModel extends CI_Model{
function construct(){
parent::__construct();
}
function getCadre($data = array()){
$this->db->where($data);//the argument witch i want to take from array
$query = $this->db->get('cadres');
if($query->num_rows()>0){
// $values = result();
return $query->result();
}
else{
return NULL;
}
}
}
OR you can pass individual data as below and return result...Also try as below
Controller:
if(! defined('BASEPATH')) exit('No direct script access allowed');
class SearchController extends CI_Controller{
var $controller = "user";
public function index(){
$this->home();
}
public function home(){
$this->load->view("search_view");
}
public function search(){
if(isset($_POST['submit'])){
$type=$this->input->post('type');
$value=$this->input->post('value');
$this->load->model("searchmodel");
$data = $this->searchmodel->getCadre($type,$value);
if($data==NULL){
echo 'No records found!!';
}
else
{
//send data to view
$this->load->view('view_name',$data);
}
}
}
}
Model
class SearchModel extends CI_Model{
function construct(){
parent::__construct();
$this->load->database();
}
function getCadre($type,$value){
$this->db->where('type',$type);//the argument witch i want to take from array
$this->db->where('value',$value);
$query = $this->db->get('cadres');
if($query->num_rows()>0){
// $values = result();
return $query->result();
}
else{
return NULL;
}
}
}
?>

Undefined variable & Invalid argument supplied for foreach() in CodeIgniter

I have the following code that query the database and display it in view.
However, I am getting these error:
- Message: Undefined variable: portfolio Filename: portfolio/home.php
- Message: Invalid argument supplied for foreach() Filename: portfolio/home.php
How should I resolve the error?
Controller (Portfolio.php)
<?php
class Portfolio extends CI_Controller {
public function view($portfolio = 'home')
{
if ( ! file_exists(APPPATH.'/views/portfolio/'.$portfolio.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($portfolio); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('portfolio/'.$portfolio, $data);
$this->load->view('templates/footer', $data);
}
public function __construct()
{
parent::__construct();
$this->load->model('portfolio_model');
$this->load->helper('url_helper');
}
public function index()
{
$data['portfolio'] = $this->portfolio_model->get_portfolio();
$this->load->view('templates/header', $data);
$this->load->view('portfolio/home', $data);
$this->load->view('templates/footer');
}
}
?>
Model (Portfolio_model)
<?php
class Portfolio_model extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function get_portfolio()
{
$query = $this->db->select('title')->from('webinfo')->get();
return $query->result_array();
}
}
?>
View (home.php)
<?php foreach ($portfolio as $portfolio_item): ?>
<h3><?php echo $portfolio_item['title']; ?></h3>
<?php endforeach; ?>
routes.php
$route['portfolio/(:any)'] = 'portfolio/view/$1';
$route['portfolio'] = 'portfolio';
$route['default_controller'] = 'portfolio/view';
$route['(:any)'] = 'portfolio/view/$1';
Couple of things may work
Model
public function get_portfolio() {
$query = $this->db->get('webinfo');
if ($query->num_rows() > 0 ) {
return $query->result_array();
} else {
return FALSE;
}
}
On controller
<?php
class Portfolio extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('portfolio_model');
$this->load->helper('url');
}
public function index() {
$data['portfolio'] = array();
$results = $this->portfolio_model->get_portfolio();
// You may need to remove !
if (!isset($results) {
foreach ($results as $result) {
$data['portfolio'][] = array(
'title' => $result['title']
);
}
}
$this->load->view('templates/header', $data);
$this->load->view('portfolio/home', $data);
$this->load->view('templates/footer');
}
public function view($portfolio = 'home') {
if (!file_exists(APPPATH.'/views/portfolio/'.$portfolio.'.php')) {
show_404();
}
$data['title'] = ucfirst($portfolio); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('portfolio/'.$portfolio, $data);
$this->load->view('templates/footer', $data);
}
}
View
<?php if ($portfolio) {?>
<?php foreach ($portfolio as $portfolio_item) { ?>
<h3><?php echo $portfolio_item['title']; ?></h3>
<?php } ?>
<?php } else { ?>
<h3>No Result</h3>
<?php } ?>
I also would recommend auto loading the database
$autoload['libraries'] = array('database');
Instead of using $this->load->database();

(ASK) Failed on adding and updating data to database mysqli using codeIgniter

So I tried to make a simple crud application. It works well when I try to delete,otherwise it always goes wrong when it comes to adding and updating data. My script didnt succeed on adding or updating data to the database. I'm using code igniter php frameworks here
Here are my script of controller and models for your references
<?php
//script of controller
class Siswa extends CI_Controller
{
private $limit=10;
function __construct()
{
parent::__construct();
$this->load->library(array('table','form_validation'));
$this->load->helper(array('form','url'));
$this->load->model('siswa_model','',TRUE);
}
function index($offset=0,$order_column='id',$order_type='asc')
{
if(empty($offset))
$offset=0;
if(empty($order_column))
$order_column='id';
if(empty($order_type))
$order_type='asc';
$siswas=$this->siswa_model->get_paged_list($this->limit,$offset,$order_column,$order_type)->result();
$this->load->library('pagination');
$config['base_url'] = site_url('siswa/index');
$config['total_rows'] = $this->siswa_model->count_all();
$config['per_page']=$this->limit;
$config['url_segment']=3;
$this->pagination->initialize($config);
$data['pagination']=$this->pagination->create_links();
$this->load->library('table');
$this->table->set_empty(" ");
$new_order=($order_type=='asc'?'desc':'asc');
$this->table->set_heading
(
'No',
anchor('siswa/index/'.$offset.'/nama'.$new_order,'Nama'),
anchor('siswa/index/'.$offset.'/alamat'.$new_order,'Alamat'),
anchor('siswa/index'.$offset.'/jenis_kelamin'.$new_order,'Jenis Kelamin'),
anchor('siswa/index'.$offset.'/tanggal_lahir'.$new_order,'Tanggal Lahir (dd-mm-yyyy)'),
'Actions'
);
$i=0+$offset;
foreach ($siswas as $siswa)
{
$this->table->add_row(++$i,
$siswa->nama,
$siswa->alamat,
strtoupper($siswa->jenis_kelamin)=='M'?
'Laki-laki':'Perempuan',
date('d-m-Y',strtotime(
$siswa->tanggal_lahir)),
anchor('siswa/view/'.$siswa->id,
'view',array('class'=>'view')).' '.
anchor('siswa/update/'.$siswa->id,
'update',array('class'=>'update')).' '.
anchor('siswa/delete/'.$siswa->id,
'delete',array('class'=>'delete',
'onclick'=>"return confirm
('Apakah Anda yakin ingin menghapus data siswa?')"))
);
}
$data['table']=$this->table->generate();
if($this->uri->segment(3)=='delete_success')
$data['message']='Data berhasil dihapus';
else if ($this->uri->segment(3)=='add_succsess')
$data['message']='Data berhasil ditambah';
else
$data['message']='';
$this->load->view('siswaList',$data);
}
function add()
{
$data['title']='Tambah siswa baru';
$data['action']= site_url('siswa/add');
$data['link_back'] = anchor('siswa/index/','Back to list of siswas',array('class'=>'back'));
$this->_set_rules();
if($this->form_validation->run() === FALSE)
{
$data['message']='';
$data['title']='Add new siswa';
$data['message'] = '';
$data['siswa']['id']='';
$data['siswa']['nama']='';
$data['siswa']['alamat']='';
$data['siswa']['jenis_kelamin']='';
$data['siswa']['tanggal_lahir']='';
$data['link_back'] = anchor('siswa/index','Lihat Daftar Siswa',array('class'=>'back'));
$this->load->view('siswaEdit',$data);
}
else
{
$siswa = array('nama'=>$this->input->post('nama'),
'alamat'=>$this->input->post('alamat'),
'jenis_kelamin'=>$this->input->post('jenis_kelamin'),
'tanggal_lahir'=>date('Y-m-d',strtotime($this->input->post('tanggal_lahir'))));
$this->validation->id = $id;
$data['siswa']=$this->siswa_model->add($id,$siswa);
redirect('siswa/index/add_success');
}
}
function view($id)
{
$data['title']='siswa Details';
$data['link_back']= anchor('siswa/index/','Lihat daftar siswas',array('class'=>'back'));
$data['siswa']=$this->siswa_model->get_by_id($id)->row();
$this->load->view('siswaView',$data);
}
function update($id)
{
$data['title']='Update siswa';
$this->load->library('form_validation');
$this->_set_rules();
$data['action']=('siswa/update/'.$id);
if($this->form_validation->run()===FALSE)
{
$data['message']='';
$data['siswa']=$this->siswa_model->get_by_id($id)->row_array();
$_POST['jenis_kelamin'] = strtoupper($data['siswa']['jenis_kelamin']);
$data['siswa']['tanggal_lahir']=date('d-m-Y',strtotime($data['siswa']['tanggal_lahir']));
$data['title']='Update siswa';
$data['message']='';
}
else
{
$id=$this->input->post('id');
$siswa=array('nama'=>$this->input->post('nama'),
'alamat'=>$this->input->post('alamat'),
'jenis_kelamin'=>$this->input->post('jenis_kelamin'),
'tanggal_lahir'=> date('Y-m-d',strtotime($this->input->post('tanggal_lahir'))));
$this->siswa_model->update($id,$siswa);
$data['message']='update siswa success';
}
$data['link_back']= anchor('siswa/index/','Lihat daftar siswas',array('class'=>'back'));
$this->load->view('siswaEdit',$data);
}
function delete($id)
{
$this->siswa_model->delete($id);
redirect('siswa/index/delete_success','refresh');
}
function _set_rules()
{
$this->form_validation->set_rules('nama','Nama','required|trim');
$this->form_validation->set_rules('jenis_kelamin','Jenis Kelamin','required');
$this->form_validation->set_rules('alamat','Alamat','required');
$this->form_validation->set_rules('tanggal_lahir','Tanggal Lahir','required|callback_valid_date');
}
function valid_date($str)
{
if(!preg_match('/^[0-9]{2}-[0-9]{2}-[0-9]{4}$/',$str))
{
$this->form_validation->set_message('valid_date','date format is not valid. dd-mm-yyyy');
return false;
}
else
{
return true;
}
}
}
?>
<?php
//script of model
class Siswa_model extends CI_Model
{
private $primary_key='id';
private $table_name='siswa';
function __construct()
{
parent::__construct();
}
function get_paged_list($limit=10,$offset=0,$order_column='',$order_type='asc')
{
if(empty($order_column) || empty ($order_type))
{
$this->db->order_by($this->primary_key,'asc');
}
else
{
$this->db->order_by($order_column,$order_type);
}
return $this->db->get($this->table_name,$limit,$offset);
}
function count_all()
{
return $this->db->count_all($this->table_name);
}
function get_by_id($id)
{
$this->db->where($this->primary_key,$id);
return $this->db->get($this->table_name);
}
function save($person)
{
$this->db->insert($this->table_name,$person);
return $this->db->insert_id();
}
function update($id,$person)
{
$this->db->where($this->primary_key,$id);
$this->db->update($this->table_name,$person);
}
function delete($id)
{
$this->db->where($this->primary_key,$id);
$this->db->delete($this->table_name);
}
}
?>
function add() {
...........
$siswa = array('nama'=>$this->input->post('nama'),
'alamat'=>$this->input->post('alamat'),
'jenis_kelamin'=>$this->input->post('jenis_kelamin'),
'tanggal_lahir'=>date('Y-m-d',strtotime($this->input->post('tanggal_lahir'))));
$this->validation->id = $id;
$data['siswa']=$this->siswa_model->add($id,$siswa);
redirect('siswa/index/add_success');
$id is not declared anywhere.
You call $this->siswa_model->add($id,$siswa) but the function add() does not exists in siswa_model (it's called save())

Codeigniter: passing whole database from model to view

Hi i am not sure why are my codes not working.
This is the Controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Admin extends CI_Controller {
public function __construct(){
parent::__construct();
if (! $this->session->userdata('is_logged_in')){
redirect('main/restricted');
} else {
$privilege = $this->session->userdata('privilege');
if ($privilege == 'member'){
redirect('main/restricted');
}
}
}
public function index() {
$this->load->model("model_books");
$data2 = $this->model_books->select_book();
$data = array(
'title' => 'Admin Page'
);
$this->load->view("header", $data);
$this->load->view("admin", $data2);
$this->load->view("footer");
}
This is the Model:
<?php
class Model_books extends CI_Model {
public function select_book(){
$query = $this->db->get('books');
if ($query){
return $query->result();
} else {
return false;
}
}
}
This is the View:
<?php
echo $data2->content;
?>
I got around 10 books inside the database however the books in the database are not showing up.
Try this
public function index() {
$this->load->model("model_books");
$data = array(
'title' => 'Admin Page',
'books' => $this->model_books->select_book()
);
$this->load->view("header", $data);
$this->load->view("admin", $data);
$this->load->view("footer");
}
In view
<?php
print_r($books);
?>
try the following in constructor function in model
$db = $this->load->database('default', TRUE);

display data from database to dropdown CodeIgniter

I'm having difficulty with display data from the db to dropdown.
This is what I have tried:
Model.php
public function __construct()
{
parent::__construct();
}
function getAllGroups()
{
/*
$query = $this->db->get('location');
foreach ($query->result() as $row)
{
echo $row->description;
}*/
$query = $this->db->query('SELECT description FROM location');
foreach ($query->result() as $row)
{
echo $row->description;
}
//echo 'Total Results: ' . $query->num_rows();
}
Controller.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Delivery_controller extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('delivery_model');
}
public function index()
{
$data['title']= 'Warehouse - Delivery';
$this->load->view('include/header',$data);
$this->load->view('include/navbar',$data);
$this->load->view('delivery_view', $data);
$this->load->view('include/sidebar',$data);
$this->load->view('include/footer',$data);
$data['groups'] = $this->delivery_model->getAllGroups();
}
}
View.php
<select class="form-control">
<?php
$data = $this->delivery_model->getAllGroups();
foreach($description as $each)
{ ?><option value="<?php echo $each['description']; ?>"><?php echo $each['description']; ?></option>';
<?php }
?>
</select>
But the results appear on top of my page. It's not appearing on the dropdown list. What am I doing wrong in here? Help is pretty much appreciated. Thanks.
You should not be calling your model from your view. Instead try calling you model and setting $data['groups'] before you load your views.
Also do not echo the row results in your model unless you want it displayed on your page.
Controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Delivery_controller extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('delivery_model');
}
public function index()
{
$data['title']= 'Warehouse - Delivery';
$data['groups'] = $this->delivery_model->getAllGroups();
$this->load->view('include/header',$data);
$this->load->view('include/navbar',$data);
$this->load->view('delivery_view', $data);
$this->load->view('include/sidebar',$data);
$this->load->view('include/footer',$data);
}
}
Model:
public function __construct()
{
parent::__construct();
}
function getAllGroups()
{
/*
$query = $this->db->get('location');
foreach ($query->result() as $row)
{
echo $row->description;
}*/
$query = $this->db->query('SELECT description FROM location');
return $query->result();
//echo 'Total Results: ' . $query->num_rows();
}
View:
<select class="form-control">
<?php
foreach($groups as $row)
{
echo '<option value="'.$row->description.'">'.$row->description.'</option>';
}
?>
</select>
This is what you should do:
Model:
public function __construct()
{
parent::__construct();
}
function getAllGroups()
{
$query = $this->db->query('SELECT description FROM location');
return $this->db->query($query)->result();
}
Controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Delivery_controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('delivery_model');
}
public function index()
{
$data['title']= 'Warehouse - Delivery';
$data['groups'] = $this->delivery_model->getAllGroups();
//I take here a sample view, you can put more view pages here
$this->load->view('include/header',$data);
}
}
View:
<select class="form-control">
<?php foreach($groups as $each){ ?>
<option value="<?php echo $each->description; ?>"><?php echo $each->description; ?></option>';
<?php } ?>
</select>
Codeigniter already has specialized functions that minimize the amount of html that you have to dump in your code:
Model
public function description_pulldown(){
$this->db->from('location');
$query = $this->db->get();
foreach($query->result() as $row ){
//this sets the key to equal the value so that
//the pulldown array lists the same for each
$array[$row->description] = $row->description;
}
return $array;
}
Controller
public function index(){
$data['description_list'] = $this->delivery_model->description_pulldown();
//load all of your view data
$this->load->view('delivery_view', $data);
}
View
echo form_label("Description");
echo form_dropdown('description', $description_list, set_value('description'), $description_list);
If you need to have the view pull up the previous data in the dropdown list, you can do a foreach loop to obtain the previous value of the dropdown from the database ie... $description = $item->description; and in the view, change the 'set_value('description')' to simply '$description.'
Never call a model from a view. It is doable but the again you lose the point of using an MVC in the first place.
Call the model from your controller. Get the data and pass the data in to your view.
Use like below.
public function index(){
$data['title']= 'Warehouse - Delivery';
$data['groups'] = $this->delivery_model->getAllGroups();
$this->load->view('include/header',$data);
$this->load->view('include/navbar',$data);
$this->load->view('delivery_view', $data);
$this->load->view('include/sidebar',$data);
$this->load->view('include/footer',$data);
}
In your view, simply loop around the $groups variable and echo to your dropdown.
<select class="form-control">
<?php
$i = 0;
while($i < count($groups)){
$val= $groups[$i]['value'];
$des = $groups[$i]['description'];
echo "<option value='$i'>$des</option>";
}
</select>
And your model's function should be,
function getAllGroups(){
$query = $this->db->get('location');
return $query->result_array();
}
Better I think, in your view use:
On your model get all your data in an array with:
public function get_all_description()
{
$query = $this->db->get('description');
return $query->result_array();
}
In controller:
$data['description']=$this->model->get_all_description();
In view:
for($i=0;$i<sizeof($description);$i++)
{
$description2[$description[$i]['description']]=$marque[$i]['description'];
}
echo form_dropdown('description', $description22, set_value('description'));
This is Codeigniter 4 answer.
Controller
public function index()
{
$delModel = new delivery_model();
$groups=$delModel->getAllGroups();
$data = [
'title' => 'Warehouse - Delivery',
'groups' => $groups,
];
return view('include/header',$data);
return view('include/navbar',$data);
return view('delivery_view', $data);
return view('include/sidebar',$data);
return view('include/footer',$data);
}
Model
public function getAllGroups()
{
$db = \Config\Database::connect();
$query = $db->query("SELECT description FROM location;");
return $query->getResultArray();
}
View
<select>
<?php
foreach ($groups as $row) {
echo '<option value="' . $row["description"] . '">' .$row["description"] . '</option>';
}?>
</select>
public function __construct(){
parent::__construct();
$this->load->helper('url');
$this->load->model('trip_model');
}
public function index(){
$data['trips']=$this->trip_model->get_all_trips();
$this->load->view("trip_view",$data);
}
public function trip_add(){
if(!empty($_FILES['trip_image']['name'])){
$config['upload_path'] = 'assests/images/';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['max_size'] = 2048;
$config['file_name'] = $_FILES['trip_image']['name'];
$this->load->library('upload',$config);
$this->upload->initialize($config);
if($this->upload->do_upload('trip_image')){
$uploadData = $this->upload->data();
$trip_image = $uploadData['file_name'];
}
else{
$trip_image = 'Hello..!!';
}
}
else{
$trip_image = 'Byeee..!!';
}
$data = array(
'trip_image' => $trip_image,
'name' => $this->input->post('name'),
'location' => $this->input->post('location'),
'trip_datetime' => $this->input->post('trip_datetime')
);
$insert = $this->trip_model->trip_add($data);
echo json_encode(array("status" => TRUE));
}
function do_upload(){
$url = "assests/images/";
$image = basename($_FILES['trip_image']['name']);
$image = str_replace(' ','|',$image);
$type = explode(".",$image);
$type = $type[count($type)-1];
if (in_array($type,array('jpg','jpeg','png','gif'))){
$tmppath="assests/images/".uniqid(rand()).".".$type;
if(is_uploaded_file($_FILES["trip_image"]["tmp_name"])){
move_uploaded_file($_FILES['trip_image']['tmp_name'],$tmppath);
return $tmppath;
}
}
}
public function ajax_edit($id){
$data = $this->trip_model->get_by_id($id);
echo json_encode($data);
}
public function trip_update(){
if(!empty($_FILES['trip_image']['name'])){
$config['upload_path'] = 'assests/images/';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['file_name'] = $_FILES['trip_image']['name'];
$this->load->library('upload',$config);
$this->upload->initialize($config);
if($this->upload->upload_img('trip_image')){
$uploadData = $this->upload->data();
$trip_image = $uploadData['file_name'];
}
else{
$trip_image = 'Hello..!!';
}
}
else{
$trip_image = 'Byeee..!!';
}
$data = array(
'trip_image' => $trip_image,
'name' => $this->input->post('name'),
'location' => $this->input->post('location'),
'trip_datetime' => $this->input->post('trip_datetime')
);
$this->trip_model->trip_update(array('trip_id' => $this->input->post('trip_id')), $data);
echo json_encode(array("status" => TRUE));
}
public function trip_delete($id){
$this->trip_model->delete_by_id($id);
echo json_encode(array("status" => TRUE));
}
}

Categories