【问题标题】:CodeIgniter custom_result_object class parameterCodeIgniter custom_result_object 类参数
【发布时间】:2015-11-12 08:32:08
【问题描述】:

在我的模型中,我有:

function select_by_limit($start, $limit) {
    $this->db->from($this->_table.' a');
    $this->db->join('zone b', "a.id_zona = b.id_zona", 'left');
    $this->db->join('tip_proprietate c', "a.id_tip_proprietate = c.id_tip_proprietate");
    $this->db->limit($limit, $start);
    $query = $this->db->get_compiled_select();
    $result = $this->db->query($query);
    return $result->custom_result_object('Proprietati');
}

所以我使用自定义对象类 Proprietati。但是如何发送参数以便在构造函数中获取它?

public function __construct($resolution = 270){
    $this->_resolution = $resolution;
}

【问题讨论】:

  • Proprietati 类是否作为 ci 库加载?
  • 您唯一的选择是在application/core 中编写MY_DB_result 类并覆盖custom_result_object()codeigniter.com/user_guide/general/core_classes.html
  • pastebin.com/WpUTt9uK 像这样。
  • 那么这是通过该决议的唯一选择吗?
  • @IonVasile 您还可以获得一个 result_array() 并将您的类加载为库。您可以选择在构造函数中传递选项,但您可能需要稍微更改构造函数实现以添加其他参数。

标签: php codeigniter model-view-controller


【解决方案1】:

控制器

class foo extends CI_Controller {
    protected $_resolution;

    public function __construct($resolution = 270){
        $this->_resolution = $resolution;
    }

将 $resolution 传递给模型函数

public function using_model($start, $limit, $this->resolution);

在模型中

function select_by_limit($start, $limit, $resolution) {
    //whatever happens here....

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-20
    • 2013-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多