简体   繁体   English

CodeIgniter致命错误:调用非对象上的成员函数display_clients()

[英]CodeIgniter fatal error: Call to a member function display_clients() on a non-object

I am writing a program that basically does stuff with a database, I am having trouble with some of the functionality though, this is what it is supposed to do 我正在编写一个基本上可以处理数据库的程序,但是我在某些功能上遇到了麻烦,这是应该做的

public function clist() {
$this->load->model('list_model');
$fields = $this->list_model->listcli();
if ($fields === $this->list_model->listcli()) {
    $fieldl = $fields;
    $this->load->view('clientlist');
    $this->clientlist->display_clients($fieldl);
}

}

This loads the model which looks like this: 这将加载如下所示的模型:

public function listcli()
{
 $this->db->list_fields('clients');
}

} }

Then runs the model function listcli so that it will list all the fields in the clients database and puts the value into $fields I then call it fieldl and load a view that will show the data, the view looks like this: 然后运行模型函数listcli以便它将列出客户端数据库中的所有字段并将值放入$fields ,然后将其fieldl并加载一个将显示数据的视图,该视图如下所示:

<html>
<body>
<p> sup </p>
<?php

 function display_clients($fieldl)
 {

        ?>
        <html>
            <body>
            <p> sup2 </p>
                <ul>
                <?php
                foreach ($fieldl as $l) {
                ?>
                <li> 
                    <?php echo $l;?>
                </li>
                <?php
                }
    }

Then calls the function inside the view and passed the data from $fieldl into it. 然后在视图内调用该函数,并将数据从$fieldl传递到该视图中。

but I am getting the error " Call to a member function display_clients() on a non-object in /codeigniter/src/application/controllers/clientlist.php on line 40" 但是我收到错误“在第40行的/codeigniter/src/application/controllers/clientlist.php中的非对象上调用成员函数display_clients()”

line 40 is 40行是

$this->clientlist->display_clients($fieldl);

Can you help? 你能帮我吗? Please and thank you. 谢谢,麻烦您了。

(I know this kind of question has been asked before but they are always very specific to the code at hand so doesn't help me, I am really new to CodeIgniter so if you can keep any answer relatively simple I will be grateful). (我知道这种问题以前曾被问过,但它们总是非常针对手头的代码,因此对我没有帮助,对于CodeIgniter来说我真的很陌生,因此,如果您能保持相对简单的答案,我将不胜感激。)

Why can't you prepare the list in the controller and pass it to view via $data array? 为什么不能在控制器中准备列表,然后通过$data数组将其传递给视图?

$my_list = '<ul>';
foreach ($fieldl as $l) {
$my_list .= '<li>'.$l.'</li>';
}
$my_list .= '</ul>';

$data['my_list'] = $my_list;

then you can access it in view as $my_list . 那么您可以在视图中以$my_list对其进行访问。 Just echo it where you need it. 只需在需要时回显它即可。

EDIT: AS per your own answer, yes - exactly. 编辑:按照您自己的答案,是的-完全是。 Using example above you would pass the $data to view as the second parameter: 使用上面的示例,您将传递$data作为第二个参数进行查看:

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

Then in the View, you access $data['my_list'] as $my_list , $data['foo'] as $foo etc. 然后在视图中,以$my_list访问$data['my_list'] ,以$foo等访问$data['my_list'] $data['foo']

我需要使用第二个参数将数据传递到视图中,而不是自己的临时解决方案,CI接受一个对象作为CI_Loader :: view()的第二个参数

暂无
暂无

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

相关问题 致命错误:在非对象,代码点火器控制器上调用成员函数 - Fatal error: Call to a member function, on a non-object, codeigniter controller 致命错误:在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 致命错误:在非对象上调用成员函数display() - Fatal error: Call to a member function display() 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随机PHP致命错误:在... mysqli_driver.php中的非对象上调用成员函数。 - CodeIgniter Random PHP Fatal error: Call to a member function … on a non-object in … mysqli_driver.php Codeigniter 应用程序返回“致命错误:在实时而非本地调用非对象 in”上的成员函数 result() - Codeigniter App Returns `Fatal error: Call to a member function result() on a non-object in` on live but not local
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM