简体   繁体   English

致命错误:在非对象,代码点火器控制器上调用成员函数

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

Here's my controller profileinfo.php 这是我的控制器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');
        }
    }
}
?>

and here's is my model aluminsert.php 这是我的模型aluminsert.php

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

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

form validation is working and after submitting the form, the error shown is: Fatal error: Call to a member function alum_insert() on a non-object in C:\\wamp\\www\\ci\\application\\controllers\\profileinfo.php on line 61 表单验证正在运行,并且提交表单后,显示的错误是:致命错误:在C:\\ wamp \\ www \\ ci \\ application \\ controllers \\ profileinfo.php中的非对象上调用成员函数alum_insert() 61

The error lies in the code below. 错误在于下面的代码。 You are trying to call a method from the 'insert' class which in this case does not exist in your model. 您正在尝试从“插入”类中调用方法,在这种情况下,该方法在您的模型中不存在。

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

Your Model is called 'Aluminsert' and the method you are using to insert is called 'alum_insert' so you should rather do this. 您的模型称为“ Aluminsert”,而您要用于插入的方法称为“ alum_insert”,因此您应该这样做。

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

In codeigniter we need to load the database. 在codeigniter中,我们需要加载数据库。 So there are two ways 所以有两种方法

  1. Either you can autoload it or 您可以自动加载它,也可以
  2. Load where ever you need it. 加载到您需要的任何地方。

In autoload.php ,you have to write the below line. autoload.php中 ,您必须编写以下行。

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

OR 要么

In other manner you can also load in following manner :- 您还可以通过其他方式加载以下内容:

$this->load->database();

Surely it will help you. 当然可以,对您有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:在Codeigniter中的非对象上调用成员函数result() - Fatal error: Call to a member function result() on a non-object in Codeigniter 致命错误:在(CodeIgniter)中的非对象上调用成员函数query() - Fatal error: Call to a member function query() on a non-object in (CodeIgniter) codeigniter致命错误在非对象上调用成员函数cookie() - codeigniter fatal error Call to a member function cookie() on a non-object Codeigniter 致命错误:调用非对象上的成员函数 query() - Codeigniter Fatal error: Call to a member function query() on a non-object CodeIgniter随机PHP致命错误:在... mysqli_driver.php中的非对象上调用成员函数。 - CodeIgniter Random PHP Fatal error: Call to a member function … on a non-object in … mysqli_driver.php CodeIgniter致命错误:调用非对象上的成员函数display_clients() - CodeIgniter fatal error: Call to a member function display_clients() on a non-object Codeigniter / Postgresql:致命错误:在非对象上调用成员函数num_rows() - Codeigniter/Postgresql: Fatal error: Call to a member function num_rows() on a non-object Codeigniter-致命错误:在非对象上调用成员函数get_news() - Codeigniter- Fatal error: Call to a member function get_news() on a non-object Codeigniter 应用程序返回“致命错误:在实时而非本地调用非对象 in”上的成员函数 result() - Codeigniter App Returns `Fatal error: Call to a member function result() on a non-object in` on live but not local Codeigniter:致命错误:在非对象上调用成员函数num_rows() - Codeigniter : Fatal error: Call to a member function num_rows() on a non-object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM