2010-07-13 3 views
2

Comment puis-je cacher notre navigation principale et l'utiliser comme page d'accueil, mais uniquement pour les utilisateurs connectés?En utilisant CakePHP, comment cacher certains éléments d'une page d'un utilisateur s'ils sont connectés?

Voici le code du diaporama. Le MENU est un élément cependant. Devraient-ils tous deux être dans le fichier d'élément ensemble? Avant de tenter de me cacher une fois connecté? Fichier /elements/nb_menu_home.ctp lit comme suit:.

<script src="/js/loopedslider.js" type="text/javascript" charset="utf-8"></script> 

<div id="loopedSlider"> <!--Beginning of slideshow--> 
    <div class="container"> 
     <?php $session->flash(); ?> 
      <div class="slides"> 
       <div id="slide_one" class="bg"><!--slide #1--> 
        <div class="slide-content"> 
         <div class="nhome"> 
          <div class="nhhleft"> 
           Borrow a car for the weekend, textbooks, and other stuff you need from other students. Free or super cheap! <br /> 
           Save money and resources @ USAFA.<br /> 
           All users and transactions "Validated by REPIFY" <br /> 
           <strong></strong> 

           <br clear="all" /> 
           <iframe src="http://www.facebook.com/plugins/like.php?href=www.neighborrow.com&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height: 30px; text-align: center;margin-top: 20px;"></iframe> 
           <br /> 
           <?= $form->create('Item', array('action' => 'indextest')); ?> 
          </div> 

          <div id="nhhright"> 
           <img src="/images/items/cars.jpg" border="0" width="90" height="90">Cars<a href="#more">View more</a> 
           <br/> 
           <img src="/images/items/games electronics.jpg" border="0" width="90" height="90">games electronics<a href="#more">View more</a> 
           <br/> 
           <img src="/images/items/textbooks.jpg" border="0" width="90" height="90">textbooks<a href="#more">View more</a> 
           <img src="/images/items/gear.jpg" border="0" width="90" height="90">outdoor gear and uniforms<a href="#more">View more</a> 
          </div> 

          <div id="captureBlock"> 
           <div id="index_headertop"><text><strong><!--Request Item--></strong></text> 
            <div id="index_close" onclick="divToggle('captureBlock');divToggle('fadedbg');"><img src="/images/Index_close.jpg"> 
            </div> 
           </div> 

           <div id="index_capturecontent"> 
            <div id="index_logoheader"><br/><img src="/images/index_pupupheader.png"></div> 
            <br/> 

            <div id="indexinput_email"> 
              <strong><text>Please Enter Your E-Mail To Continue</text></strong> 
              <?= $form->input('User.emailindex', array('label' => ' ')); ?> 
              <br/> 
              <input type="image" src="/images/index_continue.jpg" /> 
            </div> 
           </div> 
          </div> 

          <!-- <div id="index_searchblock"> 
             <div id="index_search"> 
              <?= $form->input('Item.itemindex',array('label'=>'')); ?> 
              <?= $form->end(); ?> 

              <?= $form->create('user', array('action' => 'login')); ?> 
              <?= $form->input('session.have',array('label'=>''));?> 
             </div> 

             <div id="index_listButton" style="cursor: pointer;"><input type="image" src="/images/listbutton.png" /></div> 
             <?= $form->end(); ?> 
             <div id="index_requestButton" onclick="divToggle('captureBlock');divToggle('fadedbg');" style="cursor: pointer;"></div> 
            </div>--> 
         </div><!-- capture block ends here --> 
        </div> 
       </div><!--end of slide #1--> 

       <div id="slide_two" class="bg"><!--slide #2--> 
        <div class="slide-content"> 
         <div class="nhhleft"> 
           </a> 
           (1) Click on the item you want <br /> 
            (2) Tell us when you want it<br /> 
            (3) Provide your email address for confirmation and REPIFY<br /> 
            (4) Use and return<br /> 
           <iframe src="http://www.facebook.com/plugins/like.php?href=www.neighborrow.com&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height: 30px; text-align: center;margin-top: 20px;"></iframe> 
           <br clear="all" /> 
         </div> 

         <div id="nhhright"> 
          <br clear="all" /> 
         </div> 
        </div><!-- SLIDE CONTENT ENDS HERE--> 
       </div><!--end of slide #2--> 

       <div id="slide_three" class="bg"><!--slide #3--> 
        <div class="slide-content"> 
         <div class="nhhleft"> 
           <br /><br />SAVE Money, Time, Space, the Earth<br/> 
           MAKE Money, Friends, Space, a Difference 
           <br /><br /> 
           <iframe src="http://www.facebook.com/plugins/like.php?href=www.neighborrow.com&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height: 30px; text-align: center;margin-top: 20px;"></iframe> 
           <br clear="all" /> 
         </div> 
         <div id="nhhright"> 
          <br clear="all" /> 
          <br/><br/><br/> 
          <img src="/images/save.gif"><br /><img src="/images/make.gif"> 
         </div> 
        </div><!-- SLIDE CONTENT ENDS HERE--> 
       </div><!--end of slide #3--> 

       <div id="slide_four" class="bg"><!--slide #4--> 
        <div class="slide-content"> 
         <div class="nhhleft"> 
          USAFA!!! 
          <br> 
          If you want to bring us to another school <?= $html->link('contact us', '/contact'); ?> 
          <br /><br /> 
          <iframe src="http://www.facebook.com/plugins/like.php?href=www.neighborrow.com&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height: 30px; text-align: center;margin-top: 20px;"></iframe> 
           <br clear="all" /> 
         </div> 

         <div id="nhhright"> 
          <img src="/images/skyline_3.jpg" /> 
         </div> 
        </div><!-- SLIDE CONTENT ENDS HERE--> 
       </div><!--end of slide #4--> 

       <div id="slide_five" class="bg"><!--slide #5--> 
        <div class="slide-content"> 
         <div class="nhhleft"> 
           <br /><br />LOCAL AND NATIONAL MEDIA!<br /> 
           <iframe src="http://www.facebook.com/plugins/like.php?href=www.neighborrow.com&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height: 30px; text-align: center;margin-top: 20px;"></iframe> 
           <br clear="all" /> 
         </div> 

         <div id="nhhright"> 
          <br clear="all" /> 
           <br/><br/><br/> 
           <a href="http://www.myfoxny.com/dpp/good_day_ny/tech_it_out/091002_neighborrow_tech_it_out" target="_blank"><img src="http://www.beta.neighborrow.com/images/nbmedia/fox.png" border="0" alt="Fox News" /></a> 
           <a href="http://www.msnbc.msn.com/id/15484490/"><img src="http://www.beta.neighborrow.com/images/nbmedia/msn.png" border="0" alt="MSNBC" /></a> 
           <a href="http://www.thrillist.com/new-york/neighborrow"><img src="http://www.beta.neighborrow.com/images/nbmedia/thrillist.png" border="0" alt="thrillist" /></a> 
           <a href="http://online.wsj.com/article/SB121322069979265767.html?mod=RealEstateMain_1"><img src="http://www.beta.neighborrow.com/images/nbmedia/wsj.png" border="0" alt="WSJ" /></a> 
           <br/> 
           <a href="http://www.msnbc.msn.com/id/21134540/vp/27160813#27160813"><img src="http://www.beta.neighborrow.com/images/nbmedia/today.png" border="0" alt="Today" /></a> 
           <a href="http://www.wnbc.com/news/16765259/detail.html"><img src="http://www.beta.neighborrow.com/images/nbmedia/wnbc.png" border="0" alt="WNBC" /></a> 
           <a href="http://159.54.226.237/08_issues/080601/080601thinksmart-vinegar-lighthouse-trade.html"><img src="http://www.beta.neighborrow.com/images/nbmedia/usa.png" border="0" alt="USA" /></a> 
           <a href="http://www.nydailynews.com/money/2008/07/08/2008-07-08_borrow_items_from_neighbors_through_new_.html"><img src="http://www.beta.neighborrow.com/images/nbmedia/dailynews.png" border="0" alt="Daily News" /></a> 
          </center> 
         </div> 
        </div><!-- SLIDE CONTENT ENDS HERE--> 
       </div><!--end of slide #5--> 
      </div> 

      <?php print $this->element('nbmenu_home'); ?> 
     </div> 
    </div> 

    <script type="text/javascript" charset="utf-8"> 
     $(function(){ 
      $('#loopedSlider').loopedSlider({ 
       }); 
     }); 
    </script> 

