小编dqi*_*qiu的帖子

如何从CodeIgniter中的另一个模型继承模型

我正在为我的项目使用codeigniter,我有这个类模型,我称之为Genesis,如下所示:

class Genesis_model extends CI_Model {
    function __construct() {
        parent::__construct();
    }

    function get() {
        return 'human soul';
    }
}
Run Code Online (Sandbox Code Playgroud)

我有另一个模型,存储在同一目录中,扩展了Genesis_model

class Human_model extends Genesis_model {
    function __construct() {
        parent::__construct();
    }

    function get_human() {
        return $this->get();
    }
}
Run Code Online (Sandbox Code Playgroud)

Human_model由Human控制器使用

class Human extends CI_Controller {     
    function __construct(){
        parent::__construct();
        $this->load->model('human_model');
    }       

    function get_human() {
        $data['human'] = $this->human_model->get_human();
        $this->load->view('human/human_interface', $data);
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我执行代码,它将产生一个错误,指向返回$ this-> get().它显示"致命错误:在第2行的......\application\models\human_model.php中找不到类'Genesis_model'".

我使用这种方法是因为几乎所有模型都共享几乎相同的结构.我在Genesis中收集了类似的功能,而其他模型仅作为它们所代表的表所特有的数据供应商.它在我的asp.net(vb.net)中运行良好,但我不知道如何在codeigniter中执行此操作.

有没有办法让Human_model继承Genesis_model.我不认为我可以使用include('genesis_model.php').我不知道它是否有效.

提前致谢.

inheritance extends model codeigniter

10
推荐指数
3
解决办法
1万
查看次数

如何防止array_merge重新编号数字键

我有一个看起来像这样的数组:

Array ( 
    [0] => Array ( [unit_id] => 1 [unit_name] => Clown Fish) 
    [1] => Array ( [unit_id] => L [unit_name] => Liter ) 
    [2] => Array ( [unit_id] => 2 [unit_name] => Elephant  ) 
    [3] => Array ( [unit_id] => 3 [unit_name] => Water Bottle ) 
    [4] => Array ( [unit_id] => 4 [unit_name] => Office Seating ) 
    [5] => Array ( [unit_id] => 5 [unit_name] => Green Green Grass ) 
)
Run Code Online (Sandbox Code Playgroud)

然后,我写了一个函数

function array_to_list($arr_data, $str_key, $str_value) { …
Run Code Online (Sandbox Code Playgroud)

php arrays array-merge

8
推荐指数
2
解决办法
3873
查看次数

如何在php(或codeigniter)中区分ajax调用和浏览器请求?

有没有办法区分ajax调用和PHP中的普通浏览器请求(或codeigniter是具体的)?

这是我的jquery ajax调用:

$(document).ready(function() {
    $('#container').load('http://localhost/index.php/customer/'); 
});
Run Code Online (Sandbox Code Playgroud)

这是codeigniter中客户控制器的索引方法:

public function index() {
    //if (call == 'ajax request') 
    //  do this if it's an ajax request;
    //else
    //  do that if user directly type the link in the address bar;
    $this->load->view('customer/listview');
}
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激.谢谢.

php ajax jquery codeigniter

5
推荐指数
1
解决办法
1209
查看次数

如何不在js文件中硬编码codeigniter链接

我编写了下面的例程,根据我的codeigniter应用程序选择的国家/地区检索城市.

$(document).ready(function() {
    $("select#cbo_country").change(function() {
        $.post("http://localhost/main/index.php/city/get_data_by_country", {
            int_country_id  : $(this).val()
        },
        function(data) {
            // some code here
        },'json');
    })
});
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我对网址进行了硬编码(http://localhost/main/index.php/city/get_data_by_country),我知道这是一个不好的做法,但我无法帮助它.

有没有一个很好的干净方法来不硬编码网址?我以前使用codeigniter的base_url(),但由于我将例程移动到js文件,我不再能够使用该函数.

javascript jquery codeigniter

3
推荐指数
1
解决办法
6116
查看次数