-4
public static function view($name, array $vars = null){
    if(preg_match('/\\\\/', $name)){
        $view_data = explode('\\', $name);
        if(count($view_data) == 3)
            $file = APP_PATH.DS.'views'.DS.$view_data[0].DS.$view_data[1].DS.'view.'.$view_data[2].'.php';
        else
            $file = APP_PATH.DS.'views'.DS.$view_data[0].DS.'view.'.$view_data[1].'.php';
    }
    else{
        $file = APP_PATH.DS.'views'.DS.'view.'.$name.'.php';
    }
    if(!is_readable($file)){
        throw new Exception('view file application'.DS.'views'.DS.$view_data[0].DS.'view.'.$view_data[1].'.php not found.');
    }
    else{
        if(isset($vars)){
            extract($vars);
        }
        require($file);
    }
}

[21-Apr-2015 13:10:30 UTC] PHP Notice: Undefined variable: view_data in /home/realitycards/public_html/test/system/load.class.php on line 28

Smern
  • 18,066
  • 21
  • 67
  • 87
Christian
  • 48
  • 10
  • 1
    And your question is...? – Marvin Apr 21 '15 at 14:55
  • first define $view_data = ''; out side of if and before working on it please check that $view_data is having some value or not means apply check if(isset($view_data ) && !empty($view_data)){// then all other code – Anant Kumar Singh Apr 21 '15 at 14:58

1 Answers1

2

your variable $view_data only gets defined in the first if statement. It looks like in the if statement below that you are using $view_data even though it hasn't been set.

if(!is_readable($file)){
    throw new Exception('view file application'.DS.'views'.DS.$view_data[0].DS.'view.'.$view_data[1].'.php not found.');
}

You either need to set $view_data in your else statement, or in the exception above, use the $file variable that you've already set:

if(!is_readable($file)){
    throw new Exception('view file '. $file .' not found.');
}
Bob Nocraz
  • 436
  • 7
  • 16
  • @Christian that probably means that your variable $name is 'default/header.php', looking at your concatenation. – Bob Nocraz Apr 21 '15 at 15:13
  • on my local computer works perfect , on centos 6 easyapache works now but had to edit all files from view.name to name – Christian Apr 21 '15 at 15:20