Building wizards using atkWizard: Difference between revisions
New page: {{howto|Easy|Maurice Maas <maurice@ibuildings.nl>}} ==Preface== AtkWizard is special controller (extends AtkController) which can help you to create a simple wizard. This wizard will... |
No edit summary |
||
| (2 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
{{howto| | {{howto|Advanced|[[Maurice Maas]]}} | ||
==Preface== | ==Preface== | ||
The [[atkWizard]] class is special controller (extends [[atkController]]) which can help you to create a simple wizard. This wizard will contain wizardpanels which are maped to an [[atkNode]]. First thing to keep in mind is that the atkWizard executes the actions directly after choosing to continue to the next wizardpanel. It will not collect actions up untill you finish. It won't even reverse actions automatically if you choose to cancel the wizard. | |||
==Wizard example== | ==Wizard example== | ||
| Line 12: | Line 12: | ||
Code: | Code: | ||
<syntaxhighlight lang="php"> | |||
atkimport("atk.wizard.atkwizard"); | atkimport("atk.wizard.atkwizard"); | ||
atkimport("atk.wizard.atkwizardpanel"); | atkimport("atk.wizard.atkwizardpanel"); | ||
| Line 45: | Line 45: | ||
} | } | ||
} | } | ||
</syntaxhighlight> | |||
Make an instance of atkWizardTest and start the wizard. Mind you that the atkWizard class extends atkController. | Make an instance of atkWizardTest and start the wizard. Mind you that the atkWizard class extends atkController. | ||
| Line 51: | Line 51: | ||
Code: | Code: | ||
<syntaxhighlight lang="php"> | |||
atkimport("atk.atkcontroller"); | atkimport("atk.atkcontroller"); | ||
$wizard = | $wizard = atkcontroller::createInstance("atkWizardTest"); | ||
$wizard->setMode(WIZARD_MODE_ADD); | $wizard->setMode(WIZARD_MODE_ADD); | ||
$wizard->handleRequest(); | $wizard->handleRequest(); | ||
</syntaxhighlight> | |||
==Output== | ==Output== | ||
If you are using the | If you are using the atkWizard in a default ATK application environment, the HTML will be outputted by atkOutput. The default handleRequest of atkController will do the following, where $screen is the HTML content: | ||
<syntaxhighlight lang="php"> | |||
$output = &atkOutput::getInstance(); | $output = &atkOutput::getInstance(); | ||
$output->output($screen); | $output->output($screen); | ||
</syntaxhighlight> | |||
When you are using the | When you are using the atkWizard from another environment and you don't want to use atkOutput to display the html. You could use the method setReturnOutput(boolean) to have the output returned to you be string, when calling the handleRequest method of atkWizard. You can use the method setPageFlags(flag) to influence the return output. You might not want a HEAD section of BODY tags returned, but only the wizardpanel form. | ||
Latest revision as of 09:57, 11 March 2011
|
ATK Howto: Building wizards using atkWizard
|
Preface
The atkWizard class is special controller (extends atkController) which can help you to create a simple wizard. This wizard will contain wizardpanels which are maped to an atkNode. First thing to keep in mind is that the atkWizard executes the actions directly after choosing to continue to the next wizardpanel. It will not collect actions up untill you finish. It won't even reverse actions automatically if you choose to cancel the wizard.
Wizard example
This wizard example will have two wizardpanels. First wizardpanel will show an add form of the atknode company.departement. The second wizardpanel will show an add form of company.employee. Both classes are not added in the example code.
Create a wizard class:
Code:
atkimport("atk.wizard.atkwizard");
atkimport("atk.wizard.atkwizardpanel");
atkimport("atk.utils.atkactionlistener");
class atkWizardTest extends atkWizard
{
function atkWizardTest()
{
$this->atkWizard();
$sitePanel = new atkWizardPanel($this, "Departement", "company.departement");
$sitePanel->addListener(new postAddListener());
$this->addPanel($sitePanel);
$this->addPanel(new atkWizardPanel($this, "Employee", "company.employee"));
}
}
class postAddListener extends atkActionListener
{
function postAddListener()
{
$this->atkActionListener(array("save"));
}
function actionPerformed($action, $record)
{
//do some processing
//eg save department_id in session and use
//it when adding employees
}
}
Make an instance of atkWizardTest and start the wizard. Mind you that the atkWizard class extends atkController.
Code:
atkimport("atk.atkcontroller");
$wizard = atkcontroller::createInstance("atkWizardTest");
$wizard->setMode(WIZARD_MODE_ADD);
$wizard->handleRequest();
Output
If you are using the atkWizard in a default ATK application environment, the HTML will be outputted by atkOutput. The default handleRequest of atkController will do the following, where $screen is the HTML content:
$output = &atkOutput::getInstance();
$output->output($screen);
When you are using the atkWizard from another environment and you don't want to use atkOutput to display the html. You could use the method setReturnOutput(boolean) to have the output returned to you be string, when calling the handleRequest method of atkWizard. You can use the method setPageFlags(flag) to influence the return output. You might not want a HEAD section of BODY tags returned, but only the wizardpanel form.