Php 正在尝试获取非对象的属性
我未能在php代码中选择数据 这是我的密码 home.phpPhp 正在尝试获取非对象的属性,php,mysql,Php,Mysql,我未能在php代码中选择数据 这是我的密码 home.php <div class="row"> <div class="col-sm-8"> <?php foreach (App::getInstance()->getTable('Article')->last() as $post) :?> <h2> <a href="<?= $post->url; ?>"><?= $post
<div class="row">
<div class="col-sm-8">
<?php foreach (App::getInstance()->getTable('Article')->last() as $post) :?>
<h2> <a href="<?= $post->url; ?>"><?= $post->titre; ?></a></h2>
<p><em><?= $post->categorie; ?></em></p>
<p><?= $post->extrait; ?></p>
<?php endforeach; ?>
</div>
articleTable.php
<?php
namespace app\Tables;
use core\Tables\Table;
class ArticleTable extends Table{
public function last(){
return $this->query('select *from articles');
}
}
$post
可能不是这样的对象。尝试将其作为数组进行索引,可能类似于$post['extrat']
您使用的是什么PHP框架?home.php是如何调用/包含的?home.php中的哪一行是第7行?错误是home.php中的一个变量不是对象。我不使用任何框架,这是php oop。。第7行是:
<?php
use core\config;
use core\Database\mySQLDatabase;
class App{
private static $_instance;
private $db_instance;
public static function getInstance(){
if(is_null(self::$_instance)){
self::$_instance = new App();
}
return self::$_instance;
}
public function getTable($name){
$class_name = '\\app\\Tables\\' . ucfirst($name) . 'Table';
return new $class_name($this->getDb());
}
public function getDb(){
$config = Config::getInstance(ROOT . '\config\config.php');
if(is_null($this->db_instance)){
$this->db_instance = new MySQLDatabase($config->get('db_name'),$config->get('db_user'),$config->get('db_pass'),$config->get('db_host'));
}
return $this->db_instance;
}
}