簡體   English   中英

致命錯誤:在非對象,代碼點火器控制器上調用成員函數

[英]Fatal error: Call to a member function, on a non-object, codeigniter controller

這是我的控制器profileinfo.php

<?php
class Profileinfo extends CI_Controller {

    function index()
    {

        $this->load->helper(array('form', 'url'));
        $this->load->model('aluminsert','', TRUE);
        $this->load->library('form_validation');

        $this->form_validation->set_rules('name', 'Name', 'required');
        $this->form_validation->set_rules('branch', 'Bramch', 'required');
        $this->form_validation->set_rules('academicinterest', 'Academic Interest', 'required');
        $this->form_validation->set_rules('internshipdetail', 'Internship Details', 'required');
        $this->form_validation->set_rules('interest_hobbies', 'Interest and hobbies', 'required');
        $this->form_validation->set_rules('personalblog', 'Personal Blog', 'required');
        $this->form_validation->set_rules('facebookprofile', 'Facebook Profile', 'required');
        $this->form_validation->set_rules('linkedinprofile', 'Linkedin Profile', 'required');
        $this->form_validation->set_rules('homecity', 'Home city', 'required');
        $this->form_validation->set_rules('country', 'country', 'required');
        $this->form_validation->set_rules('higherdegree', 'Higher Degree', 'required');
        $this->form_validation->set_rules('collegeofeducation', 'College of Education', 'required');
        $this->form_validation->set_rules('officialemail', 'Official Email', 'required');
        $this->form_validation->set_rules('careerinterests', 'Career Interest', 'required');
        $this->form_validation->set_rules('presentemployer', 'Present Employer', 'required');
        $this->form_validation->set_rules('presentjob', 'Present Job', 'required');
        $this->form_validation->set_rules('previousemployer', 'Previous Employee', 'required');
        $this->form_validation->set_rules('startupname', 'Startup Name', 'required');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('alumprofile');

        }
        else
        {
            $alumdata = array(
            'Name' => $this->input->post('name'),
            'Branch' => $this->input->post('branch'),
            'Academic Interest' => $this->input->post('academicinterest'),
            'Internship Details' => $this->input->post('internshipdetail'),
            'Interest and hobbies' => $this->input->post('interest_hobbies'),
            'personalblog' => $this->input->post('personalblog'),
            'Facebook profile' => $this->input->post('facebookprofile'),
            'Linkedin profile' => $this->input->post('linkedinprofile'),
            'Home city' => $this->input->post('homecity'),
            'country' => $this->input->post('country'),
            'Higher Degree' => $this->input->post('higherdegree'),
            'College of Education' => $this->input->post('collegeofeducation'),
            'Official Email' => $this->input->post('officialmail'),
            'Career Interest' => $this->input->post('careerinterests'),
            'Present Employer' => $this->input->post('presentemployer'),
            'Present Job' => $this->input->post('presentjob'),
            'Previous Employee' => $this->input->post('previousemployer'),
            'Startup Name' => $this->input->post('startupname'),
            );
            // Transfering Data To Model
            $this->insert->alum_insert($alumdata);
            $this->load->view('registration_success');
        }
    }
}
?>

這是我的模型aluminsert.php

<?php
class Aluminsert extends CI_Model{
    function __construct() {
        parent::__construct();
    }
    function alum_insert($alumdata){

        $this->db->insert('user_detail', $alumdata);
    }
}
?>

表單驗證正在運行,並且提交表單后,顯示的錯誤是:致命錯誤:在C:\\ wamp \\ www \\ ci \\ application \\ controllers \\ profileinfo.php中的非對象上調用成員函數alum_insert() 61

錯誤在於下面的代碼。 您正在嘗試從“插入”類中調用方法,在這種情況下,該方法在您的模型中不存在。

$this->insert->alum_insert($alumdata);
$this->load->view('registration_success');

您的模型稱為“ Aluminsert”,而您要用於插入的方法稱為“ alum_insert”,因此您應該這樣做。

$this->aluminsert->alum_insert($alumdata);
$this->load->view('registration_success');

在codeigniter中,我們需要加載數據庫。 所以有兩種方法

  1. 您可以自動加載它,也可以
  2. 加載到您需要的任何地方。

autoload.php中 ,您必須編寫以下行。

$autoload['libraries'] = array('database');

要么

您還可以通過其他方式加載以下內容:

$this->load->database();

當然可以,對您有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM