doupeizheng3918 2015-08-08 11:45
浏览 33
已采纳

找不到类 - OOP

i'm watching a tutorials about CMS with OOP - PHP

i have error but to check it

i have to check ArticlesCatsModel.php first

on control page : (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();

?>  

when i run it i get error

Fatal error: Class 'System' not found in /var/www/html/cms/includes/models/ArticlesCatsModel.php on line 11

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条回答 默认 最新

  • dqayok7935 2015-08-08 11:51
    关注

    Require the globals.php in your ArticlesCatsModel.php. So the System class can be used.

    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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部