How do I keep an item in a static controller part of the page?

1

It is the following, I have a project page that serves as the default for all the others, a Layout .. But I wanted to add an item (informative) to it, and it only stays on the homepage and CRUD of the informations, when goes to other pages that happens to the controller exchange, gives error and the informative ones disappear. Could anyone help ??

layout page:

<div class="col-md-8">
    <div id="c-slide" class="carousel slide auto panel">

        <div class="carousel-inner">
            <?php foreach ($informativos as $index => $informativo){ ?>

                <div class="item text-center<?php echo ($index === 0 ? " active" : "") ?>" style="width: 90%;margin-left:5%">
                    <div class="alert alert-block alert-<?php echo $informativo['Informativo']['tipo']; ?> fade in">                                    
                        <?php echo $informativo['Informativo']['texto']; ?>
                    </div>
                </div>                        

            <?php } ?>
        </div>
        <a data-slide="prev" href="#c-slide" class="left carousel-control">
            <i class="fa fa-angle-left"></i>
        </a>
        <a id="nextInformativo" data-slide="next" href="#c-slide" class="right carousel-control">
            <i class="fa fa-angle-right"></i>
        </a>
    </div>
</div>

App Controller:

public $helpers = array(
        'Gravatar.Gravatar',
        'Html', 
        'Form', 
        'Session'
);

public $components = array(
        'Auth' => array(
                'authenticate' => array('Saml.Saml')
        ),
        'Session',
        'Cookie');

var $uses = array('User');

public function beforeFilter() {
    parent::beforeFilter();     

    $this->set('convertTime', $this->convertTime);

    if ($this->Saml){
        if ($this->Saml->isAuthenticated()) {               
            $infoWSO2 = $this->Saml->getAttributes();

            if($this->Session->read('UsuarioLogado') == NULL){
                 $userSistema = $this->User->atualizaSessao($infoWSO2);

                 $this->Session->write('UsuarioLogado', $userSistema);
            }

            $this->set('login_user', $infoWSO2);
        }
    }
}
    
asked by anonymous 09.01.2015 / 18:35

1 answer

1

You should query the database in the AppController in more or less of this way:

public function beforeRender() {

    // sua query
    $query = array(
        'order' => array(
            ...
        ),
        'conditions' => array(
            ...
        ),
        'recursive' => 1
    );

    $data = $this->SeuModel->find('all', $query);
    $this->set(compact('data'));
}

So it will be available in all views.

It is not a practice considered correct, because you will have this query in all your controllers and actions, and may eventually cause a slow slowness in your application.

Correctly, you would save this data to a session, and query it in the view, so it would not impact the database.

    
09.01.2015 / 19:02