Topics

Application

Application object is the main object of ImpressPages core which initializes the application and handles the request. It is used in index.php file and should rarely be used in a controller or anywhere else unless you would like to execute a sub request. It's methods can be accessed using ipApplication() function.

Request execution flow

On each page request application executes the following flow of events, filters and jobs. In 99% of the cases you will use ipBeforeController event and ipSendResponse filter. The rest are implemented just to make the system infinitely flexible.

Type Name Comment
Job ipRouteLanguage Used to find out the language of a current request. It should be used only if you would like to change the way multilingual URL's are handled on ImpressPages or so.
Event ipInitFinished Fired as soon as main ImpressPages components are up (autoloader, translations, events, filter, jobs, etc.) 
Job ipRouteAction Used to find out current controller and action to be executed. It should be used only if you want to implement your own router or so.
Job ipDefaultPageId Used to find out the default Page ID if the root of the website is accessed. May not be executed in some scenarios.
Event ipBeforeController The most common event do actions on your plugin. On this event, you can add CSS or JS to the page, collect stats, etc.
Job ipExecuteController Used to execute the controller. Use it only if you want to change the way controller action is being executed
Filter ipSendResponse

Use this filter to modify the response just before it is being send. You can also replace existing response object with yours. Use it to

  • restrict access to particular pages
  • add additional headers
  • replace placeholders in the content
Event ipBeforeResponseSent Response has been sent to the client.
Event ipBeforeApplicationClosed Do any actions you need before the database connection will be closed.

HMVC (Hierarchical Model–View–Controller)

You can use ipApplication()->handleRequest() method to call MVC controller directly from within your code. 

<?php
    $request = new \Ip\Request();
    $request->setQuery(
        array(
            'pa' => 'MyPlugin.index', // 'pa' key means public controller.
            // A value contains a plugin name 'MyPlugin' and action name 'index'.
    ));
    $answer = ipApplication()->handleRequest($request)->getContent();
comments powered by Disqus