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!
views:
55answers:
4
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
2010-01-13 11:54:19
+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
2010-01-13 12:01:44
The PHP short tag -does- work in PHP 5.3+ you just need to enable it in php.ini
Zack
2010-01-13 15:15:08
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
2010-01-13 13:24:04