What is app?
phpFox separates application structure to App, App provides new functions, gives new blocks that administrators put into template,
integrate phpFox with external platforms etc Amazon S3, and even modify the way phpFox platform works.
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 is creating a TodoList, it's a simple todolist application, allow members share to do lists.
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.
APP_ID is the name of your application
Describe App Structure
- Ajax: This directory contains Ajax handler classes
- 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.
In some cases, you will have to modify permissions of these folder to be able to put your code in them.
Write Your First Controller
Add new php class IndexController under directory ./PF.Site/Apps/TodoList/Controller/
paste example code.
Add new template file index.html.php under /PF.Site/Apps/TodoList/views/controller,
paste following code
Now we define route to define configurations, edit start.php, paste following code.
Open browse, in address bar append /index.php/to-do-list/, then see the result.
All your php classes must have namespace Apps\TodoList, This help the autoloader knows where to load scripts.
There is a rule of naming things: if you want to create a controller named Index, you should name the php file as IndexController.php in Start.php, the route should be book.index" the template file should be index.html.php (the first part of template file's name must be the same as the last part of the route - index)
Add Main Menu
Main menu will be added automatically by phpFox, edit Install.php,
update function setAlias
update function setOthers
In case you want to use a defined phrase for menu label, you can use the below script:
Then update your app to apply your modification. (how to update app configurations)
Another way to use defined phrases is using phrase.json file, see detailed document here
Open browser again, see result:
Buttons menu is handled by Template service, you can get template service from anywhere by using
Phpfox::getLib('template'), within controller, service you can invoke method template() to get the Template service.
pasted code into IndexController.php
Click on ADD TO DO, a not found page will be shown, The next chapter will guide you how to
create new controller to handle Add process, show input form about to do list task, store item to database.