php - Joomla Developement :: Probleme with URL Rewriting

734

I am finalizing the creation of a component for Joomla and I have problems with URL rewriting.

I have created the class "router.php" which is called by the base file of my component, and I use "JRoute" to rewrite my link in SEF.

The problem is that Joomla ignores my component rooter and loads the contents of the native componentcom_content.

for the following url - http://lafoliedesvernis.com/vernitheque/revendeurs/2-printemps-haussmann.html - Joomla will show me the article ofcom_content who haveID = 2 rather than display the record of my component that hasID = 2

I feel that I have reached my goal, but for some code somewhere which I can't see. what makes Joomla ignore my router and use thecom_content router?

Here is the code for my router:

<?php
defined ('_JEXEC') or die ('Restricted access');

   VernithequeBuildRoute function (& $ query)
   {
     $ Segments = array ();

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

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

     return $ segments;
   } / / End function VernithequeBuildRoute

   VernithequeParseRoute function ($ segments)
   {
     $ Vars = array ();

     if (count ($ segments)> 0) {

         $ Vars ['view'] = $ segments [0];
       switch ($ vars ['view']) {
         case 'all':
             $ Catid = explode (':', $ segments [1]);
             $ Vars ['catid'] = (int) $ catid [0];
          break;
         case 'category':
             $ Vars ['id'] = (int) $ segments [1];
          break;
         case 'brand':
             $ Id = explode (':', $ segments [1]);            
             $ Vars ['id'] = (int) $ id [0];       
          break;
         case 'resellers':
             $ Id = explode (':', $ segments [1]);            
             $ Vars ['id'] = (int) $ id [0];       
          break;
         case 'varnish':
             $ Id = explode (':', $ segments [1]);            
             $ Vars ['id'] = (int) $ id [0];       
          break;
         case 'configure':
             $ Id = explode (':', $ segments [1]);            
             $ Vars ['id'] = (int) $ id [0];       
          break;
         box 'panel':
             $ Id = explode (':', $ segments [1]);            
             $ Vars ['id'] = (int) $ id [0];       
          break;

       };

     Else {}
       $ Vars ['view'] = $ segments [0];
     } / / End count (segments) statement

     return $ vars;
   } / / End VernithequeParseRoute
?>
655

Answer

Solution:

Your current SEF URL is made up of two parts:

vernitheque/revendeurs/ points to the component,

and

2-printemps-haussmann.html

identifies the article / item.

Joomla creates the first part based on menu item aliases, NOT component names! (unless your component has no menu item associated, in which case you would see /component/content)

So check your menus, /vernitheque should be the alias of a first-level menuitem, and possibly revendeurs is the second level for some com_content view.

So create a menu item that points to a view in your component and give it a meaningful alias.

Your SEF urls should now have the new alias as a prefix, and routing should start working again.

If however the generated alias still points to Joomla com_content, this would be very weird: Joomla only allows unique top-level aliases.

I haven't looked deeply into your code, but from the behaviour you describe the issue seems to be outside its scope (it's invoking the wrong component, not passing the wrong parameters)

910

Answer

Solution:

So I get a step and I can bring some precisions:

Apparently it's not a "router" problem , I stuted the "com_content" router, including reference information that (the $ vars array).

In this case the $vars array returned by the "route" of the "com_content" is composed of the index "view" (string), index "id" (int), and the index "catid "(int) if there is one. So I made sure that the "router" in my component returns the same thing, and that the case because if I do a var_dump of $ vars on the landing page I have returned data that appears but the loaded data are those of "com_content", it is indeed an extension problem ! Joomla does not load the correct extension, it will not read the correct table ... so what may come?? the item ID?? the menu link??

If necessary I put the code for JRoute:

// Not Working   
    $link = JRoute::_('index.php?view='.$type.''.$catid.'&id='. $slug);
    // also try this but Not Working to   
    $link = JRoute::_('index.php?option=com_vernitheque&view='.$type.''.$catid.'&id='. $slug);

People are also looking for solutions to the problem: Why my image created by php is not displaying?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.