$e["on_insert"] not working in cakephp 3

Questions$e["on_insert"] not working in cakephp 3
Anand asked 6 years ago

Hi Abu,

I have already posted some issues. Again I’m posting same issue here. I have used phpgrid in cakephp3. When i use $e[“on_insert”] = array(“add_record”, null, false);, it will return the some errors. Here I have posted error and code. please rectify this as soon as possible.

Following code will be wrote in controller.

<?php
namespace App\Controller;
use App\Controller\AppController;
use TimeConversion;
require_once(WWW_ROOT . ‘plugins’ . DS . ‘phpgrid’ . DS . ‘lib’ . DS . ‘inc’ . DS . ‘jqgrid_dist.php’);
use jqgrid;
class TransportsController extends AppController{

public function vehicleaddgrid()
{
$this->viewBuilder()->layout(‘gridlayout’);
$this->set(‘title_name’,’Subject’);
$db_conf = array();
$db_conf[“type”] = “Mysqli”; // db2 using odbc
$db_conf[“server”] = “localhost”;//192.168.2.8″; // System DSN
$db_conf[“user”] = “root”;
$db_conf[“password”] = “”;
$db_conf[“database”] = “muthusof_sru”;

$g = new jqgrid($db_conf);
$grid[“caption”] = “Add Main Vehicle”;
$grid[“width”]=1230;
$grid[“height”] = 410;
$grid[“rowList”] = array();
$grid[“rowNum”] = 17;
$grid[“add_options”] = array(‘width’=>’600’);
$grid[“edit_options”] = array(‘width’=>’600′);
$grid[“form”][“position”] = “top”;

$g->set_options($grid);

$g->select_command =’select *
from transportvehiclemaster’;
$g->table = “transportvehiclemaster”;

$col = array();
$col[“title”] = “Id”; // caption of column
$col[“name”] = “id”; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col[“editable”] = FALSE;
$col[“width”] = “10”;
$col[“hidden”] = false;
$col[“search”] = false;
$cols[] = $col;

$col = array();
$col[“title”] = “Vehicle No”; // caption of column
$col[“name”] = “vehicle_no”; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col[“editable”] = true;
$col[“width”] = “80”;
$col[“hidden”] = false;
$col[“search”] = true;
$cols[] = $col;

$col = array();
$col[“title”] = “Owner Name”; // caption of column
$col[“name”] = “vehicle_owne_name”; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col[“editable”] = true;
$col[“width”] = “80”;
$col[“hidden”] = false;
$col[“search”] = true;
$cols[] = $col;

$col = array();
$col[“title”] = “Purchase Date”; // caption of column
$col[“name”] = “purchase_date”; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col[“editable”] = true;
$col[“width”] = “80”;
$col[“hidden”] = false;
$col[“search”] = true;
$cols[] = $col;

$col = array();
$col[“title”] = “Registeration Date”; // caption of column
$col[“name”] = “registeration_date”; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col[“editable”] = true;
$col[“width”] = “80”;
$col[“hidden”] = false;
$col[“search”] = true;
$cols[] = $col;

$col = array();
$col[“title”] = “Vehicle Type”; // caption of column
$col[“name”] = “vehicle_type”; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col[“editable”] = true;
$col[“width”] = “80”;
$col[“hidden”] = false;
$col[“search”] = true;
$cols[] = $col;

$col = array();
$col[“title”] = “Modal”; // caption of column
$col[“name”] = “modal”; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col[“editable”] = true;
$col[“width”] = “80”;
$col[“hidden”] = false;
$col[“search”] = true;
$cols[] = $col;

$col = array();
$col[“title”] = “Make Year”; // caption of column
$col[“name”] = “make_year”; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col[“editable”] = true;
$col[“width”] = “80”;
$col[“hidden”] = false;
$col[“search”] = true;
$cols[] = $col;

$g->set_options($grid);

$g->set_actions(array(
“add”=>true, // allow/disallow add
“edit”=>true, // allow/disallow edit
“delete”=>false, // allow/disallow delete
“view”=>true, // allow/disallow view
“reloadgrid”=>true,
“rowactions”=>true, // show/hide row wise edit/del/save option
“export_excel”=>true, // export excel button
“export_pdf”=>true, // export pdf button
“export_csv”=>false, // export csv button // show/hide export to excel option
“autofilter” => true, // show/hide autofilter for search
“search” => “advance” // show/hide autofilter for search
)
);

//phpgrid_error($cols);exit;

$g->set_columns($cols);

$e[“on_insert”] = array(“add_record”, null, false);
$e[“on_update”] = array(“update_by”, null, false);

$g->set_events($e);
//phpgrid_error(add_record($data));

function add_record($data)
{
phpgrid_error(‘2’.$data);
global $g;
phpgrid_error(‘Sub Category Name Already Processed…’);
}

$out = $g->render(“list”);

$this->set(compact(‘out’));
}
}

Error:

Fatal Error (1): Call to undefined function App\Controller\add_record() in

Thanks

 

5 Answers
Abu Ghufran Staff answered 6 years ago

As these functions are class methods so you need to pass class name as well.

$e[“on_insert”] = array(“add_record”, “TransportsController”, false);
$e[“on_update”] = array(“update_by”, “TransportsController”, false);

3rd param to false will stop execution after callback and will ignore grid operations of insert/update.

https://www.phpgrid.org/support/questions/can-i-use-events-on-laravel5-5/

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Anand answered 6 years ago

Hi,

I tried this not showing that fatal error but on_input function not calling.

Abu Ghufran Staff answered 6 years ago

I tested cakephp3.7 and grid events. When mentioning class, you also need to provide complete namespace with class name.

Replace:

$e[“on_insert”] = array(“add_record”, “TransportsController”, false);

with:

$e[“on_insert”] = array(“add_record”, “App\Controller\TransportsController”, false);

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Anand answered 6 years ago

Hi Abu,

i tried this to but function not calling.

i checked error log getting error like this:

2019-05-15 12:20:48 Warning: Warning (2): call_user_func() expects parameter 1 to be a valid callback, class ‘App\Controller\IqacDepartmentevaluationsController’ does not have a method ‘add_record’ in [/var/www/html/webroot/plugins/phpgrid/lib/inc/jqgrid_dist.php, line 1644]

Abu Ghufran Staff answered 5 years ago

You need to replace add_record with the function callback (class method)

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

11 + 4 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?