用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1615|回复: 2
收起左侧

[模型] 在controller某個function载入相同Class名称的model運行失敗

[复制链接]
发表于 2018-7-19 10:46:04 | 显示全部楼层 |阅读模式
本帖最后由 rfrkk 于 2018-7-19 13:36 编辑

请问若不更动以下的架构,仍有解法吗? 感谢!

另外我有尝试在这些model的档案使用namespace,CI似乎却不能理解,显示 store1/coffee_model的class已经载入,不能再载入相同名称的class

ex:

// controller

public function () {

        $this->load->model('store1/coffee_model', 's1');
        $this->s1->showBrands();  // 显示 cao

               
        $this->load->model('store2/coffee_model', 's2');
        $this->s2->showBrands();  // 显示 cao ,而不是taboho
    }

// model/store1/coffee_model.php

class Coffee_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function showBrands() {
        return "cao";
    }
}

// model/store2/coffee_model.php

class Coffee_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function showBrands() {
        return "taboho";
    }
}

发表于 2018-7-20 17:39:24 | 显示全部楼层
是的,CI 3 不支持 namespace,必须采用不同名的控制器和模型。目前只有 CI4 支持 namespace
回复 支持 1 反对 0

使用道具 举报

本版积分规则