发送逗号分隔值以用作单个参数

问题描述 投票:0回答:1

我正在尝试在单个参数中将逗号分隔的值从控制器发送到模型方法。

比如model中有一个函数:

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 个不同的逗号分隔值。

下面是我使用 Ignited Data-tables 库的整个数据表通用模型:

//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\'";
php codeigniter datatables
1个回答
0
投票

这样修改

$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'

您可以采用替代方式。将数据作为数组发送并在您的模型中进行转换。

© www.soinside.com 2019 - 2024. All rights reserved.