> > Topic (new)

pageHandle

Dec 14, 2006 / pixtur
Jan 5, 2009 / phsouzacruz
 

Attached files

No files uploaded
 

About Page handlesπ

For alot of reasons, streber organizes its interface into "pages". For each page you have to create a pageHandle in pages/_handles.php.

Example for a pageHandle definitions:

  new PageHandle(array('id'=>'projListClosed',
      'req'=>'pages/proj.inc',
      'title'=>__('Closed Projects'),
      'valid_params'=>array( 'from'=>'.*'
      ),
      'test'=>'yes',
  ));


types π

Additionaly you may use following pageHandle types to clarify the context of the page:
  • PageHandleFunc - for pages that the render another page (like change list sorting)
  • PageHandleForm - for full page forms
  • PageHandleSubm - for pages that submit formData and render another page

from handles π

Clarifying the context is usefull for unit-tests and for building links. E.g. if the target page is of type PageHandleFunc it's quiet possible the user want to return to the current page after the 'function' has been executed. That's why $PH->getLink() will add a from-handle to the url which refers to the current page and it's attributes. Read more about fromHandles.


parameters of pageHandles π

id π

Has to be a uniqe id. It should be camelCase and the parts of the name should be ordered "most important first". Id is also the name of a function defined in a page-include-file named in req.

Examples for ids:
  • projView
  • projEdit
  • projEditSubmit
  • home

req π

Specifies the resouce file in which the page function has to be defined.

The above example would call a function projListClosed() defined in pages/proj.inc

title π

On requesting a link to this page, the title is used as default name.

The title is defined as __('Closed Projects') because it should be translated. See translation guide for more information about translation.

for example the following code:

  echo $PH->getLink('projListClosed');

...would produce this html-output if current language is 'de' (German)

  <a href='index.php?go=projViewClosed'>Abgeschlossene Projekte</a>


The following codes would trigger errors:

  echo $PH->getLink('projListClossed'); # triggers warning 'undefined pagehandle'
  echo $PH->getLink('projDelete'); # triggers warning 'missing project-param'


valid_params π

Valid parameters and appropriate values as regular expression. Note: the regular expression is not evaluated yet.

for example:

   echo $PH->getLink('projListClosed',array('prj'=>'foo')); # triggers warning 'undefined page-parameter'

If no valid_params has been defined, params will NOT be checked. If required parameters have been defined, they are automatically added as valid_params.


required_params π

Required params to view this page.

for example when calling page defined as...

  new PageHandle(array('id'=>'projView',
      'req'=>'pages/proj.inc',
      'title'=>__('View Project'),
      'required_params'=>array( 'from'=>'.', 'prj'=>'d',
      ),
      'test'=>'yes',
  ));

...with this:

   echo $PH->getLink('projView',array('prj'=>'34')); # fine
   echo $PH->getLink('projView',array('proj'=>'34')); # triggers two warnings (undefined param and missing param 'prj')

test π

Page will be tested in automatic unit tests.


rights required π

If defined that pageHandler will check the user-rights of the current user and returns an empty string if validation fails. If the user requests this page directly and the check fails he will be forwarded to 'home' or 'login'

for example the page defined as...

   new PageHandleFunc(array('id'=>'companyNew',
       'req'=>'pages/company.inc',
       'title'=>__('New Company'),
       'rights_required'=>RIGHT_COMPANY_CREATE,
   
       'test'=>'yes',
   ));

will refuse to render a link if user has not enough rights:

   echo $PH->getLink('companyNew'); # returns if user has not enough rights
   

valid_for_anynymous π

Use this for pages that have to be visible even if the current user has no authentication.

for example:

  new PageHandleForm(array('id'=>'loginForm',
     'req'=>'pages/login.inc',
     'title'=>__('Login'),
     'valid_for_anonymous'=>true,
     'ignore_from_handles'=>true,
     'valid_params'=>array(),
  ));

ignore_for_handles π

This setting has been depreciated and should no longer be used.


No Comments