如何在ci3上获取控制器中的数据

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

如何使用codeigniter 3框架获取控制器中的数据

我在 ci3 控制器中有这样的代码:

public function ajax_list()
{
$list = $this->thesis_title->get_datatables();
$data = array();
$no = $_POST['start'];
$text1 = "Detection of student assignments based on document.";
$text2 ="test program simple levenshtein distance";
$distance=levenshtein($text1, $text2);

foreach ($list as $text_title) {
$no++;
$row = array();
$row[] = $no;
$row[] = $title_text->id_title;
$row[] = $title_text->title;
$row[] = $distance;

$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->title_thesis->count_all(),
"recordsFiltered" => $this->title_thesis->count_filtered(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}

我想要做的是从数据库中检索标题数据并将值分配给 $text1 变量

php codeigniter model-view-controller codeigniter-3
1个回答
0
投票

尝试使用 foreach 循环访问数据库中的标题,

 public function ajax_list()
 {
   $list = $this->thesis_title->get_datatables();
   
   foreach($list as $l){
      $title = $l->title //<------------(your title collumn at database);
   }

   $data = array();
   $no = $_POST['start'];
   $text1 = $title; //<-------inserting result of looping in the variable text1
   $text2 ="test program simple levenshtein distance";
   $distance=levenshtein($text1, $text2);

   foreach ($list as $text_title) {
   $no++;
   $row = array();
   $row[] = $no;
   $row[] = $title_text->id_title;
   $row[] = $title_text->title;
   $row[] = $distance;

   $data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->title_thesis->count_all(),
"recordsFiltered" => $this->title_thesis->count_filtered(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}`
© www.soinside.com 2019 - 2024. All rights reserved.