Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Migrating to 3.0 - Redirect Loop SEF Front-end 23 Mar 2013 09:11 #6999

Hi all,

(Reposted as previous was posted in wrong category)

I have generated a component for testing with Cook and am now migrating it to work on Joomla 3.0. Back-end went fairly smoothly, but seem to have an issue with SEF and the front-end when I am accessing the component via a menu (or any SEF link really).

So for example when I do this:
www.mydomain.com/index.php?option=my_component&view=myview

It works fine.

But this:
www.mydomain.com/componentname/myview

results in a infinite redirect loop.

I have been checking the router.php generated by Cook and it seems to endlessly call the buildRoute.

This is the code of the router.php:
/**
 * Build the route for the com_wpf component
 *
 * @param	array	An array of URL arguments
 *
 * @return	array	The URL arguments to use to assemble the subsequent URL.
 */
function WpfBuildRoute(&$query) {

    logThis("Building Route\n");
    logThis("Query:\n");
    foreach ($query as $field=>$value) {
        logThis($field.'=>'.$value."\n");
    }
    logThis("\n");

    $segments = array();
    if (isset($query['view'])) {
        logThis("We have a view {$query['view']}\n");
        $view = $query['view'];
        $segments[] = $view;
        unset($query['view']);
    }

    if (isset($query['layout'])) {
        logThis("We have a layout {$query['layout']}\n");
        $segments[] = $query['layout'];
        unset($query['layout']);
    }


    if (isset($query['id'])) {
        if (in_array($view, array('country', 'editcountry', 'projectstatus', 'editprojectstatus', 'projecttype', 'editprojecttype', 'service', 'editservice', 'sector', 'editsector', 'client', 'editclient', 'clientsector', 'editclientsector', 'project', 'editproject', 'screenshot', 'editscreenshot', 'serviceapplied', 'editserviceapplied'))) {
            $segments[] = (is_array($query['id']) ? implode(',', $query['id']) : $query['id']);
            unset($query['id']);
        }
    };

    logThis("Segments:\n");
    foreach ($segments as $field=>$value) {
        logThis($field.'=>'.$value."\n");
    }
    logThis("\n\n");
    return $segments;
}

/**
 * Parse the segments of a URL.
 *
 * @param	array	The segments of the URL to parse.
 *
 * @return	array	The URL attributes to be used by the application.
 */
function WpfParseRoute($segments) {
    logThis("Parsing route\n");
    logThis("Segments:\n");
    foreach ($segments as $field=>$value) {
        logThis($field.'=>'.$value."\n");
    }
    logThis("\n\n");
    $vars = array();


    $vars['view'] = $segments[0];

    $nextPos = 1;
    if (isset($segments[$nextPos])) {
        $vars['layout'] = $segments[$nextPos];
        $nextPos++;
    }

    //Item layout : get the cid value
    if (in_array($vars['view'], array('country', 'editcountry', 'projectstatus', 'editprojectstatus', 'projecttype', 'editprojecttype', 'service', 'editservice', 'sector', 'editsector', 'client', 'editclient', 'clientsector', 'editclientsector', 'project', 'editproject', 'screenshot', 'editscreenshot', 'serviceapplied', 'editserviceapplied')) && isset($segments[$nextPos])) {
        $slug = $segments[$nextPos];
        $id = explode(':', $slug);
        $vars['id'] = (int) $id[0];

        $nextPos++;
    }
    logThis("Vars:\n");
    foreach ($vars as $field=>$value) {
        logThis($field.'=>'.$value."\n");
    }
    logThis("\n\n");

    return $vars;
}

Does anybody else had this problem and/or know how to fix it?

Many thanks,

Misha

Please Log in or Create an account to join the conversation.

Re: Migrating to 3.0 - Redirect Loop SEF Front-end 23 Mar 2013 09:39 #7001

Little update:

I managed to "fix" it. Not sure if this is the right solution and would love to hear so if it isn't.

I noticed in the main controller of the component there is something built-in for when the page is called via a post. This checks the $_GET variable. If I change that to check the JRequest, the problem disappears.

So the display function in my general controller is now:
	public function display($cachable = false, $urlparams = false)
	{
		$jinput = new JInput;


		parent::display();

		//If page is called through POST only, reconstruct the url
                // MOD: change this to check the JRequest to avoid problems with SEF and infinite redirect loop
                if (!JRequest::getVar('option'))
                //if (!isset($_GET['option']))
		{
			//Kill the post and rebuild the url
			$this->setRedirect(WpfHelper::urlRequest());
			return;
		}

		return $this;
	}

Any comments or feedback are welcome.

Kind regards,

Misha
The following user(s) said Thank You: JoomGuy

Please Log in or Create an account to join the conversation.

Re: Migrating to 3.0 - Redirect Loop SEF Front-end 23 Mar 2013 10:52 #7002

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
Hi Misha,

Your fix looks good to me!

The $_GET in the controller has probably been hanging around there since Cook version 1 I guess!

Karma++

I'll post this to admin to ensure that the old code is updated!

Thanks,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

Please Log in or Create an account to join the conversation.

Re: Migrating to 3.0 - Redirect Loop SEF Front-end 23 Mar 2013 10:57 #7003

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
By the way, it may be worth checking the parent controller in your classes folder too, just in case there are any other $_GET references.

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

Please Log in or Create an account to join the conversation.

Re: Migrating to 3.0 - Redirect Loop SEF Front-end 23 Mar 2013 11:02 #7004

Hi Gez,

Just checked. In the parent controller there are no references to that. Just in the main controller generated in the root of the component (both admin and front-end of course).

Cheers,

Misha
The following user(s) said Thank You: JoomGuy

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.062 seconds

I'm playing around with the new mvc and the FORK feature is FANTASTIC!!! it's saving me a lot of time! you are doing a very good job!!

Tomaselli (Forum)  

Get Started