Note: You are currently viewing documentation for Moodle 3.8. Up-to-date documentation for the latest stable version of Moodle may be available here: NEWMODULE Tutorial.

Development:NEWMODULE Tutorial: Difference between revisions

From MoodleDocs
No edit summary
(Moodle 1.9 template added)
 
(21 intermediate revisions by 7 users not shown)
Line 1: Line 1:
How to begin the creation of a new module.
{{Template:Work in progress}}
{{New_Module}}


*choose a name for your module. Take care: no capital letter and no numbers in the name. In this example it will be choosen: "widget"
{{Moodle 1.9}}
*find/replace all the occorrences of newmodule in each file with the name of your own module
*change the name of the folder containing you new created module to "widget"
*change the name of the file in widget/lang/en_utf8/newmodule.php to "widget.php"
*put your just born widget folder in moodle/mod
*visit "notification" page of moodle->Site Administration block
*follow the instruction on the screen


== How to Begin the Creation of a New Module ==
# Choose a name for your module. Take care: no capital letter and no numbers in the name. In this example it will be choosen: "widget".
# Use a good text editor to perform a multi-file find/replace to change all occurrences of "newmodule" in each file with the name of your own module.
# Change the name of the folder containing your newly-created module to "widget".
# Change the name of file "widget/lang/en_utf8/newmodule.php" to "widget.php".
# Put your newly-created widget folder in moodle/mod/.
# Visit the Moodle "Notifications" page (in the Moodle->Site Administration block) to trigger installation of your module.
# Follow the instructions on the screen.
[[Image:widget.gif]]
== Some Basic Regulation for the Beginner PHP Developer ==
You will probably want to use this set of basic commands:
* require
* require_once
* include
* include_once
Take in mind the difference between them.<br />
* The difference between require and include is: '''require''' produces a fatal E_ERROR level error which halts execution if the specified file cannot be accessed, while '''include''' produces a warning (E_WARNING) which does not halt execution if the specified file cannot be accessed<br />
* The difference between '''require''' and '''require_once''' is: '''require_once''' checks if the file has been included and does not include it again if it has<br />
* The difference between '''include''' and '''include_once''' is: '''include_once''' checks if the file has been included and does not include it again if it has<br />
Use only xxx to call libraries and use only xxx to include snippets of code written to different files.<br />


== Some basic regulation for the beginning php developer ==
You will probably want to use this set of basic commands
- require
- require_once
- include
- include_once
Take in mind the difference between them.
The difference between require and require_once is: ???
The difference between include and include_once is: ???
Use only xxx to call libraries and use only xxx to include snippets of code written to different files.
Remember:
Remember:
- redirect move the execution of the code to the target file and you are allowed to call the target file passing it some parameters.
* '''redirect''' moves the execution of the code to the target file and you are allowed to call the target file passing it some parameters, for instance: <code php>redirect("./come_modello/edit.php?id=$cm->id");</code>
for instance:
* '''include''' requires the name of the called file to be "clean" (i.e., without "?id=$cm->id"), and the target file is executed as it were written in the place of the calling row.
redirect("./come_modello/edit.php?id=$cm->id");
 
You need this information to correctly include library files into target files called through '''redirect''' or '''include'''.


- include requires the name of the called file "clean", without "?id=$cm->id", for instance,
== See also: ==
and the target file is executed as it were written in the place of the calling row.
* [[Development:Blocks|A Step-by-step Guide To Creating Blocks]]


You need these two informations to correctly include library files into target files called through redirect or include.
[[Category:Developer]]
[[Category:Tutorial|{{PAGENAME}}]]

Latest revision as of 18:10, 8 March 2011

Note: This page is a work-in-progress. Feedback and suggested improvements are welcome. Please [ http://moodle.org/course/view.php?id=5 join the discussion on moodle.org] or use the page comments.


Template:New Module

Template:Moodle 1.9

How to Begin the Creation of a New Module

  1. Choose a name for your module. Take care: no capital letter and no numbers in the name. In this example it will be choosen: "widget".
  2. Use a good text editor to perform a multi-file find/replace to change all occurrences of "newmodule" in each file with the name of your own module.
  3. Change the name of the folder containing your newly-created module to "widget".
  4. Change the name of file "widget/lang/en_utf8/newmodule.php" to "widget.php".
  5. Put your newly-created widget folder in moodle/mod/.
  6. Visit the Moodle "Notifications" page (in the Moodle->Site Administration block) to trigger installation of your module.
  7. Follow the instructions on the screen.

widget.gif

Some Basic Regulation for the Beginner PHP Developer

You will probably want to use this set of basic commands:

  • require
  • require_once
  • include
  • include_once

Take in mind the difference between them.

  • The difference between require and include is: require produces a fatal E_ERROR level error which halts execution if the specified file cannot be accessed, while include produces a warning (E_WARNING) which does not halt execution if the specified file cannot be accessed
  • The difference between require and require_once is: require_once checks if the file has been included and does not include it again if it has
  • The difference between include and include_once is: include_once checks if the file has been included and does not include it again if it has

Use only xxx to call libraries and use only xxx to include snippets of code written to different files.

Remember:

  • redirect moves the execution of the code to the target file and you are allowed to call the target file passing it some parameters, for instance: redirect("./come_modello/edit.php?id=$cm->id");
  • include requires the name of the called file to be "clean" (i.e., without "?id=$cm->id"), and the target file is executed as it were written in the place of the calling row.

You need this information to correctly include library files into target files called through redirect or include.

See also: