在View中显示来自控制器的数据时遇到问题。
搜索了这个,尝试了一些东西,但仍然没有为我工作。
我的控制器:
public function microBitcoin()
{
$arr = array('hashtag' => 'myhashtag', 'tweet_id' => '673899616799191040');
$data = array();
$data['liczba_tweetow'] = $this->load->library('Twetterclass', $arr);
$this->load->view('micro_btc', $data);
}
我的观点:
<?php print_r($data); ?>
<?php echo $data['$liczba_tweetow']; ?>
//tried with $data->liczba_tweetow;
我仍然得到同样的错误:
遇到PHP错误
严重性:注意
消息:未定义的变量:数据
文件名:views / micro_btc.php
如何在我的视图中显示此变量?
答案 0 :(得分:2)
答案 1 :(得分:0)
答案 2 :(得分:0)
你的观点应该是这样的
<?php
print_r($liczba_tweetow);
?>
代替
<?php print_r($data); ?>
<?php echo $data['$liczba_tweetow']; ?>
//tried with $data->liczba_tweetow;**strong text**
当我们加载一个包含数据的视图时,我们会在相应的键中将变量转换为变量,这样你就可以获得&#34; $ liczba_tweetow&#34;而是$ data [&#39; $ liczba_tweetow&#39;]
答案 3 :(得分:0)
请在控制器中按照此操作
public function microBitcoin()
{
$data['first'] = 'this is first';
$data['second'] = 'this is second';
$this->load->view('micro_btc', $data);
}
在视图中,您可以像
一样捕获echo $first;
//it will print this is first
echo $second;
//it will print this is second