By tanepiper on
Hi there,
I'm developing my first D6 menu, having written a few D5 ones.
I'm trying to write the pages for outputting the data, but every time I try access the page I keep getting 'Access Denied', despite having the permissions set up (and I'm logged in as the Admin user).
Does anyone have any ideas where this is going wrong?
This is my current bit of code:
/**
* Implementation of hook_node_info().
*/
function contacts_node_info() {
return array(
'contacts' => array(
'name' => t('Qcall Contacts'),
'module' => 'contacts',
'description' => "Qcall Contacts allows you to manage your contacts to send messages",
)
);
}
/**
* Implementation of hook_help().
*/
function contacts_help($section) {
switch ($section) {
case 'admin/help#contacts':
return t('Qcall Contacts allows you to manage your contacts to send messages');
break;
}
}
/**
* Implementation of hook_perm().
*/
function contacts_perm() {
return array('create contacts', 'read contacts', 'update contacts', 'administer contacts');
}
/**
* Implementation of hook_load
*/
function contacts_load($node) {
$extra_fields_query = db_query("
SELECT contact.contact_id,
contact.contact_surname,
contact.contact_firstname,
contact.contact_email,
contact.contact_number_id AS default_number_id,
contact_number.contact_number AS default_number
FROM {contacts} contact
LEFT JOIN {contacts_numbers} contact_number
ON contact_number.contact_number_id = contact.contact_number_id
WHERE contact.nid = %d
ORDER BY contact.contact_surname ASC", $node->nid);
$extra_fields = db_fetch_object($extra_fields_query);
return $extra_fields;
}
/**
* Implementation of hook_menu().
*/
function contacts_menu() {
$items = array();
/* Normal Drupal Forms */
$items['contacts'] = array(
'title' => 'Your Contacts',
'description' => 'A list of all your contacts',
'page_callback' => 'contacts_read',
'access arguments' => array('read contacts'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implementation of hook_form().
*/
function contacts_form(&$node) {
$type = node_get_types('type', $node);
// We need to define form elements for the node's title and body.
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -5
);
// We want the body and filter elements to be adjacent. We could try doing
// this by setting their weights, but another module might add elements to the
// form with the same weights and end up between ours. By putting them into a
// sub-array together, we're able force them to be rendered together.
$form['body_filter']['body'] = array(
'#type' => 'textarea',
'#title' => check_plain($type->body_label),
'#default_value' => $node->body,
'#required' => FALSE
);
$form['body_filter']['filter'] = filter_form($node->format);
// NOTE in node_example there is some addition code here not needed for this simple node-type
return $form;
}
function contacts_read() {
global $user;
$output = '';
$path = drupal_get_path('module', 'contacts') .'/templates';
$contact_query = db_query("SELECT nid FROM {node} WHERE type='%s' AND uid=%d", 'contacts', $user->uid);
if ($contact_query) {
while ($contact = db_fetch_object($contact_query)) {
$node = node_load($contact->nid);
$output .= '<tr>';
$output .= '<td>';
$output .= $node->contact_surname;
$output .= '</td>';
$output .= '<td>';
$output .= $node->contact_firstname;
$output .= '</td>';
$output .= '<td>';
$output .= $node->contact_email;
$output .= '</td>';
$output .= '<td>';
$output .= $node->default_number;
$output .= '</td>';
$output .= '<td>';
$output .= $node->body;
$output .= '</td>';
$output .= '<td>';
$output .= '</td>';
$output .= '</tr>';
}
} else {
$output .= '<tr>';
$output .= '<td colspan="6"><strong>You have no contacts to load</strong></td>';
$output .= '</tr>';
}
$template = file_get_contents($path . '/contacts_list.html');
$template = str_replace('#tbody_content#', $output, $template);
return $template;
}
Comments
Similar Issue
I'm writing a module and having a similar issue, so I'd like to know what you find out (if anything).
Also, instead of sticking HTML elements into your output (especially to create a table), you can use theme_table to output your results.
In the end, my problem was i
In the end, my problem was i had 'page_callback' instead of 'page callback' in my array and it fixed my issues.
Thanks!
You helped me realise that I had 'access_arguments' instead of 'access arguments'!
I had BOTH of those issues,
I had BOTH of those issues, thank you for coming back here and replying!