Jump to content

Message and error handling


LeiHa
 Share

Recommended Posts

I've been building message and error system.

And I've noticed that PW uses Jquery highlight message system, which is very easy to use.

Some of PW module do this like,

$this->message('message here');
$this->error('error message here');

And it seems like automatically generate markup for the Jquery to handle.(If I understand correctly)

So, are message and error methods only for use inside of class?

If I'm not getting it, please let me know.

Thank you.

Link to comment
Share on other sites

massage and error for admin no ? use them like this u can two

$pages->error('bad man');

$session->message('hi');

wire('pages')->error('bad bad.man');

wire('session')->message('hiho');

work.for any api vrable it does 

  • Like 4
Link to comment
Share on other sites

LeiHa,

You need to tell us more what you want to achieve.

In your modules, you can generate messages / error-messages like WillyC mentioned. Pw will output them automatically in the admin.

However, if you speak from your own templates aka frontend, I'm not sure what you want to do :)

Link to comment
Share on other sites

Sorry about the confusion.

I'm still trying to understand how to implement this in the frontend site.

The message system in admin backend site seems wonderful and I'd like to use it in the frontend.

At first, I thought that I could just use $this->error('some text'); or $this->message('some text'); in the frontend.

Eventually those didn't work of course. And tried to find out how to use this system(I assume Ryan made this. So impressive!!!)

Link to comment
Share on other sites

The notices system actually doesn't have anything to do with jQuery UI other than that the default admin theme makes use of jQuery UI class names when generating the markup for notices. But for your own front-end, you can make use of the $notices API variable to output them however you want. It can be as simple as this:

echo "<ul>";
foreach($notices as $notice) {
  $class = $notice->className();
  $text = $sanitizer->entities($notice->text); 
  echo "<li class='$class'>$text</li>";
}
echo "</ul>";

Then you would want to style the two type of notices in your CSS:

.NoticeMessage { color: green; }
.NoticeError { color: red; }
  • Like 9
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...