Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP - Why is there a function defined but not called

  • 08-06-2015 3:10pm
    #1
    Registered Users, Registered Users 2 Posts: 4,258 ✭✭✭


    I'm debugging code for a website and I have noticed that there is a particular function defined but I don't see where the function is called.

    I even did a grep on the whole site for the function but the only instance of it is in it definition.

    Here is the function:

    function salesforcedara_menu() {
    $items = array(
    'page callback' => 'salesforcedara_check_download',
    'page arguments' => array(3, 4),
    'access callback' => true,
    'type' => MENU_CALLBACK,
    );
    $items = array(
    'delivery callback' => 'ajax_deliver',
    ) + $items;

    $items = array(
    'page callback' => 'salesforcedara_start_download',
    'page arguments' => array(4,5),
    'access callback' => true,
    'type' => MENU_CALLBACK,
    );

    return $items;
    }


Comments

  • Registered Users, Registered Users 2 Posts: 1,206 ✭✭✭zig


    Maybe whoever wrote it decided not to use the function, or perhaps an update was done to the site and removed the need to call that function.


  • Registered Users, Registered Users 2 Posts: 241 ✭✭fcrossen


    Grep will not help if the function is called as a variable function - http://php.net/manual/en/functions.variable-functions.php

    Better off to add some logging to the function. Even if the function is never called, it might be someday, and removing it could leave you in a world of pain.


  • Registered Users, Registered Users 2 Posts: 2,032 ✭✭✭colm_c


    That looks like a drupal function, which takes the name of the module and puts _menu at the end of it when loading it, e.g. modulename_menu()

    See here:
    https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu/7

    So in your case it's handling requests to the following url patterns:

    support/download/file/nojs/*

    and

    support/download/file/start-the-download/*/*

    Whether to remove it or not is a different question.


  • Registered Users, Registered Users 2 Posts: 4,258 ✭✭✭swingking


    Just to give you an update on this , I have removed this and moved it to a menu_router table in the MYSQL database which does the same thing.

    The only problem I have now is that both URLs are calling the same function

    I need to have one button call this function with $nodevalue 267 and another button to call the same function with $nodevalue 275. How would I go about doing this ?

    Thanks



    function salesforcedara_page_build(&$page) {

    $nodevalue = '267';
    if (arg(0) == 'support')
    {
    $node = node_load($nodevalue);


    $page = array(
    '#weight' => 25,
    '#markup' => '<div id="dialog-message" title="'.$node->title.'" style="display:none">'.$node->body[LANGUAGE_NONE][0].'</div>',
    '#attached' => array(
    'library' => array(
    array('system', 'drupal.ajax'),
    array('system', 'ui.dialog')
    ),
    'js' => array(
    array('data' => drupal_get_path('module', 'salesforcedara') .'/js/script.js', 'type' => 'file' , 'scope' => 'footer')
    )
    )
    );
    }
    }


Advertisement