rfrkk 发表于 2018-7-19 10:46:04

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

本帖最后由 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";
    }
}

Hex 发表于 2018-7-20 17:39:24

是的,CI 3 不支持 namespace,必须采用不同名的控制器和模型。目前只有 CI4 支持 namespace
页: [1]
查看完整版本: 在controller某個function载入相同Class名称的model運行失敗