0

Having trouble with displaying my data from controller in 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

Severity: Notice

Message: Undefined variable: data

Filename: views/micro_btc.php

How I can display this variable in my View?

4 Answers 4

2

You have to use like this,

print_r($liczba_tweetow);

see this for more information

Sign up to request clarification or add additional context in comments.

18 Comments

When I use print_r($liczba_tweetow); its printing all my CI_Loader Objects. When I just echo variable echo $liczba_tweetow; I get Severity: 4096 Message: Object of class CI_Loader could not be converted to string Filename: views/micro_btc.php
you are assigning here $data['liczba_tweetow'] = $this->load->library('Twetterclass', $arr);, so you are getting that.
So what I supposted to do to display this data in View?
you are loading the library to variable, so its printing what ever is returned from library.
My library supposted to return only a single intiger. When I use print_r I get all of CI_Loader Objects. My library Twetterclass is working very well without framework, so I why I just can't get in return what I supposted to get? I get the error: Severity: 4096 Message: Object of class CI_Loader could not be converted to string Filename.
|
0
 <?php echo $liczba_tweetow; 
       print_r($liczba_tweetow);
  ?>

This is proper way to get data in view.

Reference

Comments

0

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']

Comments

0

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

1 Comment

Then I get another error: Severity: 4096 Message: Object of class CI_Loader could not be converted to string Filename: views/micro_btc.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.