API/Core

From aMember Pro Documentation
Jump to: navigation, search

aMember Pro v.4 is based on Zend Framework's Zend_Controller and follow its guidelines. There is a Bootstrap class that handles all the dependencies and configuration loading.

To get all aMember Pro functions available for your custom script, just include bootstrap.php within the amember/ folder. It does not output any page, just initialises the core.

aMember Pro uses .htaccess file in root folder to route requests to pages. It is done by using of Apache's mod_rewrite by redirecting all requests for not-image files to amember/index.php . index.php runs Zend_Controller_Front routing procedures to include necessary controller class and run it.


Directory layout

amember
  application
    configs/              - configuration files
    default/              - default module
      controllers/        - controller files - it replaces usual PHP "pages". One controller usually represents one "traditional" PHP file
      language/           - translations
      models/             - models : each file represents one database table. Contains successors to Am_Table and Am_Record classes
      plugins/            
        protect/          - integration plugins
        payment/          - payment plugins
        misc/             - misc. plugins, for example google analytics integration plugin
      themes/             - user-side themes
      themes-admin/       - admin-side themes
      views/              - templates, it is better to modify templates by creation of custom theme
      Bootstrap.php       - module bootstrap file
      db.xml              - database structure configuration file
    newsletter/           - a "newsletter" module. Described here for example
      controllers/        - newsletter module controllers. Accessible like http://www.example.com/am4/newsletter/subscribe
      library/            - newsletter module model classes and other libraries
      views/              - Zend_View templates for newsletter module. All "views" folders are merged to single view path, and module can provide its own version of existing templates
        blocks/           - template "blocks" - small page pieces that can be included/excluded/shuffled via API
  data
    cache/                - cache files
    new-rewrite/          - new-rewrite marker files
  library                 - amember and third-party core libraries
  setup/                  - setup folder
  bootstrap.php           - initialize amember core
  index.php               - runs page controller and outputs content
  js.php                  - accelerator to pack all necessary JS libs to one file and deliver to client
  public.php              - accelerator to provide quick access to custom files, specially configurable CSS files in themes

How-to

Create new "misc" plugin?

  • Create file: am/application/default/plugins/misc/sample.php
  • Put the following code into:
<?php 
class Am_Plugin_Samplename extends Am_Plugin
{
    public function isConfigured()
    {
        return (bool)$this->getConfig('vv');
    }
    function onSetupForms(Am_Event_SetupForms $forms)
    {
        $form = new Am_Form_Setup('sample');
        $form->setTitle("Sample Plugin");
        $forms->addForm($form);
        $form->addElement('text', 'vv')
             ->setLabel(array('Sample Plugin Config value'));
    }
    function onAfterRender(Am_Event_AfterRender $event)
    {
        $event->replace('(|</body>|i)', 'SAMPLE PLUGIN WORKING! ='.$this->getConfig('vv', 'but not configured - showing default').'=$1');
    }
}
?>