[英]Message: Trying to get property of non-object Codeigniter
I'm trying to create a simple piece of PHP code to display tweets using the twitter API, that just displays tweets about EVE Online - as a test. 我正在尝试创建一个简单的PHP代码,以使用twitter API显示推文,该推文仅显示有关EVE Online的推文-作为测试。 The code below does work however, I get the following error PHP notice after it:
下面的代码可以正常工作,但是我收到以下错误PHP通知:
A PHP Error was encountered
遇到PHP错误
Severity: Notice
严重程度:注意
Message: Trying to get property of non-object
消息:试图获取非对象的属性
Filename: pages/about.php
文件名:pages / about.php
Line Number: 17
行号:17
Here is my code: 这是我的代码:
<?php include('twitteroauth.php');?>
<?php include('get_tweet.php');?>
<div id="tweets">
<?php
$tweets = $twitter->get('https://api.twitter.com/1.1/search/tweets.jsonq=EveOnline&
result_type=recent&count=10' );
foreach($tweets as $tweet)
{
foreach($tweet as $t)
{
echo '<div id="tweetwrap"><img src="'.$t->user->profile_image_url.'"/>'
.$t->text.'</div>';
}
}
?>
</div>
I'm not using CodeIgniter's controllers or methods to do this. 我没有使用CodeIgniter的控制器或方法来执行此操作。 I'm trying to do it outside of CodeIgniter whilst using CodeIgniter for everything else.
我正在尝试在CodeIgniter之外执行此操作,同时将CodeIgniter用于其他所有操作。 I'm sure there's a way, however I don't understand why CodeIgniter displays errors when I'm not using any of it's controllers or methods.
我敢肯定有办法,但是我不明白为什么在不使用任何控制器或方法时CodeIgniter会显示错误。
I've also tried this: 我也尝试过这个:
echo '<div id="tweetwrap"><img src="'.$t->user['profile_image_url'].'"/>'
.$t['text'].'</div>';
But this also does not work. 但这也不起作用。 Please help.
请帮忙。
got it, basically i replaced the foreach loop with this: 知道了,基本上我用以下代码替换了foreach循环:
<?php include('twitteroauth.php');?>
<?php include('get_tweet.php');?>
<div id="tweets">
<?php
foreach($tweets->statuses as $status)
{
echo '<div id="tweetwrap"><img src="'.$status->user-
>profile_image_url.'"/>';
echo "User: " .$status->user->screen_name."</br>";
echo "<p>Tweet: " .$status->text."</p></br>";
echo "</br></div>";
}
?>
If its an array use this: 如果是数组,请使用以下命令:
echo '<div id="tweetwrap"><img src="'.$t['user']['profile_image_url'].'"/>'
.$t['text'].'</div>';
instead of: 代替:
echo '<div id="tweetwrap"><img src="'.$t->user['profile_image_url'].'"/>'
.$t['text'].'</div>';
EDIT 编辑
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.