codeigniter 发送逗号分隔的值作为单个参数

wi3ka0sx  于 4个月前  发布在  其他
关注(0)|答案(1)|浏览(40)

我试图在一个参数中将逗号分隔的值从控制器发送到模型方法。
例如,模型中有一个函数:

public function bar($param1){
//....///
  $this->datatables->edit_column($param1);
//....///
}

字符串
从控制器中,我试图发送一个参数,如下所示:

public function foo(){
   //...//
    $param = "'username', '<a href="profiles/edit/$1">$2</a>', 'id, username'";
    $this->model->bar($param);
   //...//
   }


我面临的第一个问题是,我只知道两个字符''"",因为我不能把它作为正确的字符串发送,也不擅长转义。
另外,我想我正在尝试的是,它将作为字符串在该函数中发送,但edit_column需要3个不同的逗号分隔值。
下面是我的整个Datatables通用模型,它使用了点火数据表库:

//Common DataTables Queries
function select_fields_joined_DT($data, $PTable, $joins = '', $where = '',$group_by = '', $addColumn = '', $editColumn = '',$unsetColumn = '')
{
    $this->datatables->select($data);
    if ($unsetColumn != '') {
        $this->datatables->unset_column($unsetColumn);
    }
    $this->datatables->from($PTable);
    if ($joins != '') {
        foreach ($joins as $k => $v) {
            $this->datatables->join($v['table'], $v['condition'], $v['type']);
        }
    }
    if ($where != '') {
        $this->datatables->where($where);
    }
    if($group_by != ''){
        $this->datatables->group_by($group_by);
    }
    if ($addColumn != '') {
        $this->datatables->add_column("Actions", $addColumn);
    }
    if ($editColumn != ''){
        $this->datatables->edit_column($editColumn);
    }
    $result = $this->datatables->generate();
    return $result;
}
//End of Common DataTables Queries


我被数据表的edit_column函数卡住了。
edit_column应该是这样的:

$this->datatables->edit_column('username', '<a href="profiles/edit/$1">$2</a>', 'id, username');


我只是想知道我如何在单个参数中发送用逗号分隔的不同值?或者我只需要发送数组或其他东西?
下面是我试图保存保存三个逗号分隔值的变量:

$editColumn = "\'employee.employee_id\',\'<a href=\"dashboard_site/view_skills/$1\"><span class=\"fa fa-eye\"></span></a>\',\'employee.employee_id\'";

jmo0nnb3

jmo0nnb31#

这样修改

$editColumn = "'employee.employee_id','<a href=\"dashboard_site/view_skills/$1\"><span class=\"fa fa-eye\"></span></a>','employee.employee_id'";

字符串
它会产生这样的字符串

'employee.employee_id','<a href="dashboard_site/view_skills/$1"><span class="fa fa-eye"></span></a>','employee.employee_id'


你也可以用另一种方法。将数据作为数组发送,然后在你的模型上转换它们。

相关问题