I am using usercake to generate links to different permissions.
All works fine if I want hyperlinks, I added in an image bit and it broke the code, it will load but the entire address bar goes like there are no permissions.
Before:
//Links for permission level 3 (xx)
if ($loggedInUser->checkPermission(array(3))){
echo "<div id='xx'>
<ul>
<li><a href='xx.php'>xxx</a></li>
</ul></br ></div>";
}
After
//Links for permission level 3 (xx)
if ($loggedInUser->checkPermission(array(3))){
echo "<div id='xx'>
<ul>
<li><a href="xxx.php"><img src="xx"></a></li>
</ul></br ></div>";
}
It just makes the menu bar disappear.
Any ideas? Am I missing something obvious?
--update is it because I have not escaped properly?
" characters will terminate the string literal, and if you don't follow them with a concatenation operator (either . or ,), your code will throw a syntax error.
You need to escape them using \:
if ($loggedInUser->checkPermission(array(3))){
echo "<div id='xx'>
<ul>
<li><a href=\"xxx.php\"><img src=\"xx\"></a></li>
</ul></br ></div>";
}
Failing that, since you're not outputting any variable inside your string, you can use ' (single quotes) to begin and terminate the literal, which means you won't have to escape double quotes inside of it. For example:
if ($loggedInUser->checkPermission(array(3))){
echo '<div id="xx">
<ul>
<li><a href="xxx.php"><img src="xx"></a></li>
</ul></br ></div>';
}