Everyone can give a flash demo to show the message in temp file, thanks
|
Sep '15 |
5 |
1608 |
0 |
So I am using session flash messages.
In my bootstrap index.php
file, when defining services:
use Phalcon\Flash\Session as Flash;
$di = new \Phalcon\DI\FactoryDefault();
//Set up the flash service with classes from Zurb Foundation CSS framework
$di->set('flash', function() {
return new Flash(array(
'error' => 'alert-box warning',
'success' => 'alert-box success',
'notice' => 'alert-box info',
'warning' => 'alert-box warning',
));
});
//bla bla rest of bootstrap
In my controller:
$this->flash->error('WTF, some error occured!');
In my view:
<?php echo $this->getContent() ?>
<div class="row">
<div class="small-12 medium-12 large-12 columns">
<?php $this->flash->output(); ?>
</div>
</div>
Hmmm I don't understand what your problem really is. Let's say there are 10 messages stored by flash service.
What you want to do with them?
This is simply done by the code provided by me in my former post.
Controller:
$this->flash->error('WTF, some error occured!');
$this->flash->error('Another error!');
$this->flash->success('And one success!');
In your view:
echo $this->getContent();
$this->flash->output();
This way all messages will be generated. The code will produce:
<div data-alert class="alert-box warning">WTF, some error occured!</div>
<div data-alert class="alert-box warning">Another error!</div>
<div data-alert class="alert-box success">And one success!</div>
You can use method outputMessage (string $type, string $message)
described at the end of https://docs.phalcon.io/en/latest/api/Phalcon_Flash_Session.html. Or you can extend flash service and build your own.
Hi! I am beginner so my expertise is not huge. I have used such expression to highlight that this is completely diffirent topic than flash messages. I am using Zurb Foundation as a CSS framework in my project. Forms are described here.
I have made a base class for forms with a methods to render form elements. You can read this topic in the docs https://docs.phalcon.io/en/latest/reference/forms.html#rendering-forms
namespace Conradaek\Common\Library\Forms;
use Phalcon\Forms\Element\Text,
Phalcon\Forms\Element\Select;
class BaseForm extends \Phalcon\Forms\Form {
public function renderElement($field) {
//get a form element
$element = $this->get($field);
$message = $this->getMessagesFor($field)->offsetGet(0);
//add Zurb Foundation's error class to an element
if($message){
$element->setAttribute("class","error");
echo '<label class="error">';
}
else {
echo '<label>';
}
//prints label
echo $element->getLabel();
//prints element
echo $element;
echo '</label>';
if($message) {
echo '<small class="error">';
//Print a message
echo $message;
echo '</small>';
}
}
public function renderForm() {
//get form elements
$elements = $this->getElements();
//render all elements
foreach($elements as $i => $element) {
$this->renderElement($element->getName());
}
}
}