Sooperfish Cannot redeclare callback() error help please

Permalink
Hi there

The complete error I get is:

Fatal error. Cannot redeclare callback() (previously declared in /home/zoosp198/public_html/cms/blocks/autonav/templates/sooperfish/view.php.5) in /home/zoosp198/public_html/cms/blocks/autonav/templates/sooperfish/view.php on line 8

I know this error is usually two instances of sooperfish on the one page, but on all pages I do not receive this error UNLESS I am comparing two different versions of a page with the autonav block on. Is there anyway of fixing that? As I would imagine that a comparison between two page versions would of course have two instances of the menu on!

Please, any help?

 
Remo replied on at Permalink Reply
Remo
it's not a very clean solution but you could wrap the function to make sure it doesn't get declared again. Something like this:

if (!function_exists('your_callback_function')) {
    function your_callback_function() {
...
ScottC replied on at Permalink Reply
ScottC
Remo is correct - man i type that a lot :)

You could also move this function into your controller which associates it with an object(the block controller) and you wouldn't get this error since it is no longer a function in the global scope of concrete5, but simply wrapping it in a function_exists is really easy and painless :)
Remo replied on at Permalink Reply
Remo
Thanks Scott ;-)

Well, I think he uses the template I published on my blog (http://www.codeblog.ch/2011/12/concrete5-sooperfish-drop-down-navig... )

It's nothing else than a template, doesn't change the controller.. Which is why I think function_exists is the best way to go.
PomND replied on at Permalink Reply
Thank you for the reply, I'm slightly confused though as I'm somewhat new to php and C5.

I have gone into view.php in the autonav sooperfish block template and was about to wrap

function callback($buffer) 
{
  return (str_replace('class="nav"', 'class="sf-menu" id="nav"', $buffer));
}


with your if (!function_exists... bit

but I'm not sure what you mean by 'your_callback_function'? do I just write that as is, or am I meant to replace that with some id or something from the nav?

Thanks again for your help, and sorry for not understanding straight away.
Remo replied on at Permalink Best Answer Reply
Remo
that was just an example, go with this

if (!function_exists('callback')) {
    function callback($buffer) 
    {
        return (str_replace('class="nav"', 'class="sf-menu" id="nav"', $buffer));
    }
}
PomND replied on at Permalink Reply
Ohhh so that could have been anything I wanted?

Thanks for the help, it did the trick marvellously. I have a different error that says

Warning: system() has been disabled for security reasons in /home/zoosp198/public_html/cms/concrete/tools/versions.php on line 73

But I need to go to my host about that apparently and see if I can get system() function enabled to allow for python to start.

Thanks again!
ScottC replied on at Permalink Reply
ScottC
I understand, i've been there :)
if(!function_exists('callback')){
function callback($buffer) 
{
  return (str_replace('class="nav"', 'class="sf-menu" id="nav"', $buffer));
}
}
PomND replied on at Permalink Reply
Thanks, it's sorted now apart from a host problem which I'll speak to them about. Thanks for the help!