Hey I’m new to php and codeigniter. I know that in codeigniter’s view you can echo a variable like
<?php echo $var ?>
but if say, I don’t pass the variable $var, I get a nasty
<h4>A PHP Error was encountered</h4>
in my html source code. I’ve worked with django before an in their template, if the variable doesn’t exist, they simply don’t render it. Is there a way in php/codeigniter to say ‘if $var exists do smthing else do nothing’ ?
I tried:
<?php if($title): ?>
<?php echo $title ?>
<?php endif; ?>
but that was an error. Thanks!
Use the
isset()function to test if a variable has been declared.Use the
empty()function to test if a variable has no content such asNULL, "", false or 0.