Am_Grid
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
<?php class AdminSampleBanController extends Am_Mvc_Controller { public function checkAdminPermissions(Admin $admin) { return $admin->isSuper(); }
function createGrid() { // create query to database table $ds = new Am_Query($this->getDi()->banTable); // inside controllers, plugins and tables, Am_Di instance is available with this method call: $this->getDi() // create grid with id, title, query, pass request and view $g = new Am_Grid_Editable('_ban', "Ban Records", $ds, $this->_request, $this->view); // set form creation callback for edit/add forms in grid $g->setForm(array($this, 'createForm')); // add fields to grid. @see Am_Grid_Field $g->addGridField("type", "Type"); $g->addGridField("value", "Locked Value"); $g->addGridField("comment", "Comment"); return $g; }
public function createForm(Am_Grid_Editable $grid) { // create admin-side form $form = new Am_Form_Admin; // add selection box with 2 options $form->addSelect("type")->setLabel(array("Type")->loadOptions(array('ip'=>'IP', 'email'=>'E-Mail',)); // add text field for "value" field of ban table $form->addText("value", array('size' => 40))->setLabel(array("Value", "You can use % as wildcard mask")); // add text field for "comment" field of ban table $form->addText('comment', array('size' => 40))->setLabel("Comment"); // buttons will be added by grid return $form; }
public function indexAction() { // now just run what we created before, and put grid output to response object of controller $this->createGrid()->run($this->getResponse()); } }Copyright © 2002–2026 www.amember.com. All Rights Reserved.