View Alerts

Message is a component for displaying alerts in views rendered with Wolf Template. With it, it is possible to display a message of success, error or any other type of message. By default, this class is already instantiated in the Controller class.

NOTE: if you do not extend the Controller class, you will need to instantiate the Message class.

use Solital\Core\Resource\Message;

$message = new Message();

How to use

It is possible to create a new message like this:

/**
 * @return void
 */
public function generate(): void
{
    $this->message->new('msg.test', 'Just a test message displayed in the view!');
}

To retrieve this message, use the get method inside your controller.

/**
 * @return void
 */
public function home(): void
{
    echo $this->message->get('msg.test');
}

Using in Wolf Template

To make use of this component in Wolf, the method of creating the message is exactly the same. The code represents a practical and recommended method of retrieving the message.

<?php

namespace Solital\Components\Controller;

use Solital\Components\Controller\Controller;
use Solital\Core\Wolf\Wolf;

class UserController extends Controller
{
    /**
     * Construct
     */
    public function __construct()
    {
        parent::_construct();
    }

    /**
     * @return void
     */
    public function home(): void
    {
        Wolf::loadView('home', [
            'msg' => $this->message->get('msg.test')
        ]);
    }

    /**
     * @return void
     */
    public function generate(): void
    {
        $this->message->new('msg.test', 'Just a test message displayed in the view!');
    }

In your view, display the message this way:

<div>
    <?php if($msg): ?>
        <p><?= $msg ?></p>
    <?php endif; ?>
</div>

What to see next?


Built with MkDocs.