找不到类 - OOP

时间:2015-08-08 19:45:36

标签: php oop content-management-system

我正在观看有关使用OOP的CMS教程 - PHP

我有错误但要检查

我必须首先检查ArticlesCatsModel.php

控制页面上的

:( ArticlesCatsModel.php)

class ArticlesCatsModel
{

    public function Get($extra='')
    {
        $cats = array();
        System::Get('db')->Execute("SELECT * FROM `articles_cats` {$extra}");
        if(System::Get('db')->AffectedRows()>0)
            $cats = System::Get('db')->GetRows();


        return $cats;
    }
}
$m = new ArticlesCatsModel();
$m->Get();

?>  

当我运行它时我得到错误

  

致命错误:Class' System'在第11行的/var/www/html/cms/includes/models/ArticlesCatsModel.php中找不到

globals.php

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

define('ROOT', dirname(__FILE__));
define('INC', ROOT.'/includes/');
define('CORE', INC.'/core/');
define('MODELS', INC.'/models/');
define('CONTROLLERS', INC.'/controllers/');
define('LIBS', INC.'/libs/');


/**
 * Core Files
 */
require_once(CORE.'config.php');

require_once(CORE.'mysql.class.php');

require_once(CORE.'raintpl.class.php');

require_once(CORE.'system.php');

System::Store('db', new mysql());
System::Store('tpl', new RainTPL());
?>

2 个答案:

答案 0 :(得分:0)

需要ArticlesCatsModel.php中的globals.php。所以可以使用System类。

require_once('path/to/globals.php');

class ArticlesCatsModel
{

   public function Get($extra='')
   {
      $cats = array();
      System::Get('db')->Execute("SELECT * FROM `articles_cats` {$extra}");
      if(System::Get('db')->AffectedRows()>0)
         $cats = System::Get('db')->GetRows();


      return $cats;
   }
}

// why the lines below in the same file?
$m = new ArticlesCatsModel();
$m->Get();  

答案 1 :(得分:0)

我认为类ArticlesCatsModel找不到globals.php

确保在调用globals.php班级时包含ArticlesCatsModel