Jump to content


Set Relation


  • Please log in to reply
5 replies to this topic

#1 siubie

siubie

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 25 August 2012 - 04: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 ?

#2 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,150 posts
  • LocationLondon

Posted 25 August 2012 - 04:37 PM

Hello 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 )
Posted Image

#3 noskov

noskov

    grocery CRUD Guru

  • Advanced Member
  • PipPipPip
  • 175 posts
  • LocationKiev

Posted 25 August 2012 - 04: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 :)

#4 siubie

siubie

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 25 August 2012 - 04:56 PM

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

#5 MiamMiam

MiamMiam

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts
  • LocationLimousin - France

Posted 05 January 2014 - 01: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


Grocery CRUD is great ! | Contribute or donate... or do both ;-)


#6 MiamMiam

MiamMiam

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts
  • LocationLimousin - France

Posted 11 January 2014 - 12:43 PM

any idea ? thanks


Grocery CRUD is great ! | Contribute or donate... or do both ;-)





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users