Difference between revisions of "API/Core"

From aMember Pro Documentation
Jump to: navigation, search
(Created page with "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 loadi...")
 
m (Spelling, wording, grammar.)
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
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.
 
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'' withing amember/ folder. It does not output any page, just initialises the core.
+
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.
 
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 ===
+
== Directory layout ==
 
<pre>
 
<pre>
 
amember
 
amember
 
   application
 
   application
     configs/ - configuration files
+
     configs/             - configuration files
     default/ - default module
+
     default/             - default module
       controllers/ - controller files - it replaces usual PHP "pages". One controller usually represents one "traditional" PHP file
+
       controllers/       - controller files - it replaces usual PHP "pages". One controller usually represents one "traditional" PHP file
       language/ - translations
+
       language/           - translations
       models/   - models : each file represents one database file
+
       models/             - models : each file represents one database table. Contains successors to Am_Table and Am_Record classes
       plugins/
+
       plugins/          
         protect/ -  
+
         protect/         - integration plugins
         payment/
+
         payment/         - payment plugins
         misc/  
+
         misc/             - misc. plugins, for example google analytics integration plugin
       themes/
+
       themes/             - user-side themes
       themes-admin/
+
       themes-admin/       - admin-side themes
       views/
+
       views/             - templates, it is better to modify templates by creation of custom theme
       Bootstrap.php - module bootstrap file
+
       Bootstrap.php       - module bootstrap file
       db.xml       - database structure configuration file
+
       db.xml             - database structure configuration file
     newsletter/ - a "newsletter" module. Described here for example
+
     newsletter/           - a "newsletter" module. Described here for example
       controllers/ - newsletter module controllers. Accessible like http://www.example.com/am4/newsletter/subscribe
+
       controllers/       - newsletter module controllers. Accessible like http://www.example.com/am4/newsletter/subscribe
       library/     - newsletter module model classes and other libraries
+
       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
+
       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
+
         blocks/           - template "blocks" - small page pieces that can be included/excluded/shuffled via API
 
   data
 
   data
     cache/ - cache files
+
     cache/               - cache files
     new-rewrite/ - new-rewrite label files
+
     new-rewrite/         - new-rewrite marker files
   library - amember and third-party core libraries
+
   library                 - amember and third-party core libraries
   setup/ - setup folder
+
   setup/                 - setup folder
   bootstrap.php - initialize amember core
+
   bootstrap.php           - initialize amember core
   index.php - runs page controller and outputs content
+
   index.php               - runs page controller and outputs content
   js.php     - accelerator to pack all necessary JS libs to one file and deliver to client
+
   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
+
   public.php             - accelerator to provide quick access to custom files, specially configurable CSS files in themes
 
</pre>
 
</pre>
 +
 +
== How-to ==
 +
=== Create new "misc" plugin? ===
 +
* Create file: ''am/application/default/plugins/misc/sample.php''
 +
* Put the following code into:
 +
<source>
 +
<?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');
 +
    }
 +
}
 +
?>
 +
</source>

Latest revision as of 06:38, 19 September 2012

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');
    }
}
?>