0

I need to run a function in one of my module. This function is perfectly visible throughout my drupal site.

For one of my option, I have to run this function when colorbox loads. I have no idea which PHP file is called when the colorbox opens. I do know where the JS code is when colorbox opens, so what I did was this:-

...
...
inline:function(){
        $.get("sites/all/themes/my_theme/set_session2.php");
        return $.urlParam('inline', $(this).attr('href'));
      },
...
...

In this way, I can run a php file where I placed that function. Problem is that function is not visible in this PHP file.

Is there any way, I can get through this problem?

Best.

1 Answer 1

1

All php files inside drupal cannot be directly accessed by incoming request. You should create a endpoint for $.get which can be done by hook_menu

function mymodule_menu() {
  $items['mymodule/endpoint'] = array(
    'page callback' => 'mymodule_page_callback',
    'type' => MENU_CALLBACK
  );
  return $items;
}

function mymodule_page_callback() {
  module_load_includes('php', 'mymodule', 'set_session2');
  // call function here.
}

module_load_includes can include the php file you want from the module. So please place the php file inside the module folder.

In javascript, just update the url to the one you just defined.

...
...
inline:function(){
    $.get("/mymodule/endpoint");
    return $.urlParam('inline', $(this).attr('href'));
},
...
... 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.