Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
161 views
in Technique[技术] by (71.8m points)

php - Codeignitor code gives undefined property error on live server but not on localhost

I am using Codeignitor code, the code works fine and show output on localhost fine but the same code when run on live server gives an error as:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Welcome::$data
Filename: controllers/Welcome.php
Line Number: 49
Backtrace:
File: /application/controllers/Welcome.php
Line: 49
Function: _error_handler 

The code is as follows

  1. application/controllers/Welcome.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller 
{
    public function __construct()
    {
        parent::__construct();
        
        if (!$this->ion_auth->logged_in()  || empty($this->session->name)) 
        {
            redirect('/login');
        }
        $this->load->helper('url');
        $this->load->model('BasicModel', 'basic');
        $this->load->model('LabelModel', 'label');
    }
    public function index()
    {
        //if candidate, go to basic details
        if($this->ion_auth->in_group('candidate'))
        {
            redirect('basic/edit/'.$this->session->basic_id);
        }
        if($_SESSION['org']==1)
        {
            //Get MIS count
            $this->getMISCount();
        }
        else
        {
            //Get Vericraft count without integration
            $this->getCount();
        }
        
        if($this->ion_auth->in_group('admin'))
        {
            //Get Client list
            $this->getClientList();
        }
        else if($this->ion_auth->in_group('dev'))
        {
            $this->getDevData();
        }
        $this->load->view('welcome_message', $this->data);
    }
    public function candidate()
    {
        $this->data['label_data'] = $this->label->view_label();
        $query = $this->db->query("SELECT id, CONCAT(CAST(AES_DECRYPT(fname,'".encrypted_key."') AS CHAR) AS fname,' ',CAST(AES_DECRYPT(mname,'".encrypted_key."') AS CHAR) AS mname, ' ',CAST(AES_DECRYPT(sname,'".encrypted_key."') AS CHAR) AS sname) as name,Refno, gender, CAST(AES_DECRYPT(dob,'".encrypted_key."') AS CHAR) AS dob, CAST(AES_DECRYPT(email,'".encrypted_key."') AS CHAR) AS email, CAST(AES_DECRYPT(contact,'".encrypted_key."') AS CHAR) AS contact, CAST(AES_DECRYPT(empid,'".encrypted_key."') AS CHAR) AS empid, CAST(AES_DECRYPT(location,'".encrypted_key."') AS CHAR) AS location, CAST(AES_DECRYPT(report,'".encrypted_key."') AS CHAR) AS report FROM basic WHERE user_id =".$this->session->user_id);
        $this->data['show_data'] = $query->result_array();
        
        //to get total document label
        $label_query = $this->db->select('id, label')->from('components')->get();
        $this->data['labels'] = array_column($label_query->result_array(), 'label');

        $query =$this->db->select('COUNT(vlink.id) as num_doc, vlink.file_name, vlink.created_at, vlink.updated_at, vlabel.label')
        ->from('document_links as vlink')
        ->join('components as vlabel', 'vlink.comp_id = vlabel.id', 'full outer')
        ->where('vlink.user_id', $this->session->user_id)
        ->group_by('vlink.comp_id')
        ->get();
        $this->data['count_data'] = array_column($query->result_array(), 'num_doc', 'label');
        $this->session->set_flashdata('message', 'Details updated successfully!');
        return redirect($this->agent->referrer());
    }

    public function logout()
    {
        $this->ion_auth->logout();
        redirect('login/index', 'refresh');
    }

    public function getMISCount()
    {
        if($this->ion_auth->in_group('admin'))
        {
            //MIS Total cases
            $this->data['mis_total']=$this->load->database('mis',TRUE)->query("SELECT COUNT(*) as total FROM ichek_database WHERE  ichek_database.Refno NOT LIKE '%test%' AND ichek_database.reasonpending NOT LIKE '%dup%';")->row();

                //MIS Pending Cases
            $this->data['mis_pending']=$this->load->database('mis',TRUE)->query("SELECT COUNT(*) as pending FROM ichek_database WHERE  ichek_database.Refno NOT LIKE '%test%' AND (ichek_database.reasonpending NOT LIKE '%dup%' AND ichek_database.reasonpending NOT LIKE '%stop%') AND (ichek_database.reportdate='' OR ichek_database.reportdate=0 OR ichek_database.reportdate IS NULL);")->row();
                //MIS Green Cases
            $this->data['mis_green']=$this->load->database('mis',TRUE)->query("SELECT COUNT(*) as green FROM ichek_database INNER JOIN ichek_remark ON ichek_database.Refno=ichek_remark.Refno WHERE  ichek_database.Refno NOT LIKE '%test%' AND (ichek_database.reasonpending NOT LIKE '%dup%' AND ichek_database.reasonpending NOT LIKE '%stop%') AND ichek_database.reportdate!='' AND ichek_database.reportdate!=0 AND ichek_database.reportdate IS NOT NULL AND (ichek_remark.negdedupcolor='' OR ichek_remark.negdedupcolor IS NULL OR ichek_remark.negdedupcolor='Green');")->row();

                //MIS Amber Cases
            $this->data['mis_amber']=$this->load->database('mis',TRUE)->query("SELECT COUNT(*) as yellow FROM ichek_database INNER JOIN ichek_remark ON ichek_database.Refno=ichek_remark.Refno WHERE  ichek_database.Refno NOT LIKE '%test%' AND (ichek_database.reasonpending NOT LIKE '%dup%' AND ichek_database.reasonpending NOT LIKE '%stop%') AND (ichek_database.reportdate!='' AND ichek_database.reportdate!=0 AND ichek_database.reportdate IS NOT NULL) AND ichek_remark.negdedupcolor='Amber';")->row();

                //MIS Red Cases
            $this->data['mis_red']=$this->load->database('mis',TRUE)->query("SELECT COUNT(*) as red FROM ichek_database INNER JOIN ichek_remark ON ichek_database.Refno=ichek_remark.Refno WHERE  ichek_database.Refno NOT LIKE '%test%' AND (ichek_database.reasonpending NOT LIKE '%dup%' AND ichek_database.reasonpending NOT LIKE '%stop%') AND (ichek_database.reportdate!='' AND ichek_database.reportdate!=0 AND ichek_database.reportdate IS NOT NULL) AND ichek_remark.negdedupcolor='Red';")->row();

                //MIS Stop Cases
            $this->data['mis_stop']=$this->load->database('mis',TRUE)->query("SELECT COUNT(*) as stop FROM ichek_database INNER JOIN ichek_remark ON ichek_database.Refno=ichek_remark.Refno WHERE  ichek_database.Refno NOT LIKE '%test%' AND ichek_database.reasonpending LIKE '%stop%';")->row();
        }
        else if($this->ion_auth->in_group('client'))
        {
            //MIS Total cases
            $this->data['mis_total']=$this->load->database('mis',TRUE)->query("SELECT COUNT(*) as total FROM ichek_database WHERE  ichek_database.Refno LIKE '%".$_SESSION['client_code']."%' AND ichek_database.reasonpending NOT LIKE '%dup%';")->row();

                //MIS Pending Cases
            $this->data['mis_pending']=$this->load->database('mis',TRUE)->query("SELECT COUNT(*) as pending FROM ichek_database WHERE  ichek_database.Refno LIKE '%".$_SESSION['client_code']."%' AND (ichek_database.reasonpending NOT LIKE '%dup%' AND ichek_database.reasonpending NOT LIKE '%stop%') AND (ichek_database.reportdate='' OR ichek_database.reportdate=0 OR ichek_database.reportdate IS NULL);")->row();

                //MIS Green Cases
            $this->data['mis_green']=$this->load->database('mis',TRUE)->query("SELECT COUNT(*) as green FROM ichek_database INNER JOIN ichek_remark ON ichek_database.Refno=ichek_remark.Refno WHERE  ichek_database.Refno LIKE '%".substr($_SESSION['client_code'], 0, 4)."%' AND (ichek_database.reasonpending NOT LIKE '%dup%' AND ichek_database.reasonpending NOT LIKE '%stop%') AND (ichek_database.reportdate!='' AND ichek_database.reportdate!=0 AND ichek_database.reportdate IS NOT NULL) AND (ichek_remark.negdedupcolor='' OR ichek_remark.negdedupcolor IS NULL OR ichek_remark.negdedupcolor='Green');")->row();

                //MIS Amber Cases
            $this->data['mis_amber']=$this->load->database('mis',TRUE)->query("SELECT COUNT(*) as yellow FROM ichek_database INNER JOIN ichek_remark ON ichek_database.Refno=ichek_remark.Refno WHERE  ichek_database.Refno LIKE '%".substr($_SESSION['client_code'], 0, 4)."%' AND (ichek_database.reasonpending NOT LIKE '%dup%' AND ichek_database.reasonpending NOT LIKE '%stop%') AND (ichek_database.reportdate!='' AND ichek_database.reportdate!=0 AND ichek_database.reportdate IS NOT NULL) AND ichek_remark.negdedupcolor='Amber';")->row();

                //MIS Red Cases
            $this->data['mis_red']=$this->load->database('mis',TRUE)->query("SELECT COUNT(*) as red FROM ichek_database INNER JOIN ichek_remark ON ichek_database.Refno=ichek_remark.Refno WHERE  ichek_database.Refno LIKE '%".substr($_SESSION['client_code'], 0, 4)."%' AND (ichek_database.reasonpending NOT LIKE '%dup%' AND ichek_database.reasonpending NOT LIKE '%stop%') AND (ichek_database.reportdate!='' AND ichek_database.reportdate!=0 AND ichek_database.reportdate IS NOT NULL) AND ichek_remark.negdedupcolor='Red';")->row();

                //MIS Stop Cases
            $this->data['mis_stop']=$this->load->database('mis',TRUE)->query("SELECT COUNT(*) as stop FROM ichek_database INNER JOIN ichek_remark ON ichek_database.Refno=ichek_remark.Refno WHERE  ichek_database.Refno LIKE '%".substr($_SESSION['client_code'], 0, 4)."%' AND ichek_database.reasonpending LIKE '%stop%';")->row();
        }   
    }

    public function getCount()
    {
        if($this->ion_auth->in_group('admin'))
        {
            $query=$this->db->query("select count(vbasic.id) as num, vbasic.status from basic as vbasic inner join users on vbasic.user_id=users.id WHERE users.org=".$this->session->org." group by vbasic.status;");
        }
        else if($this->ion_auth->in_group('client'))
        {
            $query=$this->db->query("select count(vbasic.id) as num, vbasic.status from basic as vbasic inner join users on vbasic.user_id=users.id where vbasic.Refno like '%".$this->session->client_code."%' and users.org=".$this->session->org." group by vbasic.status;");
        }
        else if($this->ion_auth->in_group('dev'))
        {
            $query=$this->db->query("select count(vbasic.id) as num, vbasic.status from basic as vbasic inner join users on vbasic.user_id=users.id WHERE users.org=".$this->session->org." group by vbasic.status;");
        }

        $this->data['countData'] = array_column($query->result_array(), 'num', 'status');
    }

    public function getClientList()
    {
        if($_SESSION['org']==1)
        {
            $this->data['mis_clients']=$this->load->database('mis',TRUE)->query("SELECT DISTINCT(temp.full_name) as full_name, temp.client FROM temp INNER JOIN ichek_basic ON temp.client=ichek_basic.client INNER JOIN ichek_database ON ichek_basic.Refno=ichek_database.Refno WHERE temp.client NOT LIKE '%test%' AND ichek_database.reasonpending NOT LIKE '%dup%' ORDER BY temp.full_name")->result();
        }
        else
        {
            $this->data['clients'] = $this->db->query("SELECT DISTINCT(users.company), users.client_code FROM `users` INNER JOIN users_groups on users.id=users_groups.user_

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you have used $this->data but u have not defined it

$this->load->view('welcome_message', $this->data);

define it in constructor like this :

public function __construct()
    {
        parent::__construct();
        
        if (!$this->ion_auth->logged_in()  || empty($this->session->name)) 
        {
            redirect('/login');
        }
        $this->data = [];
        $this->load->helper('url');
        $this->load->model('BasicModel', 'basic');
        $this->load->model('LabelModel', 'label');
    }

for your new error : you are using $mis_green as object

 $green= $green+$mis_green->green;

may be its an array kindly check it if its an array use it like this :

 $green= $green+$mis_green['green'];
 $red= $red+$mis_red['red']; 
 $yellow= $yellow+$mis_amber['yellow'];
 $stopcase= $stopcase+$mis_stop['stop']; 
 $inprocess= $inprocess+$mis_pending['pending'];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...