The thing to remember with the session object is that the currently logged in user’s details are available.
$session = new Session(); $session->user->GetId(); $session->user_usergroup->GetId();
AddMessage
function AddMessage($message='');
Add a Message object to the Messages array.
class ExampleController extends Controller
{
function MyAction()
{
// some actions etc
$this->session->AddMessage(new Message('success', "What ever you did ... it worked!"));
$this->Redirect();
}
}
PrintMessages
function PrintMessages($list_tag='', $list_css='', $item_tag='', $item_css);
Don’t include the delimiters in the tag name, just ‘li’ or ‘p’ is fine.
Usually this will get used on a list display page to report what the result of an action is, having used AddMessage(). So in the controller you might have something like this …
class ExampleController extends Controller
{
function MyAction()
{
// some actions etc
$this->session->AddMessage(new Message('success', "What ever you did ... it worked!"));
$this->Redirect();
}
}
Then in the template you will have a line that print out the messages in the session.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Example List Page</title>
</head>
<body>
<h1>Example List Page</h1>
<?=$this->session->PrintMessages()?>
<? $this->LoadComponent("PagingBar"); ?>
<ul>
<? foreach ($this->data as $thing) { ?>
<li><?=$thing->GetName()?></li>
<? } ?>
</ul>
<? $this->LoadComponent("PagingBar"); ?>
</body>
</html>
Tags: session class