Custom module development :-
Hi all, today i am gonna show you how you can create a simple "hello world" module in pyrocms. You can do so by following some simple steps mentioned in this article.Here are these steps,
1. download pyrocms package from pyrocms website and install it in your wamp\www directory.
2. Next create a folder "helloworld" in \www\pyrocms\addons\shared_addons\modules\
3. As pyrocms is based on codeignitor which is php framework and using MVC ( model, view, controller ) architecture, so each pyrocms module will have these folders in it. So create "controllers", "models" and "views" folders in "helloworld" folder.
After that our module directory will look something like this,
4. Next create details.php in your module's same directory. details.php file contains all the information about module like its version, title, description etc. This file also contains functions to install, uninstall and upgrade the module. In our case details.php file will look like this,
<?php
class Module_HelloWorld extends Module {
public $version = '1.0';
public function info(){
return array(
'name' => array(
'en' => 'Hello World',
),
'description' => array(
'en' => 'This is a Hello World Module.',
),
'frontend' => TRUE,
'backend' => FALSE,
'menu' => 'content'
);
}
public function install() {
return true;
}
public function uninstall(){
return true;
}
public function upgrade($old_version){
// Your Upgrade Logic
return TRUE;
}
public function help(){
// Return a string containing help info
// You could include a file and return it here.
return "No Help";
}
}
?>
Simply copy/paste and save this code in your details.php file.
5. Next create a file called "helloworld.php" in controllers folder and put following code in it,
<?php
class HelloWorld extends Public_Controller {
public function __construct(){
parent::__construct();
}
function index() {
$this->data->displayMessage = "Hello World";
$this->template->build('display',$this->data);
}
}
?>
This file is the controller file of your module and will have the same name as your module name. You can notice that this class is extending "Public_Controller" class because this module is for front-end. If you want to put some logic for admin then you have to extend "Admin_Controller" class. In our case no need to do so.
6. Next create display.php file in views folder and put following code in it,
<?php
echo $displayMessage;
?>
That's it. Now you can test your module by running the url like this (this url is in my case),
http://localhost/pyrocms/index.php/helloworld
This is the simplest explanation of how to create a new module in PyroCMS, and it gets to the point.
ReplyDeleteThanks and keep it up
thanks dear
Deletethanks Asad, very nice tutorial. look forward to more of these.
ReplyDeletei have got some error during the module install or running the module in the browser.
ReplyDeleteA PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at E:\xampp\htdocs\pyrocms\addons\shared_addons\modules\helloworld\details.php:33)
Filename: drivers/Session_cookie.php
This may be because of some error before redirecting or may be you have white space in start of file before <?php tag. So check you files for that most probably in all files of this module or index files of your project
DeleteHi Asad, Can you help me out how to integrate my own module into pyrocms running project, and i want to run whole pyrocms running project on my localhost
ReplyDeletei have a problem it says :page missing
ReplyDelete