doujie7497 2015-08-09 15:37
浏览 37
已采纳

从数据库获取信息

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

on control page : (articles.php)

<?php
require_once('globals.php');
require_once(CONTROLLERS.'ArticlesController.php');

$articlesmodel = new ArticlesModel() ; 

$catsmodel     = new ArticlesCatsModel();

$controller    = new ArticlesController($articlesmodel,$catsmodel);

$controller->show();

?>

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()); //class RainTPL
?>

ArticlesController.php

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


require_once(MODELS.'ArticlesModel.php');
require_once(MODELS.'ArticlesCatsModel.php');


class ArticlesController
{

    private $articlesModel; //Articles Model Object
    private $articlesCatsModel; //Articles Cat Model Object
                               //object of ArticlesModel class
    public function __construct(ArticlesModel $articlesmodel,ArticlesCatsModel $catsmodel)
    {

        $this->articlesModel     = $articlesmodel ;
        $this->articlesCatsModel = $catsmodel ; 
    }


    public function Show()
    {
        // array of articles from model :D 
        /*
           he takes object from Articlesmodel.php
           like private articles model 
           then he  call the Get function 
           from  ArticlesModel Class 
        */

        $articles = $this->articlesModel->Get();
        $cats     = $this->articlesCatsModel->Get();


        //put them inside the template after getting them
        System::Get('tpl')->assign('articles',$articles)    ;   
        System::Get('tpl')->assign('cats',$cats)    ;   

        // show them in the templatee

        System::Get('tpl')->draw('blog');
    }

}

Blog Where articles should be shown

but there's no problem in Blog

the problem is that $articles = $this->articlesModel->Get(); returns blank array doesn't contain the information from DB

The ArticlesCatsModel

ArticlesCatsModel includes/model

The ArticleModel

ِArticlesModel

3: http://pastebin.com/z2dzcBVc it returns blank array even there are rows in DB


This is Template i should see the articles that i get from DB

but the result is No Articles

to check where exactly the problem

i typed

in Articles.Controller.php

    $articles = $this->articlesModel->Get();
    var_dump($articles).'<br/>'; 
    $cats     = $this->articlesCatsModel->Get();
    print_r($cats); 

and if you noticed in the picture it success when i call $cats but i return blank array of $articles

Template

  • 写回答

1条回答 默认 最新

  • duanmu5039 2015-08-09 18:14
    关注

    Try to replace

    SELETE * FROM 
    

    with

    SELECT * FROM 
    

    in your Get() method in ArticlesModel.php file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大