⚠ 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

Set Relation



siubie

siubie
  • profile picture
  • Member

Posted 25 August 2012 - 16:10 PM

Hello i am new to grocerycrud :) first impression was really great.
But i have a problem here on the set_relation function.

as written in the documentation :


function employees_management()
{
$crud = new grocery_CRUD();

$crud->set_theme('datatables');
$crud->set_table('employees');
$crud->display_as('officeCode','Office City');
$crud->set_subject('Employee');

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

$output = $crud->render();

$this->_example_output($output);
}


this code works for me but in my case i need another collumn from offices tables to be shown in the grid anyone can help me with this ?

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 25 August 2012 - 16:37 PM

Hello [member='siubie'] and welcome to the forum,

I don't know if this is the situation but you can also use some other fields of you set_relation table like this:

$crud->set_relation('user_id','users','{username} - {last_name} {first_name}');

For more go to : http://www.grocerycr...ns/set_relation

If you want to have another column you have to add it as a callback_column as grocery CRUD doesn't support custom queries yet at the grid.

So for example in your case you can do something like this:

1. Add a fake column name that doesn't exist at your basic table (employees) for example:

$crud->columns('lastName','firstName','email','officeCode','country_office');

(for more go to http://www.grocerycr...nctions/columns )
2. Add a callback column at the fake column for example:

$crud->callback_column('country_office',array($this,array('_column_country_office')));

...

function _column_country_office($value, $row)
{
$this->db->where('officeCode',$row->officeCode);
return $this->db->get('offices')->row()->country;
}


(for more go to http://www.grocerycr...callback_column )

noskov.biz

noskov.biz
  • profile picture
  • Member

Posted 25 August 2012 - 16:38 PM

Hi, siubie and welcome to the forum!
Please, look at the docs for description of set_relation() function. It is well documented and I think that will help you.

If you will have any questions, you are welcome :)

siubie

siubie
  • profile picture
  • Member

Posted 25 August 2012 - 16:56 PM

Thx for a lightning speed reply guys.. i think callback_column is the solution

MiamMiam

MiamMiam
  • profile picture
  • Member

Posted 05 January 2014 - 13:49 PM

I've pasted web_johnny's code in the examples database and I get this error message :

 

A PHP Error was encounteredSeverity: Warning
Message: call_user_func() expects parameter 1 to be a valid callback, second array member is not a valid method
Filename: libraries/Grocery_CRUD.php
Line Number: 1757

What could be wrong ? Is this piece of code still available ? Thanks


MiamMiam

MiamMiam
  • profile picture
  • Member

Posted 11 January 2014 - 12:43 PM

any idea ? thanks