Répondre

2

Comme Anders, j'utilise beforeRender, mais je le couple avec ACL. Voici un fragment du code que j'utilise:

function beforeRender() 
{ 
    if($this->layout=='admin') 
    { 
     $user = ($this->Auth->user())?$this->Auth->user():array('User'=>array(
           'username' => 'anonymous', 
           'group_id' => null 
           )); 
     if(!$user['User']['group_id']) $this->redirect('/'); 
     $usersIndexAllowed = $this->Acl->check($user,"users/index"); 
    } 
    $this->set(compact('user','usersIndexAllowed','configureAllowed','moduleTypesAllowed')); 
} 

Vous pouvez ensuite utiliser conditionals dans la vue de cacher ou de blocs d'affichage HTML.

+0

remercie tout le monde – adam

1

Une méthode est d'avoir vos éléments vérifier si l'utilisateur est connecté

Alternativement, ont la vue le faire vérifier avant d'inclure l'élément.

+0

Y at-il une ressource pour voir exactement quel code utiliser pour vérifier si connecté et lui dire de ne pas afficher si elles sont? en vue – adam

+0

Voir la réponse de Anders S. Oui, il y en a. Essayez également de lire la documentation de Cake. C'est très utile. – Kalium

+0

yup été lu récemment - difficile d'obtenir le code dans les bons endroits même quand je comprends les relations et la puissance etc ... continuera à lire :) désolé si c'est une question de devoirs ... – adam

6

Vous pourriez faire quelque chose comme ça dans votre app_controller.php:

function beforeRender() 
{ 
    if($this->Session->read('Auth.User')) 
    { 
     $this->set('loggedIn', true); 
    } 
} 

Et vérifier $loggedIn dans votre vue.

+3

Ou simplement 'if ($ session-> read ('Auth.User'))' dans la vue. Pas besoin de pepper votre vue avec des variables supplémentaires et votre contrôleur avec plus de code. – deceze

Questions connexes