0

I have read https://docs.joomla.org/Supporting_SEF_URLs_in_your_component and looked at examples, i try to use in my component but something does not work: My router is:

<?php

    // No direct access
    defined('_JEXEC') or die;

    JLoader::registerPrefix('Courses', JPATH_SITE . '/components/com_courses/');


    class CoursesRouter extends JComponentRouterView
    {
        public function __construct($app = null, $menu = null) {

            $schoolscategory = new JComponentRouterViewconfiguration('schoolscategory');
            $schoolscategory->setKey('id');
            $this->registerView($schoolscategory);

            $course = new JComponentRouterViewconfiguration('course');
            $course->setKey('id')->setParent($schoolscategory, 'category');
            $this->registerView($course);

            parent::__construct($app, $menu);

            $this->attachRule(new JComponentRouterRulesMenu($this));
            $this->attachRule(new JComponentRouterRulesStandard($this));
            $this->attachRule(new JComponentRouterRulesNomenu($this));
        }


        public function getSchoolscategorySegment($id, $query) {            
             if (!strpos($id, ':')) {
                $db = JFactory::getDbo();
                $dbquery = $db->getQuery(true);
                $dbquery->select($dbquery->qn('alias'))->from($dbquery->qn('#__courses_schools_categories'))->where('id = ' . $dbquery->q($id));
                $db->setQuery($dbquery);

                $id .= ':' . $db->loadResult();
            }
            list($id, $segment) = explode(':', $id, 2);
            return array($id => $segment);
        }

        public function getCourseSegment($id, $query) {            
             if (!strpos($id, ':')) {
                $db = JFactory::getDbo();
                $dbquery = $db->getQuery(true);
                $dbquery->select($dbquery->qn('alias'))->from($dbquery->qn('#__courses_courses'))->where('id = ' . $dbquery->q($id));
                $db->setQuery($dbquery);
                $id .= ':' . $db->loadResult();               
            }
            list($void, $segment) = explode(':', $id, 2);
            return array($void => $segment);
        }

        public function getSchoolscategoryId($segment, $query) {            
             if (isset($query['id'])) {
                $db = JFactory::getDbo();
                $dbquery = $db->getQuery(true);
                $dbquery->select($dbquery->qn('id'))
                    ->from($dbquery->qn('#__courses_schools_categories'))
                    ->where('alias = ' . $dbquery->q($segment))
                    ->where('category = ' . $dbquery->q($query['id']));
                $db->setQuery($dbquery);
                return (int) $db->loadResult();
            }
        }

        public function getCourseId($segment, $query) {                   
            $db = JFactory::getDbo();
            $dbquery = $db->getQuery(true);
            $dbquery->select($dbquery->qn('id'))
                ->from($dbquery->qn('#__courses_courses'))
                ->where('alias = ' . $dbquery->q($segment))
                ->where('category = ' . $dbquery->q($query['id']));
            $db->setQuery($dbquery);
            return (int) $db->loadResult();      
        }

    }

but if i try to use jrouter: JRoute::_('index.php?option=com_courses&view=course&category=5:area-fiscalita&id=3:corso-oro-fiscalita-passato')

with slug for category "5:area-fiscalita" and slug for course "3:corso-oro-fiscalita-passato" get the url: corsi?view=course&category=5:area-fiscalita&id=3:corso-oro-fiscalita-passato

"corsi" is the item name in menu

instead of: corsi/nameOfCategory/nameOfcourse

like corsi/area-fiscalita/corso-oro-fiscalita-passato

why don't work?

thanks

  • 1
    This is the new Joomla router which you're using, and I haven't come across any questions like yours where people have been helped to reach a successful outcome. So yours may be the exception, but in the meantime I suggest you try and get your router working using the old method (ie using the parse() and build() methods). – Robbie Jackson May 29 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.