I have created a new module. In the module, I called hook_menu() like this:

function questionnaire_menu()
{
	$items = array();
	$items['questionnaire'] = array
	(
		'title' => t('Questionnaire'),
		'description' => t('Description goes here'),
		'page_callback' => 'questionnaire_get_form',
		'type' => MENU_CALLBACK,
	);
	return $items;
}

However, when I access the page after installation, I get 'You are not authorized to access this page.', even though I am user 0 and should be able to see all pages. Does anybody know how to fix this?

Comments

jaypan’s picture

I should add that I have also tried this:

function questionnaire_menu()
{
	$items = array();
	$items['questionnaire'] = array
	(
		'title' => t('Questionnaire'),
		'description' => t('description'),
		'page_callback' => 'questionnaire_get_form',
		'access arguments' => array('access content'),
		'type' => MENU_CALLBACK,
	);
	return $items;
}

And I get the same error.


Contact me to contract me for D7 -> D10/11 migrations.
Or anything really. I'm friendly, and open to work or conversation.
jaypan’s picture

Sorry, I made a mistake in the title of the thread. It should be 'user 1'. I am logged in as the master user, and am getting the error message.


Contact me to contract me for D7 -> D10/11 migrations.
Or anything really. I'm friendly, and open to work or conversation.
gpk’s picture

I assume you are using D6.

Yes IIRC if you specify neither access callback nor arguments then access will always be denied. It is only in function user_access() that user ID 1 gets allowed through. http://api.drupal.org/api/function/user_access/6 http://drupal.org/node/109584#comment-862027

Having modified the menu structure defined by your module you then need to clear the menu cache for your changes to take effect ...

You prob
gpk
----
www.alexoria.co.uk

jaypan’s picture

Thank you GPK. You are correct, I am using 6.x. I forgot to check that off when creating the thread.

I tried clearing the cache, but still got the same error. So I actually recreated the module under another name to see if it was just a caching problem, but I still got the same error.

The code I am using now is this:

function questionnaire_menu()
{
	$items = array();
	$items['questionnaire'] = array
	(
		'title' => t('Questionnaire'),
		'page_callback' => 'questionnaire_get_form',
		'access callback' => 'user_access',
		'access arguments' => array('access content'),
		'type' => MENU_CALLBACK,
	);
	return $items;
}

Any ideas? Thanks again for your assistance.


Contact me to contract me for D7 -> D10/11 migrations.
Or anything really. I'm friendly, and open to work or conversation.
jaypan’s picture

I got it to work somehow. I don't know what was wrong, but I just wiped it clean and started from scratch, and it works this time.


Contact me to contract me for D7 -> D10/11 migrations.
Or anything really. I'm friendly, and open to work or conversation.
gpk’s picture

Glad it's working now. :)

gpk
----
www.alexoria.co.uk

almul0’s picture

Hi, in your code you named a key as' page_callback' where in reality is 'page callback', without the underscore.