⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

How to replace "form_edit" title with a value from the current row ?



MiamMiam

MiamMiam
  • profile picture
  • Member

Posted 28 January 2014 - 10:31 AM

Hi,

 

I want to replace the form title "Edit User" with the name of the user.

I tried this, but it does not work :

public function test()
    {
      $crud = new grocery_CRUD();
      $crud->set_theme('datatables');
          $crud->set_table('users');
     $output = $crud->render();
     //
     $state = $crud->getState();
     $state_info = $crud->getStateInfo();
     $primary_key = $state_info->primary_key;
       if($state == 'edit')
        {
          $crud->set_lang_string('form_edit',$crud->$row->name);
        }
     $this->_example_output($output);       
    }

Thanks

 

 


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 29 January 2014 - 07:53 AM

Hi there,

 

Welll - will like u to suggest using

 

$info = $crud->getStateInfo();

$id = $info->primary_key;

.... here then u can retrieve the row and set the subject accordingly...


MiamMiam

MiamMiam
  • profile picture
  • Member

Posted 29 January 2014 - 15:09 PM

Hi Amit Shah

 

still I don't know how to get the value (newbie to OOP :blink: ) :

 

$crud->$row->name -> does not work

$crud->$row($id)->name -> does not work

 

Thanks


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 30 January 2014 - 07:55 AM

welll as i updated u the way... u need to retrieve the row / record from the table based on the id retrieved as below

 

$info = $crud->getStateInfo();

$id = $info->primary_key;

 

and then set the subject... thats the way!!


MiamMiam

MiamMiam
  • profile picture
  • Member

Posted 31 January 2014 - 08:38 AM

do you mean I need to perform a SELECT ?

 

Aren't the fields of the current row loaded somewhere during the "edit" state ?

 

What would be the precise php formula to retrieve a specific field ?

 

Thanks


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 05 February 2014 - 10:27 AM

Yes brother u need to select it from the database - cuz while in state of crud management - till the page is not rendered - there is no data being fetched from the backend. So you need to retrieve it from the table for the received primary key and use it as desired.


MiamMiam

MiamMiam
  • profile picture
  • Member

Posted 09 February 2014 - 10:49 AM

Thanks Amit Shah for this explanation. I could make it work !

 

Employees example : (check 'Firrelli Julie' at top left)

[attachment=762:replace_form_header_with_value.png]

       public function employees_show_name()
    {
        $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(''); // ============================ must be empty not to appear in form header
        //
        $crud->columns('lastName','firstName','email','officeCode','country_office');
        //
        // ================= Workaround to show the name of the employee in the header of the form (in edit mode)
        $crud_mode = $crud->getState();// Get state
        $infos = $crud->getStateInfo();
           if ($crud_mode == 'edit') {
            $fields = $this->_get_fields($infos->primary_key);
               $crud->set_lang_string('form_edit',$fields->lastName . " " . $fields->firstName);// The name takes place of the GC message
        }
        // ================ End of workaround
        //    
        $crud->required_fields('lastName');
        $crud->set_field_upload('file_url','assets/uploads/files');

        $output = $crud->render();
        $this->_example_output($output);
    }
     // Required function to make it work
    protected function _get_fields($id_employee)
    {
        $select = "SELECT * FROM employees WHERE employeeNumber=$id_employee";
        $query = $this->db->query($select);
        if ($query->num_rows() == 1) {
            return $query->row();
        } else {
            return null;
        }
    }  

The first name and the last name are displayed in the header of the form instead of "Edit Employee".

 

Ciao


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 10 February 2014 - 05:49 AM

My pleasure ...

Happy to Help :)