I'm trying to create a simple module that just prints "hello world" on a page (not block), and I'm having trouble. I've spent lots of time reading the /support section and the doxygen API stuff, but I seem to get more, not less, confused. So here I am...

Here's what I have:

"helloworld.module" contains:

<?php
function helloworld_page() {
	$output = "hello world";
	theme('page', $output, $main); 
	return;
}
?>

Then in: administration -> configuration -> modules

I checked "helloworld"

Then I navigate to:

http://mysite.com/drupal/helloworld

And I get:

"Page not found"

Can anyone help me get this up and running? I'm running 4.4.2. I'm comfortable enough with PHP to flesh out my module later but am still wrapping my head around the drupal framework.

thanks,

Phil

Comments

al’s picture

I could be wrong (been away from Drupal development for ages) but for CVS at least, I think you need to add a _menu hook. Check how other modules use that.

phildog’s picture

hm - I searched through all the .module files and couldn't find any containing the string "_menu" so I don't think that is it.

Steven’s picture

In 4.4, you need to use the _link hook to make Drupal aware of your page. You'll also need to print the theme output yourself. The return statement is not needed.

robert castelo’s picture

i.e.

print theme('page', $output);
return;

Also take a look at:

http://cvs.drupal.org/viewcvs/contributions/docs/developer/examples/

There's a page_example.module

------------------------------------------
Drupal Specialists: Consulting, Development & Training

Robert Castelo, CTO
Code Positive
London, United Kingdom
----

jonbob’s picture

Make sure you're looking at the right version of the page example module. APIs have changed between 4.3 and 4.4, and between 4.4 and HEAD. For 4.4, go to:
http://cvs.drupal.org/viewcvs/contributions/docs/developer/examples/page...

Please point out any documentation that was pointing you toward using the _page hook. That has not been supported since 4.3, and any documentation referencing it needs to be updated to reflect that.

phildog’s picture

JonBob - thank you! thank you! thank you! That link was exactly what I needed. If I come across old docs incorrectly referencing the _page hook I'll let you know.

For posterity, here is the content of my helloworld.module file:

<?php

function helloworld_helloworld() {
	$output = "hello world";
	print theme('page', $output); 
}

function helloworld_link($type) {
	if ($type == 'system') {
		if (user_access('access helloworld')) {
			menu('helloworld', 0, 'helloworld_helloworld', 0, MENU_HIDE);
		}
	}
}

?>
phildog’s picture

I just realized the code I posted above is still only working for logged-in users, which is not what I wanted.

Can anyone suggest a change that would allow it to work for any user, logged-in or not?

Dash’s picture

if (user_access('access content')) {

...I reckon...

Slave to the Music

kbahey’s picture

Another helloworld example for Drupal 6.

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba