Real Estate Listing Addon Tutorial

In this tutorial, we will be making a custom inventory database for real estate listing that you can install into PHP-Fusion 9.

Time to complete tutorial - Less than 1 hour.

In this tutorial, we will be discovering

**1. The basic of form handling in version 9 2. The basic of SQL query in version 9 3. Using PHP-Fusion utility functions such as theme and infusion components to assist you with development of this web application. 4. Basic concepts of MVCT. 5. The basics of locale in version 9 6. The basic SDK to follow to make your work into a custom infusion application package. 7. Coding it clean with proper coding standard

Lets get started.

First, we will need a name for our project. I'll have the liberty of naming this project for you, but feel free to customize it to your own name. For now, let's call this application - "property". So let's prepare the files as following for the most basic setup.

/property/
- /admin/
----- index.php
----- listing.php
- /locale/
----- index.php
----- English.php
- /images/
----- index.php
- /templates/
----- index.php
----- public.php
- view.php
- infusion.php
- infusion_db.php
- index.php

By placing index.php files in every folder, you will be disabling anyone from viewing your files directly via the browser. This is a very important thing that you must remember to do every time you create a folder. Please make it a habit!

Database Structure

Since the property listing will need to be stored somewhere, we will be using the primary MYSQL database as a medium for information data storage. Let's decide our table name and structure as following:

Table Structure
Infusion API
SQL
Table Structure

Name: property

Table Name

Type / Length

Remarks

property_id

BIGINT(20)

AUTO INCREMENT

property_name

VARCHAR(100)

NOT NULL

property_description

TEXT

NOT NULL

property_image

VARCHAR(200)

NOT NULL

property_thumb

VARCHAR(200)

NOT NULL

property_user

BIGINT(20)

UNSIGNED NOT NULL

property_datestamp

INT(10)

UNSIGNED NOT NULL

property_status

TINYINT(1)

UNSIGNED NOT NULL

property_access

SMALLINT(10)

NOT NULL

Infusion API

Refer to the Adding infusion package: Installer API section below for the file

SQL

You can click on the tab for the corresponding formats that can be used to build the table. I will not explain the SDK in general. Please read the Infusion SDK for more information on the API.

Defining Infusion Package

We'll begin by defining all the system variables and information defining the package that we will use in the rest of the addon project files in infusion_db.php

All infusion_db.php file in every folder within /infusions/ folder is automatically loaded by PHP Fusion. As such, there is no need to load this file in any file.

Installer API
Package Definitions
Locale file
Installer API
infusion.php
<?php
(defined("IN_FUSION")||exit);
// Package information
$inf_title = $locale["PROP_0100"];
$inf_description = $locale["PROP_0101"];
$inf_version = "1.0";
$inf_developer = "Your Name";
$inf_email = "your@email.com";
$inf_weburl = "https://your-url.com";
$inf_folder = "property";
$inf_image = "icon.svg";
// Define table structure
$inf_newtable[] = DB_PROPERTY." (
property_id bigint(20) unsigned not null auto_increment,
property_name varchar(100) not null,
property_description text not null,
property_image varchar(200) not null,
property_thumb varchar(200) not null,
property_datestamp int(10) unsigned not null default '0',
property_user bigint(20) unsigned not null default '0',
property_status tinyint(1) unsigned not null default '0',
property_access smallint(10) not null default '0',
PRIMARY KEY (property_id),
KEY (property_status)
) ENGINE = MYISAM;";
// Adds and remove administrative link
$inf_adminpanel[] = array(
"title" => $inf_title,
"image" => $inf_image,
"panel" => "admin/listing.php",
"rights" => $inf_rights,
"language" => LANGUAGE
);
// Drop table when uninstalling
$inf_droptable[] = DB_PROPERTY;

This file consists of package information in a standard variable required by the infusion installer system.

The $inf array defines table structure the data column structure for the installer to create table as defined.

Package Definitions
infusion_db.php
<?php
(defined("IN_FUSION")||exit);
// Define folder path constant
const PROPERTY = INFUSIONS."property/";
// Defines language folder path constant
const PROPERTY_LOCALESET = PROPERTY."locale/";
const PROPERTY_IMAGES = PROPERTY."images/";
// Defines The MYSQL table name constant
const DB_PROPERTY = DB_PREFIX."property";
set_property_locale();
// Function to add property locale file into system cache
function set_property_locale() {
// we begin with english
$locale = PROPERTY_LOCALE."English.php";
// find if current user language file is available.
if (file_exists(PROPERTY_LOCALE.LOCALESET.".php")) {
$locale = PROPERTY_LOCALE.LOCALESET.".php";
}
// define a constant
if (!defined("PROPERTY_LOCALE")) {
define("PROPERTY_LOCALE", $locale);
}
// add all variables of the file into the system locale
fusion_get_locale("", array(PROPERTY_LOCALE));
}

This file defines the CONSTANTS in the system and set the system locale.

Locale file
/locale/English.php
$locale["PROP_0100"] = "Property Estate";
$locale["PROP_0101"] = "Property Estate Listing Tutorial";
$locale["PROP_0200"] = "Property name";
$locale["PROP_0201"] = "Status";
$locale["PROP_0202"] = "Date";
$locale["PROP_0203"] = "Access";
$locale["PROP_0204"] = "ID";
$locale["PROP_0205"] = "Describe the property";
$locale["PROP_0206"] = "Hide property listing";
$locale["PROP_0207"] = "Show property listing";
$locale["PROP_0300"] = "Property has been updated.";
$locale["PROP_0301"] = "Property has been created.";
$locale["PROP_0400"] = "No property listing found.";

Administrative View

Now we will proceed to build the administrative interface. The following files are used to build the listing, and the form section for administrative users to manage the property listing in our addon package.

Generally we will require 2 components for an effective administrative view build for management of property estate listing:

/admin/listing.php
/locale/English.php
/admin/listing.php
/admin/listing.php
<?php
require_once __DIR__."/../maincore.php";
require_once THEMES."templates/header.php";
// List UI
function property_listing() {
$locale = fusion_get_locale();
}
// Property data
function get_property_data($id = 0) {
}
// Form UI
function property_form() {
$locale = fusion_get_locale();
}
require_once THEMES."templates/footer.php";
/locale/English.php
/locale/English.php
$locale["PROP_0100"] = "Property Estate";
$locale["PROP_0101"] = "Property Estate Listing Tutorial";

Guest and Member View