Admin PHP MVC application ( APM )

Contact email dal_sto@yahoo.com

What's included

In upload folder you should have this structure on files and folders

Installation

Copy files from upload folder on your server. Visit yourdomainname/install link and follow required steps.

Update settings

After installation in main-config.php and admin/main-config.php you will have settings like this define('DATABASE_USER','root');
define('DATABASE_PASSWORD','');
define('DATABASE_SERVER','localhost');
define('DATABASE_NAME','apm');
define('DATABASE_DRIVER','pdo');
define('SYSTEM_FOLDER','system/');
define('DIF_FOLDER','front/');
define('DEVELOPMENT',0);

Change in this files if you set up other driver (mysqli) or other database username/password.

Files

Model files

Files in model folder with name name_of_the_file

Content of this files is class with name Modelname_of_the_file that have parent class Model

For example in model folder you have file book.php and class name will be class ModelBook extends Model

Controller files

Files in controller folder with name name_of_the_file

Content of this files is class with name A_name_of_the_file that have parent class Controller

For example in controller folder you have file book.php and class name will be class A_Book extends Controller

Index.php

Add new page in admin

  • Add new file in module folder admin/model with name name_of_the_file
  • This file should contain class with name Modelname_of_the_file
  • Write here functions. If function is for get/insert data from database use $this->db->query("sql_expression")
  • Add new file in controller folder admin/controller with name name_of_the_file
  • This file should contain class with name A_name_of_the_file
  • This class should contain function with name index
  • Load model in variable with function $this->model('name_of_the_model');
  • Access to function from model is variable_name->name_of_function
  • Put all data in variable $data

Add new page at front

  • Add new file in controller folder front/controller with name name_of_the_file
  • This file should contain class with name A_name_of_the_file
  • This class should contain function with name index
  • Load model in variable with function $this->model('name_of_the_model');
  • Access to function from model is variable_name->name_of_function
  • Put all data in variable $data
  • Create view file in front/view with name name_of_the_file.tpl
  • Load this file with $this->view('view/name_of_the_file.tpl', $data);

Add new layout

  • Add new layout in admin->layouts with name name_of_the_layout
  • In front/view file add this code on place where you want layout to be
    <?php foreach($this->extension->getExtensions('name_of_the_layout') as $extension){
    $this->addFrame($extension['name']);
    } ?>

Add new extension

  • Add new extension in admin->extensionts with name name_of_the_extension, page where you want to be at front(home, category,all..) and layout where should extension load (footer,top,bottom...)

Add new language

  • Add new folder in system/language front or admin with name name_of_the_folder
  • Add language in Admin->languages with code name same as name_of_the_folder
  • You can simply copy en folder and than translate all files inside

Configuration files

  • All configuration files are in system/config folder
  • You can add file in system/config folder
  • Content of this files are variables like this $_config['indx_name'] = 'value';
  • Load file in controller with $this->config->addFile('file_name')
  • Get configuration value with $this->config->indx_name in controller file

Delete item with warning

In list you will need to delete some item.

  • For that you have <?php echo $this->addFrame('modal');?> in footer.tpl file
  • Add <a href="#" data-href="<?php echo $item['delete_link'];?>" data-toggle="modal" data-target="#confirm-delete"><i class="fa fa-trash-o"></i></a>
  • Delete link should point to delete function from controller

Drivers

Application use drivers for connection to database. Drivers are classes that have same functions.

Name of function Explanation
query(sql) As argument this function have sql expression. Return array of data if is SELECT query. If is UPDATE or INSERT this function return 0
dbsafe(text) Return escaped value of text. For example if text is i'm it will return i\'m. It is used to prevent sql injection. Mysqli drver use real_escape_string.
select($table_name, $count=0, $start=0) It select data from table_name table.
total($table_name, $filter_array) Will return number of rows from table_name. $filter array have index column name and integer value
select_prepare($table_name, $columns, $filter_data, $count=0, $start=0) Execute prepared statement. $columns is for which columns you want to get from $table_name.Use * for all.$filter_array is array from arrays that have indexes column,value and type( for filtering )
insert($table, $columns, $values, $type = '') Execute prepared statement. Insert values for columns in $table
update($table, $columns, $values, $condition, $type = '') Execute prepared statement. Update values for columns in $table. Last element of $values array is id of row that is updated.
delete($table, $id, $condition) Execute prepared statement. Will delete row from $table with id = $id

Settings

If you set 1 for define('DEVELOPMENT',1); in main-config.php than you will see sql expressions and results

Change pagination, number of items in listings, default language in system/config/config.php