Difference between revisions of "API/Grid"

From aMember Pro Documentation
Jump to: navigation, search
(Created page with "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 fi...")
 
Line 8: Line 8:
 
         return $admin->isSuper();
 
         return $admin->isSuper();
 
     }
 
     }
 
+
     function createGrid()
     function createGrid($id, $title)
+
 
     {
 
     {
 
         $ds = new Am_Query(BanTable::getInstance());
 
         $ds = new Am_Query(BanTable::getInstance());
         $g = new Am_Grid_Editable('_'.$id, "Ban Records", $ds, $this->_request, $this->view);
+
         $g = new Am_Grid_Editable('_ban', "Ban Records", $ds, $this->_request, $this->view);
 
         $g->setForm(array($this, 'createForm'));
 
         $g->setForm(array($this, 'createForm'));
 
         $g->addGridField("type", "Type");
 
         $g->addGridField("type", "Type");

Revision as of 08:30, 28 June 2011

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());
    }
}