Welcome, Guest
Username: Password: Remember me

TOPIC: Passing to a FLY field when different tables?

Passing to a FLY field when different tables? 05 Mar 2013 07:58 #6906

  • levi
  • levi's Avatar
  • Offline
  • New Member
  • Posts: 9
  • Thank you received: 1
  • Karma: 0
As I understand, you can as a redirect value use:

In form:
- if passing to a input field use "my_fieldname"
- if passing to a combo box prefix your fieldname with "filter_" such as "filter_myfieldname"

In fly:
- if passing to a fly field related to same table, use "filter_itemtitle" to pass the items id


But here is my question:
What redirect value can I use to pass to a fly field related to a different table?

Is there an in-Cook way of achieving this?
The administrator has disabled public write access.

Re: Passing to a FLY field when different tables? 05 Mar 2013 09:26 #6907

  • BTB300
  • BTB300's Avatar
  • Offline
  • Moderator
  • Posts: 415
  • Thank you received: 132
  • Karma: 47
Ji Levi

Do you want to pass the ID or the value of another field to a different view?

if i remember correctly the easiest way to work out what you need to pass is
- construct a fly view with the required fields
- check out the resulting model for the field names

it would be something like
my_table_field_name

Anyhow not sure if you have seen this but i would start Start Here
www.j-cook.pro/forum/33-developper-resso...-with-redirects#4149

Hope it helps
The administrator has disabled public write access.

Re: Passing to a FLY field when different tables? 05 Mar 2013 09:41 #6908

  • levi
  • levi's Avatar
  • Offline
  • New Member
  • Posts: 9
  • Thank you received: 1
  • Karma: 0
Is there an in-Cook way of achieving this?

Can I use the reuse field? "tablename_fieldname"?

I have earlier seen the link you sent, but still little unsure...
The administrator has disabled public write access.

Re: Passing to a FLY field when different tables? 05 Mar 2013 10:00 #6910

  • BTB300
  • BTB300's Avatar
  • Offline
  • Moderator
  • Posts: 415
  • Thank you received: 132
  • Karma: 47
Hi Again,
At present only the ID of the current view can be passed in Cook Redirect
- you need to modify the redirects in your downloaded component
- the redirects are located in your item controller (for both collection and item layouts)
- have not visited redirects for sometime but i think something like the following should work

This will parse the current ID and another field
case 'yyyyyyy.save':
		$this->applyRedirection($result, array(
			'com_xxxx.yyyyyy.layout1',
			'com_xxxx.yyyyyy.layout2'
		), array(
			'cid[]' => null,
			'filter_some_id'=> 'cid['.$model->getId().']', // pass the current id
			'my_table_my_field'=> $item->another_table_some_text_field // perhaps this may work?
					
		));
		break;
The administrator has disabled public write access.

Re: Passing to a FLY field when different tables? 05 Mar 2013 11:28 #6913

  • levi
  • levi's Avatar
  • Offline
  • New Member
  • Posts: 9
  • Thank you received: 1
  • Karma: 0
Tx for your feedback!

I can't get it to work.

I have two tables: companies (item is company) and departments (item is department).
In the first layout (makecompany) I register the company (fields: name, address)
In the next layout (tabledepartment) I want to add a department to the company.

The layout (tabledepartment) must show:

FLY:
Company name: [company.name]

FORM:
Department name: [department.name]
Department leader: [department.leader]

How can I define the array to be able to pass the correct variable, and then to show the company name on the second layout?

This is my code by now:
case 'makecompany.save':
$this->applyRedirection($result, array(
	'com_test.company.makecompany',
	'com_test.department.tabledepartment'
), array(
	'cid[]' => null,
	'filter_company' => $model->getState('company.id'),
	'filter_company'=> $item->department.companyid
));
break;
The administrator has disabled public write access.

