⚠ 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

Enter Default Values with Add & Update in Grocery CRUD



niketnaik
  • profile picture
  • Member

Posted 06 December 2018 - 05:28 AM

I am using Grocery CRUD for my project though i am currently new to Grocery CRUD and i am facing very basic problem with it. what i want is to add some default values when we add or update the data with CRUD. to understand better here is my table structure
 
ID(AI,PK) | Username | Password |CreatedAt|UpdatedAt|CreatedBy|UpdatedBy|

Above is the table structure where i am just entering the username and password, and CreatedAt|UpdatedAt|CreatedBy|UpdatedBy| will be added autometically.

here is my code to add the username and password

public function crudUsers()
{
$crud = new grocery_CRUD();

$crud->set_table("users");
$crud->set_subject("Website Users");

// Show in
$crud->add_fields(["username", "password"]);
$crud->edit_fields(["username", "password"]);
$crud->columns(["username", "password","CreatedAt","UpdatedAt","CreatedBy","UpdatedBy"]);


$data = (array) $crud->render();

$this->layout->set_wrapper( 'grocery', $data,'page', false);

$template_data['grocery_css'] = $data['css_files'];
$template_data['grocery_js'] = $data['js_files'];
$template_data["title"] = "Website Pages";
$template_data["crumb"] = ["table" => ""];
$this->layout->auth();
$this->layout->render('admin', $template_data); 
}

I have tried using https://www.grocerycrud.com/documentation/options_functions/callback_after_update this works but i don't find it is good approach to insert and update values again using query. Also the callbacks needs to be created for each and every functions i will use in future.

 

I like this and tried the code https://www.amitsgarage.com/knowledge-base/grocerycrud/default-values-for-add-form

This code gives the error at "$data->field_values = $this->get_add_values(null); " because this function is not there which is obvious.

I have tried other multiple options but can not able to find any good universal function which help me.

Any suggestions please?