制作虚拟主机后出现错误

时间:2018-07-13 05:48:19

标签: php apache codeigniter ubuntu codeigniter-3

我在Codeigniter中开发了一个项目。当我尝试使用localhost/bmlivenew在本地主机上的浏览器中访问它时,它工作正常。但是在建立了虚拟主机之后,当我使用www.bmlivenew.com在浏览器上对其进行访问时,它将显示该网站,但是在其顶部,它将显示一个错误

  

遇到PHP错误       严重程度:注意       消息:未定义的变量:designer_images       文件名:controllers / Designs.php       行号:42       回溯:       文件:/var/www/html/bmlivenew/application/controllers/Designs.php       行:42       函数:_error_handler       文件:/var/www/html/bmlivenew/index.php       线:324       功能:require_once

鉴于此,变量$designer_images的定义正确,如果我尝试使用localhost / bmlivenew访问网站,则不会引发此类错误。

我在Designs控制器中定义了$designer_images的代码束。

$designers  = $this->interior_images_m->get_by($cond);
foreach ($designers as $key => $designer) {

            $designer_images = $this->interior_new_m->get_by(array('id'=>$designer->name));
            $designers[$key]->images = $designer_images; 

        }


        $this->data['names'] = $designer_images;
        $this->data['designers'] = $designers;

        // Load View
        $this->load->view("frontend/ourdesign",$this->data);

欢迎任何帮助。

1 个答案:

答案 0 :(得分:1)

希望这对您有帮助:

首先在foreach循环上方初始化$designer_images

应该是这样的:

$designers = $this->interior_images_m->get_by($cond);
$designer_images = NULL; 
foreach ($designers as $key => $designer) 
{ 
    $designer_images = $this->interior_new_m->get_by(array('id' => $designer->name)); 
    $designers[$key]->images = $designer_images; 
} 
$this->data['names'] = $designer_images; 
$this->data['designers'] = $designers;