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

Open to all! Ask other shopowners for help.
Post Reply
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

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

Post 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) . '">';


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

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

Post 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
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

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

Post 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
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

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

Post 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.
I am not here to build for you.
I am here to build with you. Let's help each other.
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

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

Post 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.
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

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

Post by loop »

ok thank you all! that helped alot!


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply