Joomla! Discussion Forums



It is currently Thu Nov 26, 2009 8:16 am (All times are UTC )

 




Post new topic Reply to topic  [ 13 posts ] 
Author Message
Posted: Fri Mar 09, 2007 11:32 am 
User avatar
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Sun Jun 11, 2006 10:29 am
Posts: 291
Location: Netherlands
Hello

(yes i have read http://forum.joomla.org/index.php/topic ... html  ;))

Ok lets start to say what I know:
- put a file named router.php in your folder
- put 2 functions in it: ComponentBuildRoute and ComponentParseRoute

Then my knowledge stops :)

Ok the name I use in my classes for my component is JMS (JMSBuildRoute & JMSParseRoute)

I use links like:
- http://127.0.0.1/index.php?option=com_j ... &Itemid=51
- http://127.0.0.1/index.php?option=com_j ... =component
- http://127.0.0.1/index.php?option=com_j ... &Itemid=51
No where in my links I use &task=. Tasks are all done trough forms.

This is a part of form with the hidden values.




Ok. Now how can I change this all to integrate with the new Itemid way?
Do I have to change the links? the forms? what code should be in the router.php

I hope I have provided enough info, if not please ask for more  ;)

Thanks in advance and I hope I its not that hard as I think it is  :)

_________________
Founder and Lead developer of JAM (http://joomladev.org)
JAM is the first J!1.5 only component using AJAX!


Top
  E-mail  
 
Posted: Fri Mar 09, 2007 1:29 pm 
User avatar
Joomla! Virtuoso
Joomla! Virtuoso
Offline

Joined: Sat Sep 24, 2005 11:01 pm
Posts: 4490
Location: Toronto, Canada
Basically, ComponentBuildRoute needs to take the query that is passed to it and return an array with the items in the right order.

Then ComponentParseRoute will get an array back and it needs to set the request variables.

One thing you should know first is that this only works on the frontend (I think you know this, but just for clarification).

I don't think you need to worry about your post variables.  Post variables usually imply you are doing some sort of data manipulation.  The main point of JRouter is to make it easy for people to remember your URLs and make them easy for the search engine to distinguish.  You don't really want nor expect search engines to pick up i.e. the submit a message form or whatnot.  task is hidden from the query string, so you don't have to worry about it being unfriendly/unreadable.

Hope this helps and gets you started.  Again, I guess to put things another way, JRouter allows you to pass variables over the query string without specifying what the variable names are in the query string.  This is done by placing the variables on the query string in a predictable order.  In your example you might have URLs like:
index.php/jms/message/234
message is the view name, and 234 is the message number.  We know how to decode this: if the first parameter is message, then we know that the second one is the message number.

index.php/jms/messages/joeblow
messages is the view name, and joeblow is the user name.  We display the users messages.  We know how to decode this again because it is in a predictable order.

The jms is automatically added for you.

Does this help?
Ian

_________________
Joomla! Leadership Team - Production Working Group
Joomla! Bug Squad Coordinator
Joomla! Developer Documentation Team
Please don't say something 'isn't working'. Explain what you tried, and what happened as a result.


Top
   
 
Posted: Fri Mar 09, 2007 5:30 pm 
User avatar
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Sun Jun 11, 2006 10:29 am
Posts: 291
Location: Netherlands
Great, I understand the working now. Thanks Ian.  :-* :laugh:

Edit: Now I just have to find out how to create the right funtions....

_________________
Founder and Lead developer of JAM (http://joomladev.org)
JAM is the first J!1.5 only component using AJAX!


Last edited by nicholai on Fri Mar 09, 2007 5:48 pm, edited 1 time in total.

Top
  E-mail  
 
Posted: Fri Mar 09, 2007 7:07 pm 
User avatar
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Sun Jun 11, 2006 10:29 am
Posts: 291
Location: Netherlands
nicholai wrote:
Great, I understand the working now. Thanks Ian.  :-* :laugh:

Edit: Now I just have to find out how to create the right funtions....


Ok, I believe I have the functions done.
Code:
function JMSBuildRoute(&$query)
{
   $segments = array();

   if(isset($query['view']))
   {
      $segments[] = $query['view'];
      unset($query['view']);
   };

   if(isset($query['id']))
   {
      $segments[] = $query['id'];
      unset($query['id']);
   };

   if(isset($query['toid']))
   {
      $segments[] = $query['toid'];
      unset($query['toid']);
   };

   return $segments;
}

function JMSParseRoute($segments)
{
   // Get the active menu item
   $menu =& JMenu::getInstance();
   $item =& $menu->getActive();

   // Count route segments
   $count = count($segments);

   // Handle View and Identifier
   switch($item->query['view'])
   {
      case 'new' :
      {
         if($count == 2) {
            JRequest::setVar( 'toid', $segments[1], 'get');
         }
         $view = 'new';
      } break;

      case 'read' :
      {
         JRequest::setVar( 'id', $segments[1], 'get');
         $view = 'read';
      } break;

      case 'inbox' :
      {
         $view = 'inbox';
      } break;

      case 'outbox' :
      {
         $view = 'outbox';
      } break;

      case 'archive' :
      {
         $view = 'archive';
      } break;

      case 'trash' :
      {
         $view = 'trash';
      } break;

      case 'settings' :
      {
         $view = 'settings';
      } break;
   }

   JRequest::setVar( 'view', $view, 'get');
}


I have also changed all urls to use the JRoute::_() function.

Anyway, if I submit a form, all routing things are messed up from then, AND the urls are back to the 'old' style again.
Also trying manually to get back to the 'new' style (link = index.php/jms/new) results into the default page (inbox).
???

I also have another question. Is it possible to change the key in the url?
Example:
Original : index.php&option=com_jms&view=read&id=523
New : index.php/jms/read/subject_of_the_message

And if that's possible, how ?

Thanks in advance and bless J 1.5  8)

_________________
Founder and Lead developer of JAM (http://joomladev.org)
JAM is the first J!1.5 only component using AJAX!


Top
  E-mail  
 
Posted: Fri Mar 09, 2007 7:38 pm 
User avatar
Joomla! Virtuoso
Joomla! Virtuoso
Offline

Joined: Sat Sep 24, 2005 11:01 pm
Posts: 4490
Location: Toronto, Canada
I'm not really sure what is going on with your code...  maybe you can post the requests that aren't working or that mess things up (along with the intended get and post variables).

As for changing keys, absolutely - all you have to do is convert in the build and parse it in parse.  As long as subject is unique, you should be fine.

Ian

_________________
Joomla! Leadership Team - Production Working Group
Joomla! Bug Squad Coordinator
Joomla! Developer Documentation Team
Please don't say something 'isn't working'. Explain what you tried, and what happened as a result.


Top
   
 
Posted: Fri Mar 09, 2007 8:59 pm 
User avatar
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Sun Jun 11, 2006 10:29 am
Posts: 291
Location: Netherlands
ianmac wrote:
I'm not really sure what is going on with your code...  maybe you can post the requests that aren't working or that mess things up (along with the intended get and post variables).

As for changing keys, absolutely - all you have to do is convert in the build and parse it in parse.  As long as subject is unique, you should be fine.

Ian


No, of course the subjects can not always be the same. I ll look in the other comps as they use things like 45-example-here, where the id is 45

_________________
Founder and Lead developer of JAM (http://joomladev.org)
JAM is the first J!1.5 only component using AJAX!


Top
  E-mail  
 
Posted: Tue Mar 20, 2007 2:47 am 
User avatar
Joomla! Champion
Joomla! Champion
Offline

Joined: Fri Aug 12, 2005 12:47 am
Posts: 6431
Nicholai,

Your parse route function is wrong. You are looking at the active menu item to determine the parent view this is done in the core components t create a hierarchical structure. In your case this is not needed. You need something like :

Code:
function JMSParseRoute($segments)
{
   JRequest::setVar( 'view', $sgements[0], 'get');
}

_________________
Johan Janssens - Joomla Co-Founder, Lead Developer of Joomla 1.5

http://www.nooku.org - multi-lingual content manager and rapid extension development framework for Joomla 1.5
http://www.joomlatools.eu - training, consulting and extension development


Top
   
 
Posted: Sun Mar 25, 2007 11:02 am 
User avatar
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Sun Jun 11, 2006 10:29 am
Posts: 291
Location: Netherlands
Jinx wrote:
Nicholai,

Your parse route function is wrong. You are looking at the active menu item to determine the parent view this is done in the core components t create a hierarchical structure. In your case this is not needed. You need something like :

Code:
function JMSParseRoute($segments)
{
   JRequest::setVar( 'view', $sgements[0], 'get');
}



Thanks Jinx it is working.

I have other problems now:
After a form action the index.php/jms/blabla structure is ruined; it changes into something like "index.php/component/jms?view=settings", so the itemid is also forgotten which results in modules set by itemid = 1;
???

PS. The component is inserted, so the problem can be experienced


You do not have the required permissions to view the files attached to this post.

_________________
Founder and Lead developer of JAM (http://joomladev.org)
JAM is the first J!1.5 only component using AJAX!


Top
  E-mail  
 
Posted: Sun Mar 25, 2007 4:02 pm 
User avatar
Joomla! Champion
Joomla! Champion
Offline

Joined: Fri Aug 12, 2005 12:47 am
Posts: 6431
Don't have the time to look at your code, sorry ! Quick question, are you doing a JRoute for the form action ?

_________________
Johan Janssens - Joomla Co-Founder, Lead Developer of Joomla 1.5

http://www.nooku.org - multi-lingual content manager and rapid extension development framework for Joomla 1.5
http://www.joomlatools.eu - training, consulting and extension development


Top
   
 
Posted: Sun Mar 25, 2007 4:19 pm 
User avatar
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Sun Jun 11, 2006 10:29 am
Posts: 291
Location: Netherlands
Jinx wrote:
Don't have the time to look at your code, sorry ! Quick question, are you doing a JRoute for the form action ?


Code:
<form action="index.php" method="post" name="adminForm" enctype="multipart/form-data">
[.....]
<input type="hidden" name="option" value="com_jms" />
<input type="hidden" name="task" value="savesettings" />
</form>

_________________
Founder and Lead developer of JAM (http://joomladev.org)
JAM is the first J!1.5 only component using AJAX!


Top
  E-mail  
 
Posted: Sun Mar 25, 2007 4:39 pm 
User avatar
Joomla! Champion
Joomla! Champion
Offline

Joined: Fri Aug 12, 2005 12:47 am
Posts: 6431
Make that :

Code:
<form action="<?php echo JRoute::_('index.php') ?>" method="post" name="adminForm" enctype="multipart/form-data">

_________________
Johan Janssens - Joomla Co-Founder, Lead Developer of Joomla 1.5

http://www.nooku.org - multi-lingual content manager and rapid extension development framework for Joomla 1.5
http://www.joomlatools.eu - training, consulting and extension development


Top
   
 
Posted: Sun Mar 25, 2007 7:40 pm 
User avatar
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Sun Jun 11, 2006 10:29 am
Posts: 291
Location: Netherlands
Jinx wrote:
Make that :

Code:
<form action="<?php echo JRoute::_('index.php') ?>" method="post" name="adminForm" enctype="multipart/form-data">



Thanks Jinx  :)

_________________
Founder and Lead developer of JAM (http://joomladev.org)
JAM is the first J!1.5 only component using AJAX!


Top
  E-mail  
 
Posted: Sat May 30, 2009 12:24 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Wed May 20, 2009 7:32 pm
Posts: 18
Hello joomla people,
I had similar problem (I know this is old thread).

I've mimic Khepri functionality in front end:
http://www.jlleblanc.com/option,com_fir ... 2947/#2943

But JToolbar doesn't work with SEF.
It works well without SEF.

Most used button [apply, save, cancel] is likely forwarded
to the same url as edit form instead of main form.
I don't know if it is submitform request problem or the url problem.

I already made router.php as below.
Maybe submitbutton task request (post ???) always replaced by router' task.

I know we don't need any data entry to be known in search engine.
And since mixing post and get is confusing,
I've decided to disable $vars['task'].

The url looks like something?task=edit&cid[]=2 ..
Everything seems to be okay,
and everything is redirected to main form.

But then apply button is still
redirected to main form instead of edit form.

I've check the mvc controller,
and trapped task after clicking apply button.
Code:
   function __construct( $config = array() )
   {
      parent::__construct( $config );
      echo 'task = JRequest::getCmd('task');
      exit;


It shows nothing
Code:
task =


Am I missing something fool here?



Thank You

~epsi
---------------------

I'm using post from adminFrom.
I've check with alert(document.adminForm.task.value);
After clicking apply button, it say `alert`.

Code:
<form action="#" method="post" name="adminForm" id="adminForm">
   ...
   <input type="hidden" name="task" value="" />
</form>


Code:
<?php
/**
* SEF target
* /component/sample/master/
* /component/sample/master/add
* /component/sample/master/edit?cid[]=3
* /component/sample/detail/3
* /component/sample/detail/3/add
* /component/sample/detail/3/edit?cid[]=6
**/

// no direct access
defined('_JEXEC') or die('Restricted access');

function PortsBuildRoute(&$query)
{   
   $segments = array();

   if(isset($query['controller']))   // segment[0]
   {   
      $segments[] = $query['controller'];
      unset( $query['controller'] );
   }   
   
   // master-id for detail, if any
   if(isset($query['mid']))      // segment[1]   
   {   
      $segments[] = $query['mid'];
      unset( $query['mid'] );
   }      
/*
   if(isset($query['task']))      // segment[1]
   {   
      $segments[] = $query['task'];
      unset( $query['task'] );
   }
*/
   return $segments;
}

function PortsParseRoute($segments)
{
   $count = count( $segments );   

   $vars = array();         
   $vars['controller'] = array_shift($segments);
   
   if ($vars['controller']=='details')   
      $vars['mid'] = (int) array_shift($segments);

//   $vars['task']   = array_shift($segments);         

   return $vars;
}



Sorry for the long story.

~epsi


Top
  E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

Quick reply

 



Who is online

Users browsing this forum: michalp8105, mirnes and 36 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group