How do I retrieve (and process) the params I have being passed in from this...
Modules::load('MembersList', $this->input->get(NULL, TRUE);
... into the module its being passed into?
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class MemberList extends MX_Controller {
function __construct()
{
parent::__construct();
$this->load->model('memberslist_model');
}
public function index()
{
// $params = how_do_i_retrieve it?
if ( ! isset($list) || $list == 'individuals')
{
$data['module'] = 'Individuals';
$data['results'] = $this->memberslist_model->list_individuals();
$data['count'] = count($data['results']);
$data['view'] = $this->load->view('list_individuals', $data, TRUE);
}
if ( $list == 'families')
{
$data['module'] = 'Families';
}
return $this->load->view('memberslist', $data, TRUE);
}
public function settings()
{
$data['settings'] = $this->memberslist_model->settings();
return $this->load->view('settings', $data, TRUE);
}
}
I understand that it is being passed as URI segments like codeigniter but I've tried everything and I can't get it to work.
I'm not sure which version you use, but you can try this:
$whatEver = Modules::run('MembersList/index', $this->input->get(NULL, TRUE));
class MemberList extends MX_Controller {
function __construct()
{
parent::__construct();
$this->load->model('memberslist_model');
}
public function index($params)
{
print_r($params);
// $params = how_do_i_retrieve it?
if ( ! isset($list) || $list == 'individuals')
{
$data['module'] = 'Individuals';
$data['results'] = $this->memberslist_model->list_individuals();
$data['count'] = count($data['results']);
$data['view'] = $this->load->view('list_individuals', $data, TRUE);
}
if ( $list == 'families')
{
$data['module'] = 'Families';
}
return $this->load->view('memberslist', $data, TRUE);
}
public function settings()
{
$data['settings'] = $this->memberslist_model->settings();
return $this->load->view('settings', $data, TRUE);
}
}
Related
I am starting my game with CodeIgniter and I have a problem - I would like to download the ID - of the product from the database so that it will be passed to the URL address:
Example address:
http://localhost/crm-SEO/api/admin/domains/{{ID in database}}/notes
When I have other methods like:
domains/GET/6
domains/update/6
Everything works fine for me, but I can not grasp it that I have domains/{{ID}}/
My code i models:
public function get( $id = false)
{
if ( $id == false ) {
$q = $this->db->get('domains');
$q = $q->result();
}
else{
$this->db->where('id', $id);
$q = $this->db->get('domains');
$q = $q->row();
}
return $q;
}
public function update($domain)
{
$this->db->where('id', $domain['id'] );
$this->db->update('domains', $domain);
}
public function create($domain)
{
$this->db->insert('domains', $domain);
}
public function delete($domain)
{
$this->db->where('id', $domain['id'] );
$this->db->delete('domains');
}
My code in controller:
public function __construct()
{
parent::__construct();
$post = file_get_contents('php://input');
$_POST = json_decode($post,true);
$this->load->model('admin/domains_model');
}
public function get($id = false)
{
$result = $this->domains_model->get($id);
echo '{"records":' . json_encode( $result ) . '}';
}
public function update()
{
$domain = $this->input->post('domain');
$this->domains_model->update($domain);
}
public function create()
{
$domain = $this->input->post('domain');
$this->domains_model->create($domain);
}
public function delete()
{
$domain = $this->input->post('domain');
$this->domains_model->delete($domain);
}
I am new to code-igniter, and I am facing unknown issues in updation and deletion of rows in my database. My code for Controller is :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Nhome extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->Model('N_model');
$data['r'] = $this->N_model->getdata();
$this->load->view('Homeview',$data);
}
public function edit()
{
$id = $this->input->get('id');
$this->load->Model('N_model');
$data['s'] = $this->N_model->editdata();
$this->load->view('Neditview',$data);
}
public function loadEdit()
{
$id = $this->input->get('id');
$this->load->view('Neditview');
}
public function insertdata()
{
$eID = isset($_POST['Id'])?$_POST['Id']:'';
$arr['Name'] = $_POST['Name'];
$arr['Gender'] = $_POST['Gender'];
$arr['Email'] = $_POST['Email'];
$this->load->Model('N_model');
$res = $this->N_model->updatedata($arr , $eID);
if($res){
header('location:'.base_url()."index.php/Nhome/".$this->index());
}
}
public function delete(){
$this->load->Model('N_model');
$id = $this->input->get('Id');
$this->N_model->deletedata($id);
$this->index();
}
}
and my code for model is :
<?php
class N_Model extends CI_Model{
public $Id;
public $Name;
public $Gender;
public $Email;
public function __construct()
{
parent::__construct();
}
public function getdata()
{
$va = $this->db->get('newprac');
$res = $va->result();
return $res;
}
public function editdata($id)
{
$vr = $this->db->where('Id',$id);
return $vr;
}
public function updatedata($data , $id){
$this->db->where('newprac.Id',$id);
$res = $this->db->update('newprac', $data);
return $res;
}
public function deletedata($id)
{
$this->db->where('newprac.id',$id);
$this->db->delete('newprac');
if($this->db->affected_rows()>0)
{
return true;
}
else { return false; }
}
}
Change
$this->db->where('newprac.id',$id)
to
$this->db->where('id',$id);
Simplify your code to:
$this->db->where('id',$id)->update('newprac', $data);
Replace your controller by this code. Becuase I think you passing data as a post method so you should use post when you retrieve data.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Nhome extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->Model('N_model');
$data['r'] = $this->N_model->getdata();
$this->load->view('Homeview',$data);
}
public function edit()
{
$id = $this->input->post('id');
$this->load->Model('N_model');
$data['s'] = $this->N_model->editdata();
$this->load->view('Neditview',$data);
}
public function loadEdit()
{
$id = $this->input->post('id');
$this->load->view('Neditview');
}
public function insertdata()
{
$eID = isset($_POST['Id'])?$_POST['Id']:'';
$arr['Name'] = $_POST['Name'];
$arr['Gender'] = $_POST['Gender'];
$arr['Email'] = $_POST['Email'];
$this->load->Model('N_model');
$res = $this->N_model->updatedata($arr , $eID);
if($res){
header('location:'.base_url()."index.php/Nhome/".$this->index());
}
}
public function delete(){
$this->load->Model('N_model');
$id = $this->input->post('Id');
$this->N_model->deletedata($id);
$this->index();
}
}
Did you try to debug using Chrome debugger. You might get the exact error in debugger. I suggest you to try once let me know the error name.
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class checklist extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
$this->load->model('checklist_model');
}
public function index()
{
$data['check_list'] = $this->checklist_model->get_all_details();
$this->load->view('show_checklist', $data);
}
public function form_dropdown()
{
$this->load->view('insert_checklist');
}
public function data_submitted()
{
$data = array('dropdown_single' => $this->input->post('Technology'));
$this->load->model('checklist_model');
$this->checklist_model->insert_in_db($data);
$this->load->model("checklist_model");
$result = $this->checklist_model->read_from_db($data);
$data['result'] = $result[0];
$this->load->view('insert_checklist', $data);
}
public function add_form()
{
$this->load->view('insert_checklist');
}
public function edit()
{
$id = $this->uri->segment(3);
$data['details'] = $this->checklist_model->getById($id);
$this->load->view('edit', $data);
}
public function delete($id)
{
$this->checklist_model->delete_a_detail($id);
$this->index();
}
public function insert_new_details()
{
$udata['technology_name'] = $this->input->post('technology_name');
$udata['questions'] = $this->input->post('questions');
$udata['status'] = $this->input->post('status');
$udata['comments'] = $this->input->post('comments');
$res = $this->checklist_model->insert_details_to_db($udata);
if($res)
{
header('location:'.base_url()."/index.php/checklist/".$this->index());
}
}
public function update()
{
$mdata['technology_name']=$_POST['technology_name'];
$mdata['questions']=$_POST['questions'];
$mdata['status']=$_POST['status'];
$mdata['comments']=$_POST['comments'];
$res=$this->checklist_model->update_info($mdata, $_POST['id']);
if($res)
{
header('location:'.base_url()."/index.php/checklist/".$this->index());
}
}
}
?>
it means you call for an array variable's index 'question', and that index does not exist in that array. Maybe in function update(), $_POST['question']. Not sure. You should provide the full error msg, like file and line.
Also: the view if that's the case. And make this sound more like a question.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller
{
function __costruct(){
parent::__costruct();
$login = $this->session->userdata('login');
if(!empty($login)){
if($login!='valid'){
} else {
redirect('login/index');
}
} else{
redirect('login/index');
}
}
protected $template = array();
public function layout($arg = array()) {
$this->template['header'] = $this->load->view('theme/header_theme', $arg, true);
$this->template['header_menu'] = $this->load->view('theme/header_menu_theme', $arg, true);
$this->template['sidebar'] = $this->load->view('theme/sidebar_theme',$arg, true);
$this->template['content'] = $this->load->view($this->content, $arg, true);
$this->template['footer'] = $this->load->view('theme/footer_theme',$arg, true);
$this->load->view('theme/index_theme', $this->template);
}
If I am reading it right, and if that is the code used, the mistake is a simple spelling mistake.
function __costruct(){
parent::__costruct();
should have been
function __construct(){
parent::__construct();
Anyways, it is always better to use the server in development mode to check the same!!!
HOw do I pass $variable from comments() to someFunction()?
class Blog extends CI_Controller {
public function index()
{
echo 'Hello World!';
}
public function comments()
{
$variable = "Hello";
}
public function someFunction()
{
echo $variable;
}
}
** EDIT ** Feel free to point out any other mistakes if you wish
class Home extends CI_Controller {
private $idArray;
function __construct()
{
parent::__construct();
$this->load->model('home_model');
$this->load->library('tank_auth');
$this->load->library('form_validation');
}
public function index() {
$home_data['initial_two'] = $this->home_model->get_two_brands();
$home_data['user_id'] = $this->tank_auth->get_user_id();
$home_data['username'] = $this->tank_auth->get_username();
$this->load->view('home_view', $home_data);
}
public function get_two() {
$get_results = $this->home_model->get_two_brands();
if($get_results != false){
$html = '';
foreach($get_results as $result){
$html .= '<li>'.$result->brand.'</li>';
}
list($result1, $result2) = $get_results;
$idOne = $result1->id;
$idTwo = $result2->id;
$this->idArray = array($result1->id, $result2->id);
//var_dump($this->idArray);
$result = array('status' => 'ok', 'content' => $html);
header('Content-type: application/json');
echo json_encode($result);
exit();
}
}//public function get_two() {
function user_pick() {
$this->form_validation->set_rules('pick', 'Pick', 'required|trim|integer|xss_clean');
$this->form_validation->set_rules('notPick', 'Not Pick', 'required|trim|integer|xss_clean');
//$arr = $this->idArray;
var_dump($this->idArray); // This is NULL
$pick = $_POST['pick'];
$notPick = $_POST['notPick'];
$user_id = $this->tank_auth->get_user_id();
if ($this->form_validation->run() == FALSE)
{
$result = array('status' => 'no', 'content' => "No good!");
header('Content-type: application/json');
echo json_encode($result);
exit();
}else{//if ($this->form_validation->run() == FALSE || $do_input == NULL)
$upload = $this->home_model->user_pick($user_id, $pick, $notPick);
$result = array('status' => 'ok', 'content' => "Thank you!");
header('Content-type: application/json');
echo json_encode($result);
exit();
}//if ($this->form_validation->run() == FALSE || $do_input == NULL)
}
}//class Home extends CI_Controller { closing bracket
/* End of file home.php */
/* Location: ./application/controllers/home.php */
class Blog extends CI_Controller {
public function index()
{
echo 'Hello World!';
}
public function comments()
{
$_SESSION['variable'] = Array('k1'=>'v1','k2'=>'v2') ;
// Store the variable in session so it can be called
// in another page or ajax call
}
public function display()
{
echo $_SESSION['variable'] ;
}
}
// my index.php file
var $blog = new Blog() ;
$blog->comments() ;
//another ajax_called.php file, call in ajax on in another browser tab
var $blog = new Blog() ;
$blog->display() ;