40 Posts
yoyoxp
7 years ago
Topic

Hi all, 

I am trying to figure out the Seblod SEF Router. What I would like to do is build an SEF URL, based on the following properties: itemid, catid, id, (view=article). I would like the generated URL to be the same as the one Seblod SEF generated automatically (I have set Seblod SEF Router setting to 'parent/alias'). Is there any easy way to use the Seblod Router class to build a SEF URL based on the values that I have? What I have done is created a function under the content type/item view to show previous/next buttons. I use a DB query to find the previous and next article, and retrieve it's associated information. This works fine, but the URL rewriting does not. 

When I vardump the $query array (Seblod router.php), I get the following (one example): 

array(5) { ["view"]=> string(7) "article" ["catid"]=> string(25) "<cat_name>" ["id"]=> string(31) "<id>:<article-alias>" ["Itemid"]=> string(4) "<item-id>" ["option"]=> string(7) "com_cck" } 

Seblod will generate a link such as this (from the above): 

/<category-parent>/<category>/<article-alias>.html 

If I use JRoute::_ function, the URL generated by: 

JRoute::_('index.php?option=com_content&view=article&id='.$id.':'.$alias.'&catid='.$category.'&Itemid='.$menuitem) 

Will result in: 

/component/content/article/<parent-catid>-<parent-cat-name>/<cat-alias>/<content-id>-<content-alias>.html?Itemid=101 


This does 'work', but it changes itemid to be 101 (even though itemid is passed to JRoute, I have the menu item!), but also meta attributes (<title> tag) be that of the homepage. The most obvious problem is it very different to what Seblod generates.


The only way for this to work is to not use SEF urls for this request at all, which I would like to avoid doing. I've spent the last while now trying to figure out Seblods SEF routing code but to no avail. Am I missing something obvious here? Any help is appreciated :)


Thanks, 

Nick

Get a Book for SEBLOD
40 Posts
yoyoxp
7 years ago
5
Level 1

Well, I figured this out and will share the solution for those interested. It was actually rather simple. The Seblod Router.php will call a plugin based on the content being passed to it (e.g: joomla_article.php). Inside of joomla_article.php there is a static method: getRoute. (If you were looking up a user for e.g, there is another storage location plugin).

All you need to do is pass the Article ID, SEF number (figure this out from the source code) and itemid. For example, for a Joolmla Article type you would use: 

plgCCK_Storage_LocationJoomla_Article::getRoute(article-id, sef-id, itemid (menu-item)) 

Spent ages figuring this one out. Feel a bit silly now! 

Now I just need to find a way to get Seblods Router play nice on pages with non-Seblod content.. 

Cheers, 

Nick

4229 Posts
Kadministrator
7 years ago
4
Level 2

Thnx for sharing this, please cosider writing a short tutorial so that this ifo does not get lost in the forum threads.

40 Posts
yoyoxp
7 years ago
3
Level 3

Hi Klas,

I will do this when I get some free time. 

All the best

Nick

4229 Posts
Kadministrator
7 years ago
2
Level 4

You can just copy your forum post for the start :)

40 Posts
yoyoxp
7 years ago
1
Level 5

Cheers Klas,

It's created: https://www.seblod.com/resources/tutorials/how-to-generate-seblod-sef-url. For tutorial expanded it out a bit more. :)


Cheers,

Nick

6 years ago
0
Level 6

Hello Nick,

thanks for sharing this! That helped me a lot!

Papi

Get a VIP membership