Writing Your First App
What is app?
phpFox separate application structure to App, App provide a new function, giving new blocks that administrators put into template,
integrate phpFox with external platforms etc Amazon S3, even modify the way phpFox platform work.
Creating a New App
The best way to get things started is to create a small app showing the most common API functions we use.
Our example create a TodoList, it's a simple todolist application, allow members share to do list.
To create an app, go to AdminCP -> Apps -> New App -> put YOUR_APP_ID on the popup -> Click submit.
Then check the folder /PF.Site/Apps/YOUR_APP_ID/, you will see some default files and folders there.
Describe App Structure
- Ajax: This directory contains Ajax handler classes
- assets: This directory contains raw assets such as the images, css, javascript, ...
- Block: This directory contains block classes
- Controller: This directory contains controller classes
- Service: This directory contains service classes
- hooks: This directory contains plugin scripts
- views: This directory contain template scripts
- phrase.json: This file declares language phrases
- icon.png: This is icon of your app
- Install.php: This file contains installation script of your app
- start.php: This file contains bootstrap scripts.
Write Your First Controller
Add new php class IndexController under directory ./PF.Site/Apps/TodoList/Controller/
paste example code.
...
All your php classes must have namespace Apps\TodoList, This help autoloader know where to load scripts.
...
Add Main Menu
Main menu will be added automatically by phpFox, edit Install.php,
...
Code Block | ||||
---|---|---|---|---|
| ||||
<?php protected function setAlias() { $this->alias = 'todo'; } |
update function setVersion()setOthers
Code Block | ||||
---|---|---|---|---|
| ||||
<?php protected function setVersionsetOthers() { $this->version = '4.1.0'; //add the menu for your app } |
update function setOthers
Code Block | ||
---|---|---|
php | php | <?php protected function setOthers() { $this->menu = [ "name" => "To Do List", // Menu label "url" => "/to-do-list", // Menu Url "icon" => "tasks" // Menu icons, see http://fontawesome.io/icons/ ]; } |
In case you want to use a defined phrase for menu label, you can use the below script
Code Block | ||||
---|---|---|---|---|
| ||||
<?php
$this->menu = [
"phrase_var_name" => "menu_to_do_list", // Var name for the phrease of menu
"url" => "/to-do-list", // Menu Url
"icon" => "tasks" // Menu icons, see http://fontawesome.io/icons/
];
|
Then update your app to apply your modification. revalidate-app.md
Open browser again, see result:
...