简体   繁体   English

我的Codeigniter视图中的未定义变量

[英]Undefined variable in my Codeigniter View

Having trouble with displaying my data from controller in View. 无法在View中显示来自控制器的数据。

Searched for this, tried few things and still not working for me. 搜索了此内容,尝试了一些尝试,但仍然对我不起作用。

My controller: 我的控制器:

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);
}

My View: 我的观点:

 <?php print_r($data); ?>

 <?php echo $data['$liczba_tweetow']; ?>
 //tried with $data->liczba_tweetow;

I still get the same error: 我仍然收到相同的错误:

A PHP Error was encountered 遇到PHP错误

Severity: Notice 严重程度:注意

Message: Undefined variable: data 消息:未定义的变量:数据

Filename: views/micro_btc.php 文件名:views / micro_btc.php

How I can display this variable in my View? 如何在视图中显示此变量?

You have to use like this, 你必须这样使用

print_r($liczba_tweetow);

see this for more information 看到这个以获取更多信息

 <?php echo $liczba_tweetow; 
       print_r($liczba_tweetow);
  ?>

This is proper way to get data in view. 这是获取数据的正确方法。

Reference 参考

your view should be look like this 您的视图应如下所示

<?php
 print_r($liczba_tweetow); 
?>

instead 代替

<?php print_r($data); ?>

 <?php echo $data['$liczba_tweetow']; ?>
 //tried with $data->liczba_tweetow;**strong text**

when we load a view with the data the it would we converted in variable in respective key so you would get "$liczba_tweetow" instead $data['$liczba_tweetow'] 当我们用数据加载视图时,将在相应键中将其转换为变量,这样您将获得“ $ liczba_tweetow”而不是$ data ['$ liczba_tweetow']

please follow this,in controller 请按照此操作,在控制器中

public function microBitcoin()
{
$data['first'] = 'this is first';
$data['second'] = 'this is second';
$this->load->view('micro_btc', $data);
}

In view ,you can catch as like 看来,你可以抓住像

echo $first;
//it will print this is first
echo $second;
//it will print this is second

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM