Welcome, Guest
Username: Password: Remember me

TOPIC: [HOW TO] Work with redirects

[HOW TO] Work with redirects 30 Sep 2012 08:59 #4149

  • BTB300
  • BTB300's Avatar
  • Online
  • Moderator
  • Posts: 414
  • Thank you received: 130
  • Karma: 46
Working With Redirects [V2.0]

- You can redirect between forms related to the same table
table1.layout1 -> table1.layout2 -> table1.layout3

- You can redirect between forms with tables unrelated to each other
table1.layout1 -> table2.layout1 -> table3.layout1

when configuring the redirect option - only type the field name
we already know that we are passing the current id (filter_groupid=[id] does not work)

For a combo box use "filter_whatever_fieldname" - without quotes in the reuse option of the redirect
For any integer field use "whatever_fieldname" - without quotes in the reuse option of the redirect

To pass between forms related to the same table use "id" - without quotes in the reuse option of the redirect
(great for making step by step wizards to complete large data entries in smaller steps)

Currently only the current id is passed - (the id of the record that is displayed)

The redirect works well now and you can pass integer values easily using the methods above
- it allows you to pass to a filter (combo box) using 'filter_some_id' = cid
- it also allows you to display a specific record by using id = cid
- it allows you to create step by step wizards based on the same table
- it allows you to pass the current id to any other layout

Limitations of current redirect method
- currently passing strings such as " Freds Group" it does work without code modification
- currently it does not allow you to pass the value of any other variable

the structure is there to pass multiple values as shown below
- the only thing is that the url becomes very long passing additional individual values
- an array of values could be passed as ....&values in the url

REDIRECT FUNCTIONS - V2.0 (30/9/12)
- The redirect functions can be found inside the controller file of the relevant layout
- The code below shows a save function snippet
	case 'yyyyyy.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
					
		));
		break;

For those wanting to pass more than one variable in the redirect to combos in the next form (not currently available in cook redirect) edit the relevant controller file save function

PASSING MORE THAN ONE VARIABLE - not currently available in cook redirect
	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
			'filter_another_id'=> $item->another_id // add the the additional value for the combo here
					
		));
		break;

PASSING ALTERNATE VARIABLES - not currently available in cook redirect
	case 'yyyyyy.save':
		$this->applyRedirection($result, array(
			'com_xxxx.yyyyyy.layout1',
			'com_xxxx.yyyyyy.layout2'
		), array(
			'cid[]' => null,
			// remove this 'filter_some_id'=> 'cid['.$model->getId().']', // pass the current id
			'filter_another_id'=> $item->another_id // add the the additional value for the combo here
					
		));
		break;
Last Edit: 03 Oct 2012 13:34 by admin.
The administrator has disabled public write access.
The following user(s) said Thank You: admin, VeCrea, JoomGuy

Re: HOW TO: Work with redirects 30 Sep 2012 16:04 #4161

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  • Karma: 30
Superb. Thanks mate
The administrator has disabled public write access.

Re: HOW TO: Work with redirects 07 Dec 2012 20:32 #5910

  • jcasanova
  • jcasanova's Avatar
  • Offline
  • Senior Member
  • Posts: 40
  • Thank you received: 1
  • Karma: 1
Where are the "REDIRECT FUNCTIONS - V2.0 (30/9/12) "

can't find any on code nor cook UI
The administrator has disabled public write access.

Re: [HOW TO] Work with redirects 08 Dec 2012 07:03 #5927

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  • Karma: 30
BTB300 wrote:
Working With Redirects [V2.0]

REDIRECT FUNCTIONS - V2.0 (30/9/12)
- The redirect functions can be found inside the controller file of the relevant layout
- The code below shows a save function snippet
	case 'yyyyyy.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
					
		));
		break;

For those wanting to pass more than one variable in the redirect to combos in the next form (not currently available in cook redirect) edit the relevant controller file save function

PASSING MORE THAN ONE VARIABLE - not currently available in cook redirect
	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
			'filter_another_id'=> $item->another_id // add the the additional value for the combo here
					
		));
		break;

PASSING ALTERNATE VARIABLES - not currently available in cook redirect
	case 'yyyyyy.save':
		$this->applyRedirection($result, array(
			'com_xxxx.yyyyyy.layout1',
			'com_xxxx.yyyyyy.layout2'
		), array(
			'cid[]' => null,
			// remove this 'filter_some_id'=> 'cid['.$model->getId().']', // pass the current id
			'filter_another_id'=> $item->another_id // add the the additional value for the combo here
					
		));
		break;
The administrator has disabled public write access.

Re: [HOW TO] Work with redirects 08 Dec 2012 07:05 #5928

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  • Karma: 30
VeCrea wrote:
BTB300 wrote:
Working With Redirects [V2.0]

REDIRECT FUNCTIONS - V2.0 (30/9/12)
- The redirect functions can be found inside the controller file of the relevant layout
- The code below shows a save function snippet

Means you have to look in yoursite.com/components/com_youcomponent/controllers/the_name_of_the_table_you're_working_on.php

Did it help ?
The administrator has disabled public write access.

Re: [HOW TO] Work with redirects 08 Dec 2012 09:42 #5931

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
@Jcasanova

I think this is the same issue as you posted in the other thread about redirects. Here's how to create the save() function:audibleid wrote:
Sure, well, I don't believe a component is necessary but here's an example/instructions how to implement BTB300's redirection tutorial.

