0

Here is my current component setup. I have a very dynamic page generation component that syncs with data from a external API to create pages for products without extra data entry.

Right now it works at a simple button click to populate all and update any changes, or just update individual fields. What this leads to is the generation of static "pages" from the api in joomla, and the ability to update it from the api.

The problem comes into the fact that this is used as the "home" menu item so the component itself takes the root directory. What I need is each "page" to take a sub menu of home automatically, though just setting the main menu item as home does not seem to work, it leads to the JRoute class getting confused and using component/ , everything I have read so far takes the assumption it is not the default menu item so I am losing home making it fully automatic.

So my question is, is there a function class to create menu items from components in joomla? adding another row to the joomla menu table for each page while i update them "should" solve the problem, I know I can try to figure out how joomla adds them to the database on my own, but I would prefer to use a joomla class/function if at all possible, any ideas?

here is my current router.php, works fine for directly linking to the page but not when using JRoute. There is some uneeded parts to this as I have been doing some extensive testing though.

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

function GoFormsBuildRoute($query){
    $segments = array();
    $app        = JFactory::getApplication();
    $menu       = $app->getMenu();
    $params     = JComponentHelper::getParams('com_goforms');
    $db = JFactory::getDBO();
    if (empty($query['Itemid'])) {
        $menuItem = $menu->getActive();
        $menuItemGiven = false;
    }
    else {
        $menuItem = $menu->getItem($query['Itemid']);
        $menuItemGiven = true;
    }
    //print_r($menuItem);
    if(isset($query['option'])){
        unset($query['option']);
    }
    if(isset($query['view'])){
        $view = $query['view'];
    }else{
        return $segments;
    }
    unset($query['view']);
    if(isset($query['id'])){
        if ($menuItemGiven && isset($menuItem->query['id'])) {
            $mCatid = $menuItem->query['id'];
        } else {
            $mCatid = 0;
        }
        //echo 'hi';
        if(strpos($query['id'], ':') === false) {
            $db = JFactory::getDbo();
            $aquery = $db->setQuery($db->getQuery(true)
                ->select('alias')
                ->from('#__goforms_list')
                ->where('id='.(int)$query['id'])
            );
            $alias = $db->loadResult();
            $query['id'] = $alias;
        }
        $segments[] = $query['id'];
        unset($query['id']);
    }
    print_r($segments);

    return $segments;
}

function GoFormsParseRoute($segments){
    $vars = array();
    $app        = JFactory::getApplication();
    $menu   = $app->getMenu();
    $item   = $menu->getActive();
    $params     = JComponentHelper::getParams('com_goforms');
    $db = JFactory::getDBO();
    print_r($item);
    $count = count($segments);
    if($count == 1){
        if(isset($segments[0])){
            $vars['view'] = 'region';
            $alias = str_replace(':','-',$segments[0]);
            //print_r($alias);
            //echo '<br>';
            $query = 'SELECT alias, id FROM #__goforms_list WHERE alias = "'.$alias.'"';
            $db->setQuery($query);
            $page = $db->loadObject();
            if($page){
                $vars['view'] = 'region';
                $vars['id'] = (int)$page->id;
                return $vars;
            }else{
                $vars['view'] = 'goforms';
            }
        }else{
            $vars['view'] = 'goforms';
        }
    }
    return $vars;
}


?>

in review:

  • Joomla 2.5
  • component is at root menu item of site (home)
  • items from component need to fall under the first level of menu after home
  • links work, however JRoute class in joomla does not properly make the link.
tereško
  • 58,060
  • 25
  • 98
  • 150
Jordan Ramstad
  • 169
  • 3
  • 8
  • 37
  • Hi @REaction, I have a couple of ideas as to what may be the problem here but first, a couple of questions to clarify a few details:Is the component you speak of a custom extension? – JoomGuy Jun 28 '13 at 20:20
  • yes, I will add in the router.php file into this. – Jordan Ramstad Jun 28 '13 at 20:24
  • Is it written using joomla MVC 'standard'? 2 - What version of Joomla? Are you using SEF, mod_rewrite, .htaccess or any 3rd party SEF extension? Gez IGNORE *PS what do you mean, you'll "...add outer.php file into this"? IGNORE *I see now – JoomGuy Jun 28 '13 at 20:26
  • No, just been trying to use default joomla routing, nothing special. I want it to work without any dependency on other extensions. Just make the url site.com/page for every item in the component, so the component uses the home menu item and every page tries to be automatic from there. – Jordan Ramstad Jun 28 '13 at 20:29
  • OK, presumably J2.5, right? Hmmm, I seem to remember that when you set a component to the home (default) menu item, there is some tricky things to watch out for as far as routing links from the home page is concerned. – JoomGuy Jun 28 '13 at 20:33
  • OK, what does your a raw url to one of your pages look like? Is it something like /index.php?option=com_goforms&view=some_view&id=1 ? what is the default layout of your component - a list of all 'items' (products are they?)? – JoomGuy Jun 28 '13 at 20:43
  • Yea I am thinking since it is root its not normally "possible" so If there is joomla helpers or something to save custom menu utems, outside of the physical admin forms for it then I could call that and add each page to a menu item automatically, saving me the grief. I can force push it into the database, but there can be so many dependencies that I really hope there is a way to use the CMS functions rather then make my own. The default raw url is exactly as you said. The list for all is basically the root page, and is routed to the page from there. No they are forms built from regions. – Jordan Ramstad Jun 28 '13 at 20:44
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/32597/discussion-between-mybo-and-reaction) – JoomGuy Jun 28 '13 at 20:49
  • I don't understand what you mean when you say "component is i the root directory" since in Joomla there are no pages in directories there is just data in the database and the urls that give you the illusion of physical pages when in reality pages are based on queries. Are you basically using a web service? Are you storing data in your database? – Elin Jun 29 '13 at 01:48
  • basically a normal menu item will have "root.com/menu_item" and then there is 1 menu item that is "default" that is the root "root.com/" and that is the menu item I set the component to, however it looks for menu items first for the first level i think. – Jordan Ramstad Jun 29 '13 at 07:50

0 Answers0