API/Grid

From aMember Pro Documentation
Revision as of 08:30, 28 June 2011 by Alex (Talk | contribs)

Jump to: navigation, search

The grid component we developed from scratch provides very easy way to deal with table records - editing and displaying. There is a simple example of usage. You can save it to file AdminSampleBanController.php and copy to am/application/default/controllers/ , then access as http://example.com/am/admin-sample-ban

class AdminSampleBanController extends Am_Controller
{
    public function checkAdminPermissions(Admin $admin)
    {
        return $admin->isSuper();
    }
    function createGrid()
    {
        $ds = new Am_Query(BanTable::getInstance());
        $g = new Am_Grid_Editable('_ban', "Ban Records", $ds, $this->_request, $this->view);
        $g->setForm(array($this, 'createForm'));
        $g->addGridField("type", "Type");
        $g->addGridField("value", "Locked Value");
        $g->addGridField("comment", "Comment");
        return $g;
    }
    public function createForm(Am_Grid_Editable $grid)
    {
        $form = new Am_Form_Admin;
        $form->addSelect("type")->setLabel(array("Type")->loadOptions(array('ip'=>'IP', 'email'=>'E-Mail',));
        $form->addText("value", array('size' => 40))->setLabel(array("Value", "You can use % as wildcard mask"));
        $form->addText('comment', array('size' => 40))->setLabel("Comment");
        return $form;
    }
    public function indexAction()
    {
        $this->createGrid()->run($this->getResponse());
    }
}