Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

First, let's look over the file structure of an app: 

NameInfoNote
/Ajax/ajax functions 
/assets/Store static resources for app: JS, CSS, LESS, images ... 
/Block/Controller files of blocks 
/Controller/Controllers files 
/Installation/Installation files 
/Service/Service files 
/hooks/Support add hook for app (same as plugin of module). 
/views/HTML files to control the layout of each page. 
/app.jsonMain config file for each app.deprecated from 4.5.0
/app.lockApp is installed when this file exists. 
/start.phpFile is loaded on every page and is designed to be used to create routes. 
/phrase.json  
/icon.png  
/Install.php  


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.

To create an app, navigate over to the go to AdminCP -> Apps -> New App -> put your App on the popup -> Click submit. Then check the folder /PF.Site/Apps/. Create a folder called Sample. Navigate into that folder and create a file called app.json and open it up. Place the following content in it.

Code Block
{
   "id": "Sample",
   "name": "My Sample App",
   "version": 1,
   "icon": ""
}

This file is used to configure your app in different ways, which is covered in JSON Configuration. The JSON data we pasted in that file are the 4 required params your app must have in order to work.

Enabling Your App

By creating a folder in the /PF.Site/Apps/ folder with an app.json file, phpFox picks this up as an app that is almost ready to be loaded. However, without a file called app.lock it won't load it. So create a blank file called app.lock in your Sample/ app directory.{Your_App_ID}/, you will see some default files and folders there.

Bootstrap Your App

Our app at this point is ready to do something. phpFox is loading it, but it also needs to find your code. For this we have a bootstrap file called start.php. Each app comes with their own start.php, which is where all the base code is placed.

...

Code Block
<?php

/**
 * Create a namespace for your app and group all routes in it.
 */
group('/sample', function() {

   /**
    * Index route for your namespace.
    */
   route('/', function() {

      // Set the title
      title('Sample App');

      // Set a section title
      section('Sample App', '/sample');

      // Create a sub menu
      menu('/sample', [
         'Link 1' => url('/sample'),
         'Link 2' => url('/sample/link2')
      ]);

      // Create an action button
      button('Create', url('/sample/create'));

      // Place a block
      block(3, function() {

         // Load views/block.html
         return view('@Sample/block.html');
      });

      // Run a database query for some users
      $users = db()->select('*')
         ->from(':user')
         ->order('user_id ASC')
         ->limit(10)
         ->all>executeRows();

      // Load views/index.html
      return view('index.html', [

         // Assign users to the HTML template
         'users' => $users
      ]);
   });

});

...