Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter Grocery Crud extend set_relation() function?

Is there anyone knows how to extend the set_relation() ?

Here is the idea, base on the example of Grocery Crud employee and offices tablesample table

$crud->set_relation('officeCode','offices','city');

the code output will show all city in dropdown, but I want to extent the set_relation() to filter all city by state to show in dropdown?

for example I want to show all city of Arizona state in dropdown, Does anyone done this before using grocery crud?

reference example:

Grocery Crud

like image 484
noviceRick Avatar asked Jun 02 '26 23:06

noviceRick


1 Answers

I know my response is some what dated and probably no use to the OP now, but I'm guessing there are many people who might be looking at this post for inspiration to their own set_relation problems. I propose a more simple solution to this... (in fairness to Idham I don't know when the 4th param of set_relation() became available.)

...
$state = "AZ"; // or however you get the state you want to filter by
$crud->set_relation('officeCode','offices','city', 'officeCode IN (SELECT officeCode FROM offices WHERE state='.$state.')');
...

Voila! True grocery_CRUD awesomeness!

like image 84
Kenilik Avatar answered Jun 06 '26 06:06

Kenilik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!