views:

55

answers:

4

Help, this is my first Codeigniter app and I am having the strangest problem, the View is not getting the values of the variables from the database. I followed this tutorial, and instead, when I load the page, the values from the foreach loop show like this $value instead of displaying the actual contents in the database. I'm confused!

A: 

Using my divination powers, I'd say either:

  • your webserver is not configured to serve PHP
  • you forgot to put $value inside of an PHP block

For better answers, provide some of your code and the link to the tutorial.

Gordon
+1  A: 

I guess in your view you should have something like:

<?php foreach ($data as $value): ?>
    <?php echo $value; ?>
<?php endforeach; ?>

From your question it sounds like the foreach part is working, so maybe inside the foreach you are putting something like this instead:

$value

or

<?php echo '$value'; ?>

Both will just print out the literal $value without treating it as a variable. It also could be that you are using short tags (i.e. <?= and <?) which may not be enabled in your PHP configuration.

Tom Haigh
A: 

might be u r using <? as start tag thats not work with php5.3.

neverSayNo
The PHP short tag -does- work in PHP 5.3+ you just need to enable it in php.ini
Zack
A: 

Hi! All variables are extracted when passing data to a view in CI. That means in practice:

Controller:

$data['myvar'] = 'Contents';
$data['myothervar'] = 'Contents 2';
$this->load->view('viewname', $data);

View:

<?=$myvar;?>

Do you see the pattern?

Industrial