Quick start guide
This guide will show you how to start developing with Tigermouse. Basic issues are explained:
- how to display a composite view
- how to define Ajax action
- how to write template
- how to do form validation
- how to update part of page
Once you have set up Tigermouse correctly you can immediately start writing your first
controller method. Tigermouse starts your application using MainCtrl controller class
and its show. Go to ctrl/ directory and start with the following code.
class MainCtrl extends Ctrl {
public function show() {
$form = new Form('quick_start');
$login = new Input('login');
$form->add($login);
$password = new Input('password');
$password->secret = true;
$form->add($password);
$ok = new Button('ok');
$ok->addListener(
new ClickListener(
new Action('MainCtrl/auth', $form->valueReader())
)
);
$form->add($ok);
return $form;
}
}
A form has been created and two input fields and button added to it. A listener has been configured
for button that will wait for mouse click event then server side action will be performed via Ajax call.
String 'MainCtrl/auth' means that method auth of class MainCtrl
will be called. This method needs to be written.
class MainCtrl extends Ctrl {
public function show() {
...
...
}
public function auth(FormContext $cx) {
$form = $this->show();
$form->clearError();
if (!$cx->login) {
$form->login->errorMessage('Enter your login, please');
return;
}
if (!$cx->password) {
$form->password->errorMessage('Enter your password, please');
return;
}
... // login procedure here
}
}
Form definition is retrieved from show method and previous error messages are removed.
FormContext object holds data posted by form and object properties are respective to
input fields names (e.g. $cx->login holds the data entered to 'login' input field).
Form fields are accessible as properties, too. Use form field identifier as property name to access it
(e.g. $form->login).
This is a working example of simple form, however it is not very pretty. Use external template
to organize form layout. Define $form->template property so it points to a template file.
class MainCtrl extends Ctrl {
public function show() {
$form = new Form('quick_start');
$form->template = 'LoginForm.tpl';
...
...
Save this template to view/LoginForm.tpl file.
<div id="{$id}">
login: {$login}
password: {$password}
{$ok}
</div>
Form elements identifiers has been used as Smarty variables.
The last thing to be shown in this Guide is how to replace/update page with Ajax call.
Login form will be replaced after user fills in (any) login name and (any) password.
auth method needs to be altered.
class MainCtrl extends Ctrl {
public function show() {
...
...
}
public function auth(FormContext $cx) {
$form = $this->show();
$form->clearError();
if (!$cx->login) {
$form->login->errorMessage('Enter your login, please');
return;
}
if (!$cx->password) {
$form->password->errorMessage('Enter your password, please');
return;
}
$l = new Label('quick_start');
$l->text = 'Hello ' . $cx->login;
return $l;
}
}
Login form is replaced with Hello message. The magic happens because both form and message
has the same identifier 'quick_start'. It is enough to return a view with existing identifier
to replace it.









