Hi , I am trying to create my own custom hook function to use in another modules. But it displays errors like “Warning: Missing argument 1 for access_hook_module_example_thingy() in access_hook_module_example_thingy() (line 17 of C:\wamp\www\Drupal\drupal_for_theme-7.22\sites\all\modules\access_hook_module\access_hook_module.module).”
What I did was,
1. I created module called hook_module.module. And then added below codes.
$my_var = 'some_var';
$data = module_invoke_all('example_thingy', $my_var);
drupal_alter('example_thingy', $my_var);
2. Again I created a module called access_hook_module.module to access the custom hook “'example_thingy”. And then I added below codes.
function access_hook_module_menu() {
$items['hook_access'] = array(
'title' => 'accessing hook module',
'description' => ' Accessing the hook module example_thingy',
'page callback' => 'access_hook_module_example_thingy',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implements hook_example_thingy().
*/
function access_hook_module_example_thingy(&$my_var) {
$my_var = 'foo';
return $my_var;
}
It displays errors. Anybody help me to fix this problem.
Comments
<?php $my_var = 'some_var';
Where?
What?
hi Jaypan, i try to create a
hi Jaypan, i try to create a custom hook function for other modules. i tried by using this website Creating custom hooks in Drupal and passing variables by reference. so i added below codes to define hook_name("example_thingy"). it is accessible in another modules by simply using MODULE_NAME_example_thingy().
I understand. But you didn't
I understand. But you didn't tell us where you put that code, or what the errors are, so we can't help with the information you've given.
i created a module called
i created a module called hook_module to define a hook_name function in it. and then i put these codes in it.
and then again i created a module called access_hook_module to test the created hook function outputs. so i added these codes below in it.
i want to pass variables by reference using access_hook_module_example_thingy(&$my_var) . when i run the above codes, it displays errors that Warning: Missing argument 1 for access_hook_module_example_thingy() in access_hook_module_example_thingy() (line 17 of C:\wamp\www\Drupal\drupal_for_theme-7.22\sites\all\modules\access_hook_module\access_hook_module.module).. how do i pass variables in "access_hook_module_example_thingy(&$my_var)" ?
<?phpfunction access_hook
hi, i tested your codes. It
hi, i tested your codes. It displays only hello. And then it displays errors like Warning: Missing argument 1 for access_hook_module_example_thingy() in access_hook_module_example_thingy() (line 23 of C:\wamp\www\Drupal\drupal_for_theme-7.22\sites\all\modules\access_hook_module\access_hook_module.module).
Notice: Undefined variable: my_var in access_hook_module_example_thingy() (line 24 of C:\wamp\www\Drupal\drupal_for_theme-7.22\sites\all\modules\access_hook_module\access_hook_module.module). .
<?phpfunction some_page(){
hi jaypan, i tested your
hi jaypan, it works correctly now. thank you very much for your good help.