By phildog on
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
You need to tell drupal about the module in its _menu hook
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.
couldn't find any _menu hook
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.
_link
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.
Print
i.e.
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
----
Version dependency
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.
Thanks!
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:
"hello world" module still not working...
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?
access content
if (user_access('access content')) {...I reckon...
Slave to the Music
Another example, Drupal 6
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