Cook handles this far better than joomla native although, because the code from cook is streamlined so well, you won't find a save function in your controllers/models as they utilise parent classes & super classes.Therefore, you need to:
  1. overload the save redirection in the controller like:
    public function save()
    {
      JRequest::checkToken() or JRequest::checkToken('get') or jexit(JText::_('JINVALID_TOKEN'));
      //Check the ACLs 
      $model = $this->getModel();
      $item = $model->getItem();
      if (!$model->canEdit($item))
        return false;
      $result = parent::save();
      //Catch the initializated JModel trough postSaveHook()
      $model = $this->model;
      //Define the redirections
      switch($this->getLayout() .'.'. $this->getTask())
    //==== REDIRECTORS GO BELOW HERE - see @BTB's solutions above in thread ====//
  2. Then, underneath the comment //==== REDIRECTORS GO... ====//, copy one of @BTB300's solutions, changing the component.view.layout in the redirectors as well as the view.task in the case/switch;
    • the first is the redirect if $result of the parent::save() == 0 OR NULL
    • the second is if if $result of the parent::save() == 1
  3. Be sure to close out of the switch()/cases and the save() function with:
    } // CLOSE SWITCH
    }//CLOSE FUNCTION
  4. Save and happy redirecting!
Hope it helps,

Gez ;)
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
Last Edit: 08 Dec 2012 09:43 by JoomGuy.
The administrator has disabled public write access.
The following user(s) said Thank You: jcasanova

Re: [HOW TO] Work with redirects 08 Dec 2012 12:26 #5935

  • jcasanova
  • jcasanova's Avatar
  • Offline
  • Senior Member
  • Posts: 40
  • Thank you received: 1
  • Karma: 1
Thanks Gez! Its 98% clear that way! Im on the phone right now, ill check
It ASAP

Again thank you so much!
The administrator has disabled public write access.

Re: [HOW TO] Work with redirects 10 Dec 2012 11:34 #5966

  • BTB300
  • BTB300's Avatar
  • Online
  • Moderator
  • Posts: 414
  • Thank you received: 130
  • Karma: 46
audibleid wrote:
the first is the redirect if $result of the parent::save() == 0 OR NULL
the second is if if $result of the parent::save() == 1
[/quote]

Almost
case 'yyyyyy.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
					
		));
		break;
To further explain
yyyyyy.save
yyyyyy => is the table name
save => the task applied to the button
com_xxxx.yyyyyy.layout1 and com_xxxx.yyyyyy.layout2
xxxx => your component name
yyyyyy => again is the table name
layout1 => is the layout the redirect is coming from
layout2 => is the layout the redirect is going to

its also worth noting the following
In your downloaded component - the code below has changed slightly
array(
			'cid[]' => null,
			'filter_some_id'=> 'cid['.$model->getId().']', // pass the current id
					
		));
When passing values between tables use the database tables field name! not the field alias from the mysql statement

for the redirect value
- if passing to a input field use "my_fieldname"
- if passing to a combo box prefix your fieldname with "filter_" such as "filter_myfieldname"
// To a combo box use
array(
		'cid[]' => null,
		'filter_myfieldname'=> ....
// To a input box use
array(
		'cid[]' => null,
		'myfieldname'=> ....

Hope it Helps
Last Edit: 10 Dec 2012 11:38 by BTB300.
The administrator has disabled public write access.
The following user(s) said Thank You: admin, jcasanova

Re: [HOW TO] Work with redirects 10 Dec 2012 11:41 #5968

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
BTB300 wrote:
audibleid wrote:
the first is the redirect if $result of the parent::save() == 0 OR NULL
the second is if if $result of the parent::save() == 1
Almost...
When I mentioned the first/second, I was referring to the 2 layouts in the applyRedirection: 'com_xxxx.yyyyyy.layout1' & 'com_xxxx.yyyyyy.layout2'.

That is right isn't it? So, if $result == 0 || $result == NULL -> 'com_xxxx.yyyyyy.layout1'
If $result == 1 -> 'com_xxxx.yyyyyy.layout2'.

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: [HOW TO] Work with redirects 10 Dec 2012 11:44 #5969

  • jcasanova
  • jcasanova's Avatar
  • Offline
  • Senior Member
  • Posts: 40
  • Thank you received: 1
  • Karma: 1
Guys, ...

I'm passing the ID (cid,) but in the redirection layout I want it hidden... should work just giving the fieldname (input hidden) and it will be hidden?

Thanks for your help
The administrator has disabled public write access.

Re: [HOW TO] Work with redirects 10 Dec 2012 11:53 #5973

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
You can do that either in your XML that contains your form by adding hidden to it: www.ostraining.com/howtojoomla/how-tos/d...g-started-with-jform I did have a link direct to the docs for field types but can't find it at the moment. Search the forum for JForm and I'm sure you'll get there...

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: [HOW TO] Work with redirects 10 Dec 2012 11:53 #5974

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
That's not easy.

Because redirections are not working with post.

I think you can write something in the router.php file.

Catch your case, and unset the var in url. It will be recognised in the request object (or now, jinput object).

Hope it helps, but I am not a guru with SEF.

Not easy stuff.

I think, using post is not possible in redirectior (even with some hacks).
My advice : router.php

Cannot say more.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: [HOW TO] Work with redirects 10 Dec 2012 12:11 #5982

  • BTB300
  • BTB300's Avatar
  • Online
  • Moderator
  • Posts: 414
  • Thank you received: 130
  • Karma: 46
@audiobleid looks like your correct layout1 is not only the current layout... (sorry my bad :whistle: )admin wrote:
Just a precision :
layout1, as somebody said, is almost of the case you layout from. But, it can also be another error page, even outside of your component (ex : an article, or home page... what you want)
The administrator has disabled public write access.

Re: [HOW TO] Work with redirects 10 Dec 2012 12:14 #5984

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
No probs, I was just checking it out with you/admin too - just to be sure... ;)

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.
Time to create page: 0.258 seconds

Get Started