i've been working with CI for almost a year now and i could almost solve any problem i had.
but now i've run in to a wall with something that looks like parameter caching for views.
EXAMPLE
Controller method:
public function cache_test()
{
$data['dummy'] = "foobar";
$this->load->view('cache_view', $data); // should output "foobar"
unset($data['dummy']);
$this->load->view('cache_view', $data); // should output nothing
}
view:
<? if(isset($dummy)): ?>
<?= $dummy ?>
<? endif; ?>
result:
foobar foobar
i found a workaround where you have to set the variable to an empty string
$data['dummy'] = ""
and then make change the if to
if(isset($dummy) && $dummy != "")
but this doesnt seem very clean to me, and stuff like this bugs me :/
any help or pointers in the right direction are highly appreciated.
EDIT: i want to use this to load several items of a menu, where some of the view parameters are optional. these optional parameters then decide if i show some content in the view or not.
You can try following code , may be it will be solved your problem
public function cache_test()
{
$data['dummy'] = "foobar";
$this->load->view('cache_view', $data); // should output "foobar"
unset($data);
$this->load->view('cache_view', $data); // should output nothing
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.