×
Please submit new Bug Reports on GitHub: github.com/Jensen-Technologies/component-creator-issues/issues
Joomla Router JComponentRouterView does not work
Francesco Reitano
Nieuw lid
Posts: 7
4 jaren 6 maanden geleden #9732
door Francesco Reitano
Joomla Router JComponentRouterView does not work werd gestart door Francesco Reitano
I try to use the new router system in a component, i have read 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)) {
$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));
$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));
$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
<?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)) {
$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));
$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));
$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
Gelieve Inloggen of een account aanmaken om deel te nemen aan het gesprek.
Carl Fuentes
Moderator
Posts: 23
4 jaren 5 maanden geleden #9734
door Carl Fuentes
Beantwoord door Carl Fuentes in topic Joomla Router JComponentRouterView does not work
Hi, Make sure you have all the code, I think you missed the function buildRoute and parseRoute in your codes. We have a builtin fully working Route when you use component creator. I suggest you further develop your custom route base on the one we provided.
Gelieve Inloggen of een account aanmaken om deel te nemen aan het gesprek.
Francesco Reitano
Nieuw lid
Posts: 7
4 jaren 5 maanden geleden #9735
door Francesco Reitano
Beantwoord door Francesco Reitano in topic Joomla Router JComponentRouterView does not work
Hi this is the code:
codeshare.io/2EEmMO
but in com_content example online is not buildRoute or parseRoute functions, and is not in the documentation.
In your route.php (in the component generated with component creator) you use the old system with functions build and parse.
In the documentation:
docs.joomla.org/Supporting_SEF_URLs_in_your_component
the new system it's different.
thanks for your help
codeshare.io/2EEmMO
but in com_content example online is not buildRoute or parseRoute functions, and is not in the documentation.
In your route.php (in the component generated with component creator) you use the old system with functions build and parse.
In the documentation:
docs.joomla.org/Supporting_SEF_URLs_in_your_component
the new system it's different.
thanks for your help
Gelieve Inloggen of een account aanmaken om deel te nemen aan het gesprek.
Carl Fuentes
Moderator
Posts: 23
4 jaren 5 maanden geleden #9738
door Carl Fuentes
Beantwoord door Carl Fuentes in topic Joomla Router JComponentRouterView does not work
The new method to work with router is new but not mandatory. If you want to use a different method, then you have to do it on your own.
We will try to help but can you show me what is the error showing? or result of your code.
We will try to help but can you show me what is the error showing? or result of your code.
Gelieve Inloggen of een account aanmaken om deel te nemen aan het gesprek.
Francesco Reitano
Nieuw lid
Posts: 7
4 jaren 5 maanden geleden #9739
door Francesco Reitano
Beantwoord door Francesco Reitano in topic Joomla Router JComponentRouterView does not work
no error! just don't make the parse, the url:
JRoute::_('index.php?option=com_courses&view=course&category=5:area-fiscalita&id=3:corso-oro-fiscalita-passato')
must transform in:
menuitem/area-fiscalita/corso-oro-fiscalita-passato
but give me:
menuitem?view=course&category=5:area-fiscalita&id=3:corso-oro-fiscalita-passato
i try with
JRoute::_('index.php?option=com_courses&view=course&category=5&id=3:corso-oro-fiscalita-passato')
without slug in category, but give me the same:
menuitem?view=course&category=5&id=3:corso-oro-fiscalita-passato
but the code is equal to com_content...
JRoute::_('index.php?option=com_courses&view=course&category=5:area-fiscalita&id=3:corso-oro-fiscalita-passato')
must transform in:
menuitem/area-fiscalita/corso-oro-fiscalita-passato
but give me:
menuitem?view=course&category=5:area-fiscalita&id=3:corso-oro-fiscalita-passato
i try with
JRoute::_('index.php?option=com_courses&view=course&category=5&id=3:corso-oro-fiscalita-passato')
without slug in category, but give me the same:
menuitem?view=course&category=5&id=3:corso-oro-fiscalita-passato
but the code is equal to com_content...
Gelieve Inloggen of een account aanmaken om deel te nemen aan het gesprek.
Francesco Reitano
Nieuw lid
Posts: 7
4 jaren 5 maanden geleden #9740
door Francesco Reitano
Beantwoord door Francesco Reitano in topic Joomla Router JComponentRouterView does not work
i check and the functions getCourseSegment and getSchoolscategorySegment are called.
Gelieve Inloggen of een account aanmaken om deel te nemen aan het gesprek.
Tijd voor maken pagina: 0.057 seconden