I'm developing a Joomla 4 component, and I have issues to rewrite URL for the view Category.
In my site\src\Service\EventsNomenuRules.php I have this :
Code: Select all
public function parse(&$segments, &$vars)
{
//with this url: http://localhost/j4x/my-events/event-n/event-title.html
// segments: [[0] => event-n, [1] => event-title]
// vars: [[option] => com_rwlevents, [view] => rwlevents, [id] => 0]
$vars['view'] = 'event';
$vars['id'] = substr($segments[0], strpos($segments[0], '-') + 1);
array_shift($segments);
array_shift($segments);
return;
}
/**
* Build a menu-less URL
*
* @param array &$query The vars that should be converted
* @param array &$segments The URL segments to create
*
* @return void
*
* @since 3.4
*/
public function build(&$query, &$segments)
{
if (!isset($query['view']) || (isset($query['view']) && $query['view'] !== 'event') || isset($query['format']))
{
return;
}
$segments[] = $query['view'] . '-' . $query['id'];
// the last part of the url may be missing
if (isset($query['alias'])) {
$segments[] = $query['alias'];
unset($query['alias']);
}
unset($query['view']);
unset($query['id']);
}
And then, in the \site\src\Service\Router.php, I have this :
Code: Select all
public function __construct(SiteApplication $app, AbstractMenu $menu,
CategoryFactoryInterface $categoryFactory, DatabaseInterface $db)
{
$this->categoryFactory = $categoryFactory;
$this->db = $db;
$params = ComponentHelper::getParams('com_rwlevents');
$this->noIDs = (bool) $params->get('sef_ids');
$category = new RouterViewConfiguration('category');
$category->setKey('id');
$this->registerView($category);
$events = new RouterViewConfiguration('events');
$events->setKey('id');
$this->registerView($events);
$event = new RouterViewConfiguration('event');
$event->setKey('id');
$this->registerView($event);
parent::__construct($app, $menu);
$this->attachRule(new MenuRules($this));
$this->attachRule(new StandardRules($this));
$this->attachRule(new NomenuRules($this));
}
rwl-events/event-249/sortie-du-single-do-what-u-like
But for Category, I have this result :
rwl-events?view=category&id=11&alias=1991
How can i do to make other views work too ?
Thanks !