Formlar ve başarı çıktı

1 Cevap php

Eh,

It's a beginner's question but I really don't know what is the best way. I have a basic CRUD (Create, Retrieve, Update and Delete) in my project and I'd like to output some message if succeeded or not in a div inside the same page.

Yani, temelde, ben eylem aynı sayfa için ayarlanmış bir form var ve ben bir div #statusDiv I Register included with success gibi bir şey çıktı istiyorum bu aynı formda aşağıda var.

Bunu yapmak için en iyi yolu nedir?

  • Denetleyici bir bayrak kümesi $this->view->flagStatus = 'message' ardından görünümünde diyoruz?

Sadece daha net yapmak için. Bu benim kod:

//IndexController.php indexAction()

...

//Check if there's submitted data
if ($this->getRequest()->isPost()) {
    ...
    $registries->insert($data);
    $this->view->flagStatus = 'message';
}

Sonra benim görünümü:

....
<?php if ($this->flagStatus) { ?>   
    <div id="divStatus" class="success span-5" style="display: none;">
        <?php echo $this->flagStatus; ?>
    </div>
<?php } ?>
....

1 Cevap

Eğer yönlendiriliyorsunuz beri bu durumda, $ this-> görünüm-> flagStatus kaybolur. Bunun yerine ne kullanmalıyım FlashMessenger Eylem yardımcısıdır:

http://framework.zend.com/manual/en/zend.controller.actionhelpers.html

temelde değiştirmek istiyorum hariç sen, şu anda gibi kullanabilirsiniz:

$this->view->flagStatus = 'message';

karşı

$this->_helper->flashMessenger->addMessage('message');

after this you'll need karşı send the flashMessenger object karşı the view. You should do this in a place that gets executed on every page request so you can send messages karşı any page:

$this->view->flashMessenger = $this->_helper->flashMessenger;

and then change your view karşı:

<?php if($this->flashMessenger->hasMessages(): ?> 
    <div id="divStatus" class="success span-5" style="display: none;">
        <?php $messages = $this->flashMessenger->getMessages(); ?>
        <?php foreach($messages as $message): ?>
        <p><?= $message; ?></p>
        <?php endforeach; ?>
    </div>
<?php endif; ?>

Bu yardımcı olur umarım!