Difference between revisions of "API/Samples"
From aMember Pro Documentation
Line 48: | Line 48: | ||
} | } | ||
// if controller name has "admin" string inside, admin authentication will be automatically required | // if controller name has "admin" string inside, admin authentication will be automatically required | ||
− | class AdminPluginTestController extends | + | class AdminPluginTestController extends Am_Mvc_Controller // a Zend_Controller_Action successor |
{ | { | ||
// validate if given admin have access to this page, return false if it does not | // validate if given admin have access to this page, return false if it does not |
Revision as of 07:54, 7 May 2016
Create a simple plugin and run a sample query (note the plugin name matches filename)
application/default/plugins/misc/test.php
class Am_Plugin_Test extends Am_Plugin { function init() { $this->getDi()->db->selectRow("SELECT * FROM ?_user LIMIT 1"); // look at DbSimple docs } function onInvoiceStarted(Am_Event $event) // catches Am_Event::INVOICE_STARTED { $invoice = $event->getInvoice(); // Invoice object $user = $event->getUser(); // User object } }
Create a simple plugin that provides admin backend application/default/plugins/misc/test.php
class Am_Plugin_Test extends Am_Plugin { function init() { $router = Zend_Controller_Front::getInstance()->getRouter(); $router->addRoute('plugin-test-route', new Zend_Controller_Router_Route( 'admin-plugin-test', // your controller will be accessible as http://www.example.com/amember/admin-plugin-test array( 'module' => 'default', 'controller' => 'admin-plugin-test', // class name must be AdminPluginTestController (!) 'action' => 'index', // default action ) )); } function onAdminMenu(Am_Event $event) { $menu = $event->getMenu(); // Am_Navigation_Admin object $menu->addPage( array( 'id' => 'plugin-test-menuitem', 'controller' => 'admin-plugin-test', 'module' => 'default', 'label' => "Test Plugin Admin", ) ); } } // if controller name has "admin" string inside, admin authentication will be automatically required class AdminPluginTestController extends Am_Mvc_Controller // a Zend_Controller_Action successor { // validate if given admin have access to this page, return false if it does not public function checkAdminPermissions(Admin $admin) { return $admin->isSuper(); } function indexAction() { $this->view->title = "Test Admin Plugin"; $this->view->content = "I AM ALIVE!"; $this->view->display('admin/layout.phtml'); } }