Can I use Events on Laravel5.5?

QuestionsCan I use Events on Laravel5.5?
hirohito wada asked 6 years ago

I can't use Events on Laravel5.5.

source
$e["on_insert"] = array("add_kamoku", null, FALSE);
$g->set_events($e);

error messeage.

call_user_func() expects parameter 1 to be a valid callback, function 'add_kamoku' not found or invalid function name
/Users/hirohito/Laravel5/ringi/app/Classes/phpgrid/jqgrid_dist.php#2167

8 Answers
Abu Ghufran answered 6 years ago

It appears that your function add_kamoku is some class method and not global function.
In that case, you need to pass class name as second param. e.g. if your class name is 'Foo' you need to set:

$e["on_insert"] = array("add_kamoku", "Foo", FALSE);

hirohito wada answered 6 years ago

Thank you.

It solved. A little problem remains.

'jqg'+xx(xx is integer) show in Id column(Primary/autoincrement).
When reloading, It change integer.

Abu Ghufran answered 6 years ago

You can set:

$opt["reloadedit"] = true;

$g->set_options($opt);

It will force reloading after add/edit.

hirohito wada answered 6 years ago

Unfortunately it doesn't work.
My options is follow

$opt=$this->opt_edit('科目一覧');
$g->set_options($opt);

——————————————-

protected function opt_edit($param) {

$opt=array();
$opt["cellEdit"] = true;
$opt["scroll"] = true;
$opt["autowidth"] = true;
$opt["resizable"] = true;
$opt["viewrecords"] = true;
$opt["caption"] = $param;
$opt["actionicon"] = TRUE;
$opt["reloadedit"] = true;
// $opt["toolbar"] = TRUE;
// $opt["toppager"] = TRUE;
return $opt;
}

Abu Ghufran answered 6 years ago

Can you check if this issue exist on demo: http://phpgrid.org/demo/demos/editing/inline-add.php
If it's working in demo, please compare you code with it.

gianluca answered 4 years ago

Hi Abu,

I need to handle on_insert event in a subgrid (laravel) so I add in my public function index_detail(Request $request) following code:

$e[“on_insert”] = array(“add_prestazione”, “App\Http\Controllers\OrdiniController”, true);

$grid->set_events($e);

In the same controller I put my custom code with a test query:

public function add_prestazione($input)
{
global $grid;
$grid->execute_query(“INSERT INTO test VALUES (‘2′,’testo’)”);

 

but I got this error message in chrome console.

  1. {message: “Call to a member function execute_query() on null”, exception: “Error”,…}
    1. exceptionError
    2. fileC:\xampp\htdocs\sigesc\app\Http\Controllers\OrdiniController.php
    3. line2169
    4. messageCall to a member function execute_query() on null
    5. trace[{file: “C:\xampp\htdocs\sigesc\app\Classes\phpgrid\jqgrid_dist.php”, line: 2594,…},…]
      1. 0{file: “C:\xampp\htdocs\sigesc\app\Classes\phpgrid\jqgrid_dist.php”, line: 2594,…}
        1. classApp\Http\Controllers\OrdiniController
        2. fileC:\xampp\htdocs\sigesc\app\Classes\phpgrid\jqgrid_dist.php
        3. functionadd_prestazione
        4. line2594
        5. type::
      2. 1{file: “C:\xampp\htdocs\sigesc\app\Http\Controllers\OrdiniController.php”, line: 1586,…}
        1. classjqgrid
        2. fileC:\xampp\htdocs\sigesc\app\Http\Controllers\OrdiniController.php
        3. functionrender
        4. line1586
        5. type->
      3. 2{function: “indexDetail”, class: “App\Http\Controllers\OrdiniController”, type: “->”}
        1. classApp\Http\Controllers\OrdiniController
        2. functionindexDetail
        3. type->

Can you help me find where I’m wrong?

Thanks

Abu Ghufran Staff answered 4 years ago

When you use laravel, inside controller there is no $grid variable which is defined globally. You need to make it controller member variable and access with $this->grid;

Refer this code: https://gist.github.com/749f9e975c1b583768a5aedf2d8c079f

Line 16,47,86

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

Thank You. Now I can fully handle on_insert events

Your Answer

2 + 6 =

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?