In case you've missed it, you are looking at an older version of the website. Checkout our latest version, we promise you will love it 😍

getState

string getState()
Quick Description: Get the state string key according to the documentation.

We can see an example of how it works below:

Let's say we have our function employees_management . I have created two functions named getState and getStateInfo. getState will return a value from the array:

$states = array(
        0    => 'unknown',
        1    => 'list',
        2    => 'add',
        3    => 'edit',
        4    => 'delete',
        5    => 'insert',
        6    => 'update',
        7    => 'ajax_list',
        8    => 'ajax_list_info',
        9    => 'insert_validation',
        10    => 'update_validation',
        11    => 'upload_file',
        12    => 'delete_file',
        13    => 'ajax_relation',
        14    => 'ajax_relation_n_n',
        15    => 'success',
        16    => 'export',
        17    => 'print'
    );

So if you need for example to handle the State 'add' and 'edit' you will do:

 
function employees_management()
{
    $crud = new grocery_CRUD();
 
    $crud->set_theme('datatables');
    $crud->set_table('employees');
    $crud->set_relation('officeCode','offices','city');
    $crud->display_as('officeCode','Office City');
    $crud->set_subject('Employee');
 
    $output = $crud->render();
 
      $state = $crud->getState();
    $state_info = $crud->getStateInfo();
 
    if($state == 'add')
    {
        //Do your cool stuff here . You don't need any State info you are in add
    }
    elseif($state == 'edit')
    {
        $primary_key = $state_info->primary_key;
        //Do your awesome coding here. 
    }
    else
    {
        $this->_example_output($output);
    }
}