wait

Tigermouse AJAX framework for PHP

Tigermouse - AJAX framework for PHP
login password or
search
english polski español français
about
news about publicity rss
demo
5 minutes tour live demo screencast demo other frameworks
getting started
faq download and installation quick start guide user documentation on-line help channel
getting involved
mailing lists developer documentation development guidelines upgrade assistant
the goal
Our goal is to develop high quality web applications framework for PHP and AJAX. We follow the best practices of software engineering to provide reliable, ready for changes and easily maintainable solution.
did you know?
Employ Translation classes to automate data conversion between Model and View. Use WikiTranslator to convert Wiki formatting to HTML.
technology
PHP Smarty Sourceforge JSON AJAX Tigermouse

Quick start guide

This guide will show you how to start developing with Tigermouse. Basic issues are explained:

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.