Page tree

Versions Compared

Key

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

...

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 Define phrases on your app 
/icon.png Icon of your App 
/Install.php Main configurations for app. 


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, go to AdminCP -> Apps -> New App -> put your App on {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.

...

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.

In your Sample{Your_App_ID}app directory, create a file called start.php and paste the following content.

Code Block
languagephp
titlestart.php
linenumberstrue
<?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)
         ->executeRows();

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

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

});

...

We separate our HTML from our PHP code. Any HTML file loaded from your app will search for files in a folder views/ that we now need to create. In your Sample/ app folder, create a new folder called views. In that folder create a file called index.html. Paste the following content 

Code Block
languagexml
titleindex.html
linenumberstrue
<h2>Users</h2>
<ul class="sample_app">
{% for user in users %}
   <li>#{{ user.user_id }} - {{ user.full_name }}</li>
{% endfor %}
</ul>

...

Our app needs another HTML file called block.html. Create the file and paste 

Code Block
languagexml
titleblock.html
linenumberstrue
<div class="block">
   <div class="title">
      Sample Block
   </div>
   <div class="content">
      ...
   </div>
</div>

...