By nomax5 on
Is there a really basic example - simple module or tutorial like an “Hello World” module?
One that says
Hello member
where the member is the name of the member and perhaps does a little php function to get the time or something?
Just something to get me started
Comments
Very simple module example
Very simple module example (no node type but only module which generate own page type after call own path). You need create directory hello_world in your modules directory and create file hello_world.module with this code inside... And enable hello_world.module in your module administration...
Usage - just call ?q=hello on your DRUPAL page...
--
My blog - Havran's mini-blog
My first drupal site - http://www.enigma.sk/
--
My site - Svoji.SK
My first Drupal site - http://www.enigma.sk/
wow did you just write that
wow did you just write that for me?
Thanks you Havran it's amazing how much I can work out from examples thats fantasic.
I am very new I've just discovered I can cut n paste my php into a story module - I didn't realise.
if you're still around and I could pick your brains a little...
what I usually do with php and forms is have a little bit of processing code that also does the confirm message
eg
The problem I have is: now I've put my code into a drupal story what or where do I point the form?
and in process.php where do I go back to?
I know my code is not very advanced I just typed it in for example purposes.
If you need create some
If you need create some forms in your page, you need study Drupal Form API - here is Quickstart guide - http://api.drupal.org/api/4.7/file/developer/topics/forms_api.html
You only need create array with your form elements and call
(Look at test_page() function - it is like hello_world_page() in my example).
How to validate and submit form - examples for this are in form quickstart guide too.
--
My blog - Havran's mini-blog
My first drupal site - http://www.enigma.sk/
--
My site - Svoji.SK
My first Drupal site - http://www.enigma.sk/
Clarity
Modules are not stories, nor are they blocks.
A module is a component of the underlying software. A story is a type of node (other types are blog, page, event, etc.) A block is an independent component that can be rendered at the same time as a node, or on overview pages.
Modules can define new node types, or they can directly provide content (such as a form) and interact with input through a GET or POST.
As you noted, Drupal does you paste PHP into a document (not a module) if you have permission. Typically you are pasting into the body of a node. So you can do what you ask, by pasting PHP into the body of a simple node type (such as page or story) and selecting the PHP filter, so your code will be evaluated.
Writing a module is a much better way.
In Havran's example, www.example.com/hello calls the function hello_world_page() to fire, since it is identified as a callback function in hello_world_menu().
There are examples in the developer documentation that provide details on how to do what you want. Click the link in the left rail corresponding to the version of Drupal that you use.
You can take shortcuts and paste PHP into documents but learning the "Drupal way" of doing things pays benefits in the long term.
I am going to do all the
I am going to do all the things you say and read the stuff
But I am doing some strange things with my forms and I’m wondering if they’re a little to strange
For instance I read all records on a table for a user and display them in a form, with a radio button on each one to select that record. The value of the radio button holds the record id so I can then present that record for edit etc.
Do you think it will be able to handle that sort of thing?
that was the only way I could think of passing the the relevant record id to process.php
that's not strange, put it in a module like this:
in a module called example, in example _form():
Handbook
Would you be willing to write this up for the handbook? Just find a likely spot and add a page. Adding some more comments aimed at total newbies would help as well.
Thanks,
Michelle
--------------------------------------
My site: http://shellmultimedia.com
I'm not very good in english
I'm not very good in english language. I give this oportunity someone with better ability in english. :)
--
My blog - Havran's mini-blog
My first drupal site - http://www.enigma.sk/
--
My site - Svoji.SK
My first Drupal site - http://www.enigma.sk/
Seems fine to me :)
Your English seems fine to me. Besides, grammar can always be corrected later. Even if you put the code you have and some text in the best English you can manage, that's a good start.
Michelle
--------------------------------------
My site: http://shellmultimedia.com
I've been making total
I've been making total newbie notes, so I can write a total beginners guide.
I was thinking of perhaps a tutorial to developing small website.
something like a DVD collection website, with a form a table and couple of pages.
step by step.
once I know what I'm doing and am confident with the code.
Also Havran, your english is fine mate.
That would be great!
Entry level docs are always great. By the time most people get to writing docs, they've been around enough that it's hard to remember the newbie perspective well.
Michelle
--------------------------------------
My site: http://shellmultimedia.com
Very useful example
Thanks for your simple module example. I only got it to print anything though after I changed the last function to:
But what I would really like to do is display the output within the themed page. I thought that could be achieved with the following function:
I have tried changing print to return without any success.
Any ideas?
Access denied (Drupal 6)
It can be a very frustrating experience that sometimes it works, and sometimes you can get an "access denied" page, while you didn't change anything.
Digging deeper I found out the "access" entry in the array items in the returned array from the hook_menu is wrong (at least for Drupal 6). In the end, to determine whether you are granted access, the final boolean result is stored in the "access" entry, but any value you give it here doesn't make it into the database table
menu_router, which is used at runtime, and so it is simply ignored. As a result, access is not granted — or it should be inherited from a higher level. (That's why it sometimes works anyway.)Instead, you have to use the key "access callback", which is usually used for a function name for the callback; but if the value is a number (or
trueorfalse) no function is called; instead, this value is used directly as the result.TL;DR: Replace
with
and Bob is a male relative.
hello_world.info in Drupal 5.x
Please do add a hello_world.info file as well if using it in Drupal 5.x, I was unable to get a listing on the module enable/disable page without it
Contencts of hello_world.info
--------snip------
name = hello_world
description = This description would be listed on module enable/disable page.
package = Core - optional
version = 1.0
--------snip------
doesn't seem to work in 6.x
i've tried this out a bunch of times. however, i always get an access denied error in 6.x. when trying to access http://example.com/hello
what is minimum definition of a module? in terms of functions etc. like if we had to write the module by implementing an abstract class what's the signature?
would love to have that kind of definition of a module.
6.x
check out the creating modules tutorial - a tad more indepth than this, but in the end, produces a working module and
help you understand how it all comes together
http://drupal.org/node/206753
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
Example
Hi,
You may use next example.
It is very easy for understanding.
Hello World for Drupal
See the page example module
See the page example module within http://drupal.org/project/examples
Hello World User Tab ...
http://drupal.org/node/188660#comment-5124326