views:

51

answers:

2

The example I have in HTML:

<div id="red-nav-warp">
  <ul id="red-nav-logo">
    <li><img class="sponsors" id="sponsorone" src="media/img/logosmall.png" /></li>
  </ul>
  <ul class="clearfix" id="red-nav-list-member" >
    <li><?php $themeSys->Href('logout',$langSys->get('LOGOUT')); ?></li>
    <li><?php $themeSys->Href('settings',$langSys->get('SETTINGS')); ?></li>
  </ul>    
  <ul class="clearfix" id="red-nav-list" >
    <li><?php $themeSys->Href('home',$langSys->get('HOME')); ?></li>
    <li><?php $themeSys->Href('why',$langSys->get('WHY')); ?></li>
    <li><?php $themeSys->Href('register',$langSys->get('REGISTER')); ?></a></li>
    <li><?php $themeSys->Href('account',$langSys->get('MEMBER')); ?></a></li>
    <li><?php $themeSys->Href('community',$langSys->get('COMMUNITY')); ?></a></li>
    <li><?php $themeSys->Href('blog',$langSys->get('BLOG')); ?></a></li>
    <li><?php $themeSys->Href('partners',$langSys->get('PARTNERS')); ?></a></li>
  </ul> 

  <div class="clearfix"></div>    
</div><!-- END red-nav-warp -->

What I just want to show is a portion of HTML if he is a logged in user.

<div id="red-nav-warp">
  <ul id="red-nav-logo">
    <li><img class="sponsors" id="sponsorone" src="media/img/logosmall.png" /></li>
  </ul>

  <!-- hidden or no output -->  
  <ul class="clearfix" id="red-nav-list" >
    <li><?php $themeSys->Href('home',$langSys->get('HOME')); ?></li>
    <li><?php $themeSys->Href('why',$langSys->get('WHY')); ?></li>
    <li><?php $themeSys->Href('register',$langSys->get('REGISTER')); ?></a></li>
    <li><?php $themeSys->Href('account',$langSys->get('MEMBER')); ?></a></li>
    <li><?php $themeSys->Href('community',$langSys->get('COMMUNITY')); ?></a></li>
    <li><?php $themeSys->Href('blog',$langSys->get('BLOG')); ?></a></li>
    <li><?php $themeSys->Href('partners',$langSys->get('PARTNERS')); ?></a></li>
  </ul> 

  <div class="clearfix"></div>    
</div><!-- END red-nav-warp -->

Anyone have an idea or a example class that can hide things so that I can write it like ( better an class if it's possible.)

<div id="red-nav-warp">
  <ul id="red-nav-logo">
    <li><img class="sponsors" id="sponsorone" src="media/img/logosmall.png" /></li>
   </ul>
   <?php $hideSys->hiddenbelow(); ?> <!-- some hide class or some magic -->
   <ul class="clearfix" id="red-nav-list-member" >
     <li><?php $themeSys->Href('logout',$langSys->get('LOGOUT')); ?></li>
     <li><?php $themeSys->Href('settings',$langSys->get('SETTINGS')); ?></li>
   </ul>
   <?php $hideSys->stop(); ?> <!-- end some hide class or some magic -->   
   <ul class="clearfix" id="red-nav-list" >
     <li><?php $themeSys->Href('home',$langSys->get('HOME')); ?></li>
     <li><?php $themeSys->Href('why',$langSys->get('WHY')); ?></li>
     <li><?php $themeSys->Href('register',$langSys->get('REGISTER')); ?></a></li>
     <li><?php $themeSys->Href('account',$langSys->get('MEMBER')); ?></a></li>
     <li><?php $themeSys->Href('community',$langSys->get('COMMUNITY')); ?></a></li>
     <li><?php $themeSys->Href('blog',$langSys->get('BLOG')); ?></a></li>
     <li><?php $themeSys->Href('partners',$langSys->get('PARTNERS')); ?></a></li>
   </ul> 

   <div class="clearfix"></div>    
</div><!-- END red-nav-warp -->

What I have done, and yes I know it's an epic fail at least I'm trying :)

<?php  
/**
* TRYING TO HIDE SOME PART OF HTML
* useing if $_Session['login'] = true;
*/
class Hideing
{
  function __construct()
  {

  }

  function hiddenbelow()
  {
    return "if($_Session['login']){"; // epic fail
  }

  function stop()
  {
    return "}";
  }
}

$hideSys = new Hideing;
?>

Thanks for looking in,

Adam Ramadhan

A: 

wrap the code you want to hide with:

<?php if ($_SESSION['login']): ?>
<!-- code goes here -->
<?php endif; ?>
blob8108
+1  A: 

Your code just returns a string. PHP will not execute it automatically.

You need to do

 </ul>
 <?php if($_Session['login']) { ?> <!-- some hide class or some magic -->
 <ul class="clearfix" id="red-nav-list-member" >
  <li><?php $themeSys->Href('logout',$langSys->get('LOGOUT')); ?></li>
  <li><?php $themeSys->Href('settings',$langSys->get('SETTINGS')); ?></li>
 </ul>
 <?php } ?> <!-- end some hide class or some magic -->   
 <ul class="clearfix" id="red-nav-list" >

You may have read about the wisdom of seperating Model View and Controller logic and want to encapsulate that logic into a class, but you still need ifs in the PHP code.

 </ul>
 <?php if($hideSys->isLoggedIn()) { ?> <!-- some hide class or some magic -->
 <ul class="clearfix" id="red-nav-list-member" >
  <li><?php $themeSys->Href('logout',$langSys->get('LOGOUT')); ?></li>
  <li><?php $themeSys->Href('settings',$langSys->get('SETTINGS')); ?></li>
 </ul>
 <?php } ?> <!-- end some hide class or some magic -->   
 <ul class="clearfix" id="red-nav-list" >

Where the isLoggedIn() method returns a Boolean true or false variable.

James
how a bout makeing it a class james? or its better this way ?
Adam Ramadhan
@Adam: there are other ways, but if you want to keep if all in one file, and not refactor your whole system, this one would be most readable to other coders, and it does the job well.
Wrikken
Personally I always try to separate my code into Model View Presentation layers. You'll find lots on that online. But anyway, you definitely want that code in a class or function, because you don't want to repeat code - repeated code makes it hard to change things later. And I'm sure isLoggedIn() will be a frequently used check.
James
@wrikken - disagree. Putting logic directly into your presentation layer makes for a hard to test, hard to change and hard to understand system. A nice model layer with clear interfaces is great. Of course, if it's a small one-page simple system maybe that's over the top - but I'm guessing any system with logins is not such a system.
James
Sorry, I keep putting in "login" when I mean "logic" - agghhh
James
well i think there is no other way then inserting an if :)
Adam Ramadhan
Yes, you definitely need an if. Sorry, I'm jumping straight from one topic to another and it's probably a bit confusing.
James