Create your first page
To create a page in your plugin you will have to register the page in your plugin loader.php file and create the pager file inside the pages/ folder
So lets start
Inside your plugin loader.php file insert the following code in it
Let me explain the register_pager() function
- It takes two parameter the first one is the url slugs for example if you want your pager registeration to listen to url like this : http://www.yourdomain.com/test/plugin/page
- The second parameter is an array() that contains other information about the pager plugin, pager file and the function to call in the pager file to load the page content
- as: is a unique ID that you can use to create link to your pager at any time in your code for example : my link, NOTE: This example is use in views or template files
- use: This key contain info about the plugin name test the pager file mypage and the function to call in the pager file index_pager
So create a file at plugins/test/pages/ call it mypage.php and input the following code in the file
return $app->render(“Hello World!!”);
}
Save and visit the url by going to http://yourdomain.com/test/plugin/page
You should see the Hello world! in the browser and thats your first page in the plugin
Let me explain the code above
The function index_pager() was registered in our loader.php file in which if the url match the specified for the registeration this function will be called
and every pager function takes a parameter which is $app App class current instance
and in the function the return value will be use as the content of the page
So my pager function call a function inside the App class called render() which takes one parameter string
With this now you have created your first page in your plugin you can go on with other tutorials like how to add assets and hook into the system
Thanks for reading…
pRocrea8 Team