Skip to content
rileywiebe edited this page Nov 2, 2011 · 25 revisions

First Application

After installing where do you start?

Framework Layout

The framework is split into two files, Application and System. System was built so that it doesn't need to be touched by the application creator to allow for updates, changes and new libraries to be added with less issues to the application.

You will be working in the Application directory which has the directory tree:


  • /cache
  • /general
  • /language
  • /template
  • /template_compile
  • /config
  • /libraries
  • /logs
  • /public
  • /controllers
  • /languages
  • /template

The directories you will focus on are /config, /public and /libraries.

Beginning

To begin you will want to set up all of the /config files so that your application runs as you expect. You can find information about configuring on the Configure page.

Many applications will use databases. To setup a database please reference Database.

Writable Directories

You must set the following directories to be writeable.

/application/cache/general

/application/cache/language and possibly /application/cache/en.php

/application/cache/template

/application/cache/template_compile

Paths

The framework formats paths to make mod_rewrite easy. The paths.php config file allows you to set the style and default locations to use.

Default Path

The default path is the name of the controller that will automatically run when your website starts. This is the index or homepage. The variable index corresponds with the controller index.php if you would like to change the default path you must have a controller that matches the new name.

Default Driver

The default driver is the method that will run when the controller is called an no other driver has been. The default value is main this means that when a controller has been called it will run the main method of that controller. If there is no default driver in the controller, and no other driver is specified, the error.php page will be shown. (The error.php page can be changed in paths as well.)

Public

The /public directory contains your controllers and template.

Basic Controllers

Controllers are used to build your application. Each application should have a controller and a driver method which matches what you set in your paths config file. Every controller will have a similar structure.

index.php


<?php
class index
{
    public function main()
    {
        // Your code here.
    }
}

The name of your class must be identical to the file name. So class index matches index.php

Loading Libraries

In order to utilize the most functionality of the framework you must load different libraries. To see documentation about all of the available libraries see the Libraries list.

There are two places to load a library, inside the method or inside the constructor. If you are using the same library for multiple methods it might benefit you to load it in the constructor.

Some libraries are static and an object does not need to be created, other need to be initialized as an object. FTemplate is a library that needs to be initialized as an object unlike FDatabase which doesn't.

example.php


<?php
class example
{
    private $template;
    
    public function __construct()
    {
        // Load Database library
        load::library('FDatabase');
        
        // Loading the FTemplate library
        load::library('FTemplate');
        
        $template = new FTemplate;
        
        // Initialize variable
        $this->template = $template->template();
    }
    
    public function main()
    {
        // Some Database query
        $sql = FDatabase::query('SELECT * FROM example');
        
        // Template utilizes Smarty so we need to call smarty while using template.
        $template->display('welcome.html');
    }
}

In the example the global variable $template is initialized in the constructor because we may want to use a template in multiple methods, and it saves time so we don't need to keep initializing it.

FDatabase was loaded in the constructor since we may want to use FDatabase in multiple methods so this allows us to only have to load it once. And because FDatabase contains static methods we do not need to use an object. Therefore you call methods using :: so to call a query you'd use FDatabase::query('');

Learn to make a basic Hello World application.

Clone this wiki locally