skip to Main Content

I integrate “Twitter Bootstrap” with my little CakePHP project, I have 2 questions:

1) There is a way to use the standards flash messages? (because after the integration the alerts are not working anymore)

2)How can I use this Js alert? (in vers 2.7 the flash messages were changed from

<?php $this->Session->setFlash("Flash Message");?>

to

<?php $this->Flash->success(__('Flash Message'));?>

and I can’t find the way to do that)

Thanks.

2

Answers


  1. FlashComponent provides far more flexibility than what Session->setFlash() does.

    Now you are not bound to a single method, but can implement as many different flash ‘magic’ methods as you wish.

    To be able to flash a custom flash message with

    $this->Flash->success(__('Flash Message'));?>
    

    You need to create an element in

    app/View/Elements/Flash/success.ctp
    

    with the appropriate HTML/javascript template.

    You have more information in the Cookbook 2.x: Setting Flash Messages

    Login or Signup to reply.
  2. // please include any jquery min js Create a file called success.ctp in app/View/Elements/ folder

    <div class="success_msg alert">
    <a href="#" class="close">x</a>
    <?php echo $message; ?>
    </div>
    
    // add css :- 
    .alert {
    
    border: 1px solid transparent;
    border-radius: 4px;
    margin-bottom: 20px;
    padding: 15px;}
    
    .success_msg {
    background-color: #dff0d8;
    border-color: #d6e9c6;
    color: #3c763d;}
    
    
    .close{   text-decoration :none;
     float: right;}
    
    
    
    // Add script :-
     $(document).ready(function(){
    
      $('#content .close').click(function(){
       $(this).parent().fadeOut();
       return false; });
    
    
      $('.alert').animate({opacity: 1.0}, 3000).fadeOut();
     });
    
    
    // Use this anywhere in your controller actions,
     $this->Session->setFlash('You have successfully logged   
             in','success');
    return $this->redirect(array('action' => 'index'));
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search