Building wizards using atkWizard
From Achievo/ATK Wiki
|
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.