简体   繁体   English

CodeIgniter:模型包含函数时为空白页

[英]CodeIgniter: blank page when a model contains a function

i'm using codeigniter for a website project. 我正在为网站项目使用codeigniter。 when i include a model, it will work as long as no function is implemented (except the constructor). 当我包含一个模型时,只要不执行任何功能(构造函数除外),它将起作用。

this configuration works: 此配置有效:

class Xyz_model extends CI_Model {

    function __construct() {

    }
}

this doesn't: 这不是:

class Xyz_model extends CI_Model {

    function __construct() {

    }

    public function get_xyz() {
        return [        
            "xy" => ["xy"],
            "yz" => ["xy"],
            "zz" => ["xy","zx","zy"]
        ];
    }
}

there is not even an database access... and i have no clue why it is not working. 甚至没有数据库访问权限...而且我不知道为什么它不起作用。

You are extending the core model class, but the child's constructor is being used in placed of the parents: 您正在扩展核心模型类,但是使用了子代的构造函数代替了父代:

parent::__construct();

Add that to your models constructor. 将其添加到您的模型构造函数中。

use this 用这个

In model 在模型中

class Xyz_model extends CI_Model {

    function __construct() {

    }

    public function get_xyz() {
        $array = array(
            'xy' => 'xy',
            'yz' => 'xy',
            'zz' => array("xy","zx","zy")
        );
        return $array;
    }
}

In controller 在控制器中

$new = $this->Xyz_model->get_xyz()

print_r($new);

so output will be 所以输出将是

Array ( [xy] => xy [yz] => xy [zz] => Array ( [0] => xy [1] => zx [2] => zy ) )

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM