LemonStand Documentation

Using module access points

Module access points allow you to register special URLs which can be used for different tasks, for example for executing some module specific actions using cron jobs.

In order to register a module access point you need to override the register_access_points() method in the module information class. The module information class has been described in the Developing a simple module article. The register_access_points() method should return an array. Indexes (keys) of the array should match URLs you want to register. Slashes are not allowed in access point URLs. Array values should match the information class method names. Below is an example of the access point registration code.

public function register_access_points()
{
  return array(
    'blog_send_newspaper'=>'send_newspaper'
  );
}

The code registers a single access point with URL 'blog_send_newspaper'. If your website URL was http://my-site.com/ then the access point URL would be http://my-site.com/blog_send_newspaper.

According to the code example, the module information class should also have the send_newspaper() method definition. It should be a public class method with a single parameter:

public function send_newspaper($params)
{
  /*
   * Some newspaper sending code
   */
}

The method parameter is an array, which contains all parameters presented in the access point URL. For example, if the access point was invoked using the http://my-site.com/blog_send_newspaper/subscribers URL, the $params array would have a single element - 'subscribers'. You can use a many access point parameters as you need.

Access points are not actions and they have no corresponding view documents. You can use the echo() or print() function for outputting some status information.

Next: Handling LemonStand events
Previous: Programming module CMS actions
Return to Developing LemonStand modules

Comments

Silas

Thursday, September 15, 2011

Hey,
I have a page at the root of my site (example.com/page-url/) but I want to set up an access point so that when you go to example.com/page-url/123/ then my access point handles the output but if you go to example.com/page-url/ then the page handles it.
Also I wanted to know if there was a simple way to send the user to 404 when the url doesn't match anything.

Aleksey Bobkov

Thursday, September 15, 2011

@Silas - this is not supported. Access points should have unique addresses. However you can invoke custom code from your module right from your page. Inside your page code, check the parameter value, and if it is "123", invoke your module code.
To redirect to 404, just to Phpr::$response->redirect(root_url('/404'));

Add your comment

Loading form...