Re: Passing to a FLY field when different tables? 05 Mar 2013 16:34 #6914

  • BTB300
  • BTB300's Avatar
  • Offline
  • Moderator
  • Posts: 415
  • Thank you received: 132
  • Karma: 47
Hi Levi
Have set up a test component
Companies (collection) / Company (item)
[company_name]
[company_address]

Departments (collection) / Department (item)
[department_name]
[department_leader]
[company_id]

In Your Company Item Controller you need to pass the company_name as shown below see comment.

Offered as a work around but as always open to options if anyone else has alternate / cleaner solution

Hope it helps get you on the right track...
switch($this->getLayout() .'.'. $this->getTask())
{
	case 'makecompany.save':
		$this->applyRedirection($result, array(
			'com_company.company.makecompany',
			'com_company.department.department'
		), array(
			'cid[]' => null,
			'filter_company_id' => $model->getState('company.id'), 
		// <= added comma in the line above
		// <= added the line below to get the value of company_name from the model 
			'_company_id_company_name' => $model->getItem()->company_name
		));
		break;
}

And In your Department Model - the value of company name is not populated until the department view is saved (save and close button) or applied (save button). Need to add the company name to the default values - see note in code below

The default values are set here in your department model
// Prime some default values.
if ($this->getState('department.id') == 0)
{
	$jinput = new JInput;

	$data->id = 0;
	$data->params = null;
	$data->department_name = null;
	$data->department_leader = null;
	$data->company_id = $jinput->get('filter_company_id', $this->getState('filter.company_id'), 'INT');
	// Added the following line to pre-populate the company name 
	$data->_company_id_company_name = $jinput->get('_company_id_company_name');

}

Further down in your model you will find the name of the field you need - see comment in code below
switch($this->getState('context'))
{
	case 'department.department':

	//BASE FIELDS
	$this->addSelect(	'a.company_id,'
				.	'a.department_name,'
				.	'a.department_leader');

	//SELECT
	// the field name to pre populate in the default values is found here 
	// NOTE: the underscore!
	$this->addSelect('_company_id_.company_name AS `_company_id_company_name`');

	//JOIN
	$this->addJoin('`#__company_companies` AS _company_id_ ON _company_id_.id = a.company_id', 'LEFT');

	break;
Last Edit: 05 Mar 2013 17:13 by BTB300.
The administrator has disabled public write access.

Re: Passing to a FLY field when different tables? 05 Mar 2013 17:09 #6915

  • BTB300
  • BTB300's Avatar
  • Offline
  • Moderator
  • Posts: 415
  • Thank you received: 132
  • Karma: 47
NOTICE: Above Reply edited - with solution / workaround
BTB300
The administrator has disabled public write access.

Re: Passing to a FLY field when different tables? 05 Mar 2013 18:44 #6916

  • BTB300
  • BTB300's Avatar
  • Offline
  • Moderator
  • Posts: 415
  • Thank you received: 132
  • Karma: 47
A Cleaner Method would be to pass the filter_company_id to a function in model (that way the company name is not passed and displayed as part of the URL) and potentially you could pre-populate fly views with any variables you wish... Just a thought

Function could be something like this
public function prequery( $id)
	{
		$db=JFactory::getDBO();
		$query = $db->getQuery(true);
		$query->select(array('pre.id', 'pre.company_name'));
		$query->from('#__company_companies AS pre');
		$query->where('pre.id = ' . (int) $id);
		
		$db->setQuery($query);
		
		$result= $db->loadObject();
		
		return $result;
		
	}
Last Edit: 05 Mar 2013 18:46 by BTB300.
The administrator has disabled public write access.

Re: Passing to a FLY field when different tables? 06 Mar 2013 07:06 #6918

  • levi
  • levi's Avatar
  • Offline
  • New Member
  • Posts: 9
  • Thank you received: 1
  • Karma: 0
Tx. I will look into this :-)
The administrator has disabled public write access.
Time to create page: 0.062 seconds

Get Started