rosuandreimihai Posted May 17, 2016 Share Posted May 17, 2016 Hi all, I am developing a dynamic CMS page. So I have to create a custom function for building up the link to those pages in class Link.php. The function looks something like the one below Could someone tell me why the $link->getVirtualPageLink() inside a *.tpl file throws error like PHP Fatal error: Call to a member function getVirtualPageLink() on string in The complete smarty code used for the function below is: {foreach $vPages as $page} <li> {assign var="link" value="flowers-{$page.country}-{$page.city}.html"} {assign var="id_link" value="{$link->getVirtualPageLink('8',$page.id_country,$page.city)}"} {assign var="meta_title" value="Flowers in {$page.country} - {$page.city}"} <a style="color:normal" href="{$id_link|escape:'html':'UTF-8'}" title="{$meta_title|escape:'html':'UTF-8'}"> {$meta_title|escape:'html':'UTF-8'} </a> </li> {/foreach} public function getVirtualPageLink($cms, $id_country, $city, $alias = null, $ssl = null, $id_lang = null, $id_shop = null, $relative_protocol = false) { if (!$id_lang) { $id_lang = Context::getContext()->language->id; } $url = $this->getBaseLink($id_shop, $ssl, $relative_protocol).$this->getLangLink($id_lang, null, $id_shop); $dispatcher = Dispatcher::getInstance(); if (!is_object($cms)) { if ($alias !== null && !$dispatcher->hasKeyword('cms_rule', $id_lang, 'id_country', $id_shop) && !$dispatcher->hasKeyword('cms_rule', $id_lang, 'city', $id_shop)) { return $url.$dispatcher->createUrl('cms_rule', $id_lang, array('id' => (int)$cms, 'rewrite' => (string)$alias), $this->allow, '', $id_shop); } $cms = new CMS($cms, $id_lang); } // Set available keywords $params = array(); $params['id'] = $cms->id; $params['rewrite'] = (!$alias) ? (is_array($cms->link_rewrite) ? $cms->link_rewrite[(int)$id_lang] : $cms->link_rewrite) : $alias; $params['id_country'] = ''; $params['id_country'] = $id_country; $params['city'] = ''; $params['city'] = $city; return $url.$dispatcher->createUrl('cms_rule', $id_lang, $params, $this->allow, '', $id_shop); } Link to comment Share on other sites More sharing options...
roja45 Posted May 17, 2016 Share Posted May 17, 2016 {assign var="link" value="flowers-{$page.country}-{$page.city}.html"} Link to comment Share on other sites More sharing options...
rosuandreimihai Posted May 17, 2016 Author Share Posted May 17, 2016 Well, that would be the easiest solution ever, right? But, how do you use the city and country from the link? Because, as I said it will be a dynamic CMS page that will use the id's for the country and for the city.That was my first option but as I wanted to have the params also I had to build a custom link function Do you know how can I achieve that? Thanks! Link to comment Share on other sites More sharing options...
roja45 Posted May 17, 2016 Share Posted May 17, 2016 it may certainly win an award for having the answer most closest to the problem.. not entirely sure what you mean, but I don't see the assigned 'link' being used in that foreach block so why do you have it there. The object link, you need to be able to call that method, will have been assigned in the controller, or you module, whatever you are using. Link to comment Share on other sites More sharing options...
rosuandreimihai Posted May 17, 2016 Author Share Posted May 17, 2016 I purposely left the first assignment, the one you also mentioned just to be sure that everybody sees that I don't want that I will have a page with a lot of links just like /flowers-country-city.html, but when accessing them I want to be able to pull out the params city and country, crucial for the cms page So, I have made an override for the Link,php class and added a new function getVirtualPageLink, function similar to getCMSLink. The question is why am I getting that error, or how should I approach this task? Thank you again, Mihai Link to comment Share on other sites More sharing options...
erouvier29 Posted May 18, 2016 Share Posted May 18, 2016 (edited) As roja45 said, you're getting an error because you re-assigned a string to the smarty variable $link (it is normally initially assigned with a Link object by the FrontController). Remove the line {assign var="link" value="flowers-{$page.country}-{$page.city}.html"} and it should work. Edited May 18, 2016 by erouvier29 (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now