Page 1 of 1

Correct way / function / object to show a new Link?

Posted: Thu Jun 16, 2022 1:53 pm
by loop
Hi All
I want to make a link the right way, so it's also renamed from the addon name_based_url.
Is the correct way this:
$GLOBALS['Linker']->build('index.php?cPath=864_1920');

because the link is not changed to the "name_based_url" so probably I make something wrong...

edit:
I see when I use $GLOBALS['Linker']->build('index.php', ['cPath' => '864_1920']) then the rewrite works, but what should I do if I have "index.php?cPath=864_1920" saved in the MySQL DB?
Does it have a function to parse the parameter or do I have to do it myself and separate the file from the parameter manually to make this writing, like this?

Code: Select all

                $url_components = parse_url($c['advert_url']);
                parse_str($url_components['query'], $params);
                $inner .= '<a href="' . $GLOBALS['Linker']->build('index.php', $params) . '">';

Re: correct way / function / object to show a new Link?

Posted: Thu Jun 16, 2022 4:09 pm
by Kofod95
If you use the advert_fragment in the advert manager, you could just split it that way. If you have tons of adverts, that would of course be a pain, but could be automated.

//Daniel

Re: correct way / function / object to show a new Link?

Posted: Thu Jun 16, 2022 4:21 pm
by loop
thank you for your reply, but my question is more generel, how to handle the links especialy if the link is with parameter included

Re: correct way / function / object to show a new Link?

Posted: Thu Jun 16, 2022 4:46 pm
by burt
loop wrote: Thu Jun 16, 2022 1:53 pm $GLOBALS['Linker']->build('index.php', ['cPath' => '864_1920'])
Is the correct way, as you already found out.

If an addon does not work in the way you expect, it's best to try to solve it with the help of the addon maker.

Re: correct way / function / object to show a new Link?

Posted: Thu Jun 16, 2022 5:16 pm
by ecartz
loop wrote: Thu Jun 16, 2022 1:53 pm Does it have a function to parse the parameter or do i have to do it myself and separate the file from the parameter manually to make this writing, like this?

Code: Select all

$url_components = parse_url($c['advert_url']);
                parse_str($url_components['query'], $params);
                $inner .= '<a href="' . $GLOBALS['Linker']->build('index.php', $params) . '">';
Currently, there is a phoenix_parameterize function at https://github.com/CE-PhoenixCart/Phoen ... ut.php#L13

That takes a query string and breaks it up into the parameters array that Linker/Href expect. There's no function to split the query string from the rest of the URL, as that was never done internally. At the moment, you are welcome to use the phoenix_parameterize function. But you should expect it to go away after tep_href_link goes away. Because it is really just a helper function to transition from passing the query string to passing the parameters as an array.

Re: Correct way / function / object to show a new Link?

Posted: Thu Jun 16, 2022 5:26 pm
by loop
ok thank you all! that helped alot!