I just installed the latest version and am needing to add a button to records that when clicked, goes to the URL contained in the record.
The table has a field “web” that contains the URL.
This worked great in the old version with the “$crud->add_action” function, but I cannot figure out how to make this work with the new “$crud->setActionButton”
I looked at the example in the documentation, but nothing I have tried does anything but put a non-functioning button on the record.
Can you please give a more specific example of what you are trying to do? I mean if you can add the code that you were using on the older versions that worked for you and what you have tried that doesn’t work should help.
Johnny, thanks for your reply, I really appreciate all your hard work.
What worked in the old version.
Note: I had to replace the actual url prefix with “SITE” to keep from being locked out of the forum.
Controller
$crud->add_action(‘SITE png’, ‘demo/action_more’,‘ui-icon-plus’,array($this,‘google_map’));
public function google_map($primary_key , $row)
{
//With the below code you will have the lat and the lon as GET parameters to your next request.
return “SITE/maps?q=”.$row->lat.",".$row->lng;
}
What I have tried that didn’t work would fill an encyclopedia
I did get it working, but is extremely kludgy. I have a function in the controller that calls a function in Model that cerates a new database connection, queries the table for the value in map for the record number in $row and returns the result back to the controller function that is the callback.
Apparently $row was an object in the old version, but is just a variable in the new one.
Ok, now I am getting the frustration that you had. I will try to update the documentation as this is a very common question that I have and it is not clear at the documentation. so your code will look similar to this (but there is a hint):
However, this will not work as the lat and lng will not be available for your datagrid. In short, for performance and security reasons I’ve removed the * from the SELECT of all the columns that I had before from 2.8.0 and later. Now you simply have to specify the columns as invisible columns. So your example will look like this:
$crud->columns(['customerName','phone','your_field_name', 'lat', 'lng']);
// By using the fieldTypeColumn you specify that the `invisible`
// field type will only be on the datagrid columns
$crud->fieldTypeColumn('lat', 'invisible');
$crud->fieldTypeColumn('lng', 'invisible');
$crud->setActionButton('your_field_name', 'fa fa-plus', function ($row) {
return "SITE/maps?q=" . $row->lat . "," . $row->lng;
});
I don’t seem to have the same library as you. In the description it says v 2.0.0.
When I call “fieldTypeColumn” it throws an error. I searched in the library and there is no function by that name.
I downloaded the package v 2.0.1 from your site.
I tried commenting out those lines, but then it throws the same error I originally had when first trying to move to new version.
See attached screen shots.
Thanks again for your time.
Hello @JDodd , sorry my mistake, I thought that you were referring to Grocery CRUD Enterprise edition. I will check the same for the community edition and let you know.
So @JDodd I’ve investigated the issue and on community edition the first argument is the value but the $row is on the second parameter. So your example will look like this: