Home  >  Q&A  >  body text

Why does the page prompt that the variable ImgList is not defined?

Modified based on the teacher’s gradeList

public function imgList()
{
$Image = img_tb::all();

$count = img_tb::count ( ); $value->name,
                                                                                                                                                           ] = $data;
}
$this->view->assign('imgList',$ImgList);
$this->view->assign('count',$ count);
//Render image list template
return $this -> fetch('img_list');
}

JerryJerry2478 days ago2020

reply all(8)I'll reply

  • 宇瞳

    宇瞳2018-05-10 10:48:18

    Define $i=0 before foreach;


    $ImgList[$i] = $data;

    $i++;

    That’s it

    reply
    0
  • 宇瞳

    Add $ImgList=array(); in front of it.

    宇瞳 · 2018-05-10 23:53:02
  • 韦小宝

    韦小宝2018-01-30 09:10:53

    Then try declaring this variable before and assign it to empty.

    reply
    0
  • Jerry

    It is true that no error is reported, but the database data cannot be displayed on the page.

    Jerry · 2018-01-30 13:38:06
    Jerry

    The variables read out, the output array is empty

    Jerry · 2018-01-30 13:41:55
    Jerry

    foreach ($Image as $value) { $data = [ 'id' => $value->id, 'name' => $value->name, 'img' => $value->img, 'create_time' => $value->create_time, 'update_time' => $value->update_time, ]; $imgList[] = $data; dump($data); } This is what I output. Where can I see the output?

    Jerry · 2018-01-30 14:01:16
    韦小宝

    Print the variable to see if it has a value

    韦小宝 · 2018-01-30 13:40:42
    韦小宝

    Print $data and see if there is any value. By the way, your $ImgList is empty and is best placed at the front of the method.

    韦小宝 · 2018-01-30 13:43:06
  • Cancelreply