Elgg\SystemMessagesService::addErrorMessage PHP Method

addErrorMessage() public method

Display an error on next page load.
public addErrorMessage ( string | string[] $error ) : void
$error string | string[] Error or errors to add
return void
    public function addErrorMessage($error)
    {
        $set = $this->loadRegisters();
        foreach ((array) $error as $str) {
            $set->error[] = $str;
        }
        $this->saveRegisters($set);
    }

Usage Example

Ejemplo n.º 1
0
 function testCanModifyRegisterSet()
 {
     $this->svc->addSuccessMessage(['s2', 's3']);
     $this->svc->addErrorMessage(['e1', 'e2', 'e3']);
     $set = $this->svc->loadRegisters();
     $this->assertEquals(['s2', 's3'], $set->success);
     $this->assertEquals(['e1', 'e2', 'e3'], $set->error);
     // will be filtered
     $set->success = ['', 's2'];
     $set->error = ['e1', false];
     $set->notice = ['n1', 'n2'];
     $set->invalid = true;
     $this->svc->saveRegisters($set);
     $this->assertEquals(['success' => ['s2']], $this->svc->dumpRegister('success'));
     $this->assertEquals(['error' => ['e1']], $this->svc->dumpRegister('error'));
     $this->assertEquals(['notice' => ['n1', 'n2']], $this->svc->dumpRegister());
 }