PHP Class View_CRUD, atk4

IMPORTANT NOTE: While you can disable adding and editing, if you do that you must simply use Grid!
Inheritance: extends View
Mostra file Open project: atk4/atk4 Class Usage Examples

Public Properties

Property Type Description
$add_button Button This points to a Button object, which you can change if you want a different label or anything else on it.
$allow_add boolean $this->add('CRUD', array('allow_add'=>false')); // to disable
$allow_del boolean $this->add('CRUD', array('allow_del'=>false')); // to disable
$allow_edit boolean $this->add('CRUD', array('allow_edit'=>false')); // to disable
$app App_Web
$entity_name string If you set this to 'false' then CRUD will not attempt to change default label ("Add")
$form Form IMPORTANT: check isEditing() method
$form_class string $this->add('CRUD', array('form_class'=>'MyForm'));
$form_options array $this->add('CRUD', array('form_options'=>array('js_widget'=>'ui.atk4_form')));
$frame_options array When clicking on EDIT or ADD the frameURL is used. If you want to pass some arguments to it, put your hash here.
$grid Grid IMPORTANT: check isEditing() method
$grid_class string $this->add('CRUD', array('grid_class'=>'MyGrid'));
$grid_options array $this->add('CRUD', array('grid_options'=>array('show_header'=>false)));
$id mixed This is set to ID of the model when are in editing mode. In theory this can also be 0, so use is_null().
$js_reload jQuery_Chain Contains reload javascript, used occassionally throughout the object.
$owner View
$virtual_page VirtualPage If isEditing() then you can add more stuff on this page, by calling virtual_page->getPage()->add('Hello!');

Public Methods

Method Description
addAction ( string $method_name, array $options = [] ) Assuming that your model contains a certain method, this allows you to create a frame which will pop you a new frame with a form representing model method arguments. Once the form is submitted, the action will be evaluated.
addButton ( string | array $label, string $class = 'Button' ) : Button Transparent method for adding buttons to a crud.
addFrame ( string $name, array $options = [] ) : Page | boolean Adds button to the crud, which opens a new frame and returns page to you. Add anything into the page as you see fit. The ID of the record will be inside $crud->id.
addRef ( string $name, array $options = [] ) : View_CRUD | null Assuming that your model has a $relation defined, this method will add a button into a separate column. When clicking, it will expand the grid and will present either another CRUD with related model contents (one to many) or a form preloaded with related model data (many to one).
formSubmitSuccess ( ) : jQuery_Chain Returns JavaScript action which should be executed on form successfull submission.
init ( )
isEditing ( string $mode = null ) : boolean Returns if CRUD is in editing mode or not. It's preferable over checking if($grid->form).
setModel ( string | Model $model, array $fields = null, array $grid_fields = null ) : AbstractModel Assign model to your CRUD and specify list of fields to use from model.

Protected Methods

Method Description
configureAdd ( array $fields = null ) : void | Model Configures necessary components when CRUD is in the adding mode.
configureDel ( ) Configures deleting functionality for grid.
configureEdit ( array $fields = null ) : void | Model Configures necessary components when CRUD is in the editing mode.
configureGrid ( array $fields ) Configures grid's model itself.
formSubmit ( Form $form ) Called after on post-init hook when form is submitted.

Method Details

addAction() public method

Assuming that your model contains a certain method, this allows you to create a frame which will pop you a new frame with a form representing model method arguments. Once the form is submitted, the action will be evaluated.
public addAction ( string $method_name, array $options = [] )
$method_name string
$options array

addButton() public method

Transparent method for adding buttons to a crud.
public addButton ( string | array $label, string $class = 'Button' ) : Button
$label string | array
$class string
return Button

addFrame() public method

The format of $options is the following: array ( 'title'=> 'Click Me' // Header for the column 'label'=> 'Click Me' // Text to put on the button 'icon' => 'click-me' // Icon for button )
public addFrame ( string $name, array $options = [] ) : Page | boolean
$name string Unique name, also button and title default
$options array Options
return Page | boolean Returns object if clicked on popup.

addRef() public method

Adds expander to the crud, which edits references under the specified name. Returns object of nested CRUD when active, or null The format of $options is the following: array ( 'view_class' => 'CRUD', // Which View to use inside expander 'view_options' => .. // Second arg when adding view. 'view_model' => model or callback // Use custom model for sub-View, by default ref($name) will be used 'fields' => array() // Used as second argument for setModel() 'extra_fields' => array() // Third arguments to setModel() used by CRUDs 'label'=> 'Click Me' // Label for a button inside a grid )
public addRef ( string $name, array $options = [] ) : View_CRUD | null
$name string Name of the reference. If you leave blank adds all
$options array Customizations, see above
return View_CRUD | null Returns crud object, when expanded page is rendered

configureAdd() protected method

Configures necessary components when CRUD is in the adding mode.
protected configureAdd ( array $fields = null ) : void | Model
$fields array List of fields for add form
return void | Model If model, then bail out, no greed needed

configureDel() protected method

Configures deleting functionality for grid.
protected configureDel ( )

configureEdit() protected method

Configures necessary components when CRUD is in the editing mode.
protected configureEdit ( array $fields = null ) : void | Model
$fields array List of fields for add form
return void | Model If model, then bail out, no greed needed

configureGrid() protected method

Configures grid's model itself.
protected configureGrid ( array $fields )
$fields array List of fields for grid

formSubmit() protected method

Called after on post-init hook when form is submitted.
protected formSubmit ( Form $form )
$form Form Form which was submitted

formSubmitSuccess() public method

Returns JavaScript action which should be executed on form successfull submission.
public formSubmitSuccess ( ) : jQuery_Chain
return jQuery_Chain to be executed on successful submit

init() public method

CRUD's init() will create either a grid or form, depending on isEditing(). You can then do the necessary changes after Note, that the form or grid will not be populated until you call setModel()
public init ( )

isEditing() public method

Returns if CRUD is in editing mode or not. It's preferable over checking if($grid->form).
public isEditing ( string $mode = null ) : boolean
$mode string Specify which editing mode you expect
return boolean true if editing.

setModel() public method

public setModel ( string | Model $model, array $fields = null, array $grid_fields = null ) : AbstractModel
$model string | Model Same as parent
$fields array Specify list of fields for form and grid
$grid_fields array Overide list of fields for the grid
return AbstractModel $model

Property Details

$add_button public_oe property

This points to a Button object, which you can change if you want a different label or anything else on it.
public Button $add_button
return Button

$allow_add public_oe property

$this->add('CRUD', array('allow_add'=>false')); // to disable
public bool $allow_add
return boolean

$allow_del public_oe property

$this->add('CRUD', array('allow_del'=>false')); // to disable
public bool $allow_del
return boolean

$allow_edit public_oe property

$this->add('CRUD', array('allow_edit'=>false')); // to disable
public bool $allow_edit
return boolean

$app public_oe property

public App_Web $app
return App_Web

$entity_name public_oe property

If you set this to 'false' then CRUD will not attempt to change default label ("Add")
public string $entity_name
return string

$form public_oe property

IMPORTANT: check isEditing() method
public Form $form
return Form

$form_class public_oe property

$this->add('CRUD', array('form_class'=>'MyForm'));
public string $form_class
return string

$form_options public_oe property

$this->add('CRUD', array('form_options'=>array('js_widget'=>'ui.atk4_form')));
public array $form_options
return array

$frame_options public_oe property

When clicking on EDIT or ADD the frameURL is used. If you want to pass some arguments to it, put your hash here.
public array $frame_options
return array

$grid public_oe property

IMPORTANT: check isEditing() method
public Grid $grid
return Grid

$grid_class public_oe property

$this->add('CRUD', array('grid_class'=>'MyGrid'));
public string $grid_class
return string

$grid_options public_oe property

$this->add('CRUD', array('grid_options'=>array('show_header'=>false)));
public array $grid_options
return array

$id public_oe property

This is set to ID of the model when are in editing mode. In theory this can also be 0, so use is_null().
public mixed $id
return mixed

$js_reload public_oe property

Contains reload javascript, used occassionally throughout the object.
public jQuery_Chain $js_reload
return jQuery_Chain

$owner public_oe property

public View $owner
return View

$virtual_page public_oe property

If isEditing() then you can add more stuff on this page, by calling virtual_page->getPage()->add('Hello!');
public VirtualPage $virtual_page
return VirtualPage