Welcome to Maya

Database centered PHP Framework

Maya Get Started

Develop Websites in 3 Easy Steps

img

1. Design your database

This should follow specific maya db rules in order for automatic generate of mvc to work.

read more
img

2. Generate MVC Automatically

Using the database tables, Maya can generate automatically the model, view and controller.

read more
img

3. Override Generated Codes

To customize your application you need to override generated codes.

read more

Installation

note: This assumes that you have basic knowledge of installing web servers with php support such as apache,nginx,lighttpd etc. Therefore the installation assumes you have a mysql db and php support already installed.

1) Download or clone the files from https://gitlab.com/efabian/maya.git and make sure you put it in your server

2) You may rename the 'maya' folder to your desired application directory.

3) Open the file config/database.cfg.php and change the database host $this->host = "localhost", database name $this->name = "[db name]", user name for db $this->user = "root" and password for db $this->password = "[db password]";

4) If needed you may change the default roles needed by your users at app/model/Role.php by overriding the default roles of user and admin.

5) If needed you may also change the extensions or files that will be ignored by the auto menu generation of maya at app/model/MayaModel.php using the $this->file_filters="".

Now you are ready to design the db tables

Methods to load test db data

1) If you want to try the sample db data, first fill the $db->host, $db->name, $db->user, $db->password at config/database.cfg.php first with the right data. Then go to util directory and execute

php init_sample_db.php
or point your browser to your [server path]/util/init_sample_db.php.

This will create the database tables described below and an initial user with email=maya.admin@gmail.com and default password=maya

Initializations

  • Rename the cloned maya to a folder of your project name
  • Download an html template that you want to be your main theme.
  • Rename the index.html file to index.php and place inside the [project] folder.
  • Copy all the images from the template into [project]/images
  • Copy all the css from the template into [project]/mages
  • Open the [project]/config/paths.cfg.php and make sure replace the field $this->home with the intended home $this->home = home.pub.htm

Step 1. Design Database

Sample users table

fieldtypedescription
idunsigned intPrimary key
firstnamevarcharFirstname of the user
lastnamevarcharLastname of the user
roleint Integer values corresponding to certain user roles tied to their rights. A value 0 is always the default assigned rule typically for unauthenticated user. Higher values means higher rights. Details of rights are defined in app/model/Role.php.
saltvarcharSalt in hashing the password
passwordvarcharHashed password
createdtimestampDefaults to timestamp as db insertion

Sample configurations table

fieldtypedescription
idunsigned intPrimary key
namevarcharName of this configuration
valuevarcharValue of this particular configuration
descriptionvarcharDescription of this subject
createdtimestampDefaults to timestamp as db insertion

Sample subjects table linked to users

fieldtypedescription
idunsigned intPrimary key
namevarcharName of this subject
descriptionvarcharDescription of this subject
user_id_teacherunsigned intThis is a foreign key from the 'users' table, which will be named/labeled 'teacher' in tables and inputs
statusunsigned intactive=1 or not_active=0
createdtimestampDefaults to timestamp as db insertion

Sample enrolees table linked to users and subjects

fieldtypedescription
idunsigned intPrimary key
subject_idunsigned intThis is a foreign key pointing to the subjects table
users_ids_enrolleesunsigned intAn array of enrollee id pointing to the users table
createdtimestampDefaults to timestamp as db insertion

Rules in db creation.

1) All names of database table names must be in small letters and plural form. For example users, billboards, subjects etc. This is because the model created by the generateModel.php utility will be singular.

2) Foreign key relation shall be linked according to the name of the field for example 'user_id_teacher' means an id that points to the a user in the 'users' which is named as 'teacher'. Setting of foreign key relation in db is not required.

3) Foreign key relation n to n relation shall be linked according to the name of the field but plural form such as 'users_ids_enrollees'. This means any number of users id (array) that points to users in 'users' table that should be named 'enrollees' in tables and forms.

4) All tables should have an 'id' as a primary key which must be an unsigned integer.

5) All fields must be in small letters like id, name, description etc.

6) All maya projects should have at least configurations and users tables.

7) The configurations table should at least have one entry configuration.name='domain' configuration.value='' without http:// or https:// like www.gahum.com or docph.net

Step 2. Generate Model, View, Controllers

Generate Model

1) Open your linux terminal

2) Go to ../util folder

3) run 'php generateModel.php (table name) [link_image]

For example 'php generateModel.php users link_image', if the users table exist, this command will generate three files namely ../usr_generated/model/UserProtected.php, ../usr_generated/model/UserPublic.php and ../usr/model/User.php . The ../user/model/User.php includes a User class that will extend the UserProtected class at ../usr_generated/model/UserProtected.php/. The UserProtected class will contain all the get and set methods to access the db fields.

Generate Controllers

1) Open your linux terminal

2) Go to ../util folder

3) run 'php generateController.php (table name) [link_image] [login_register]

For example 'php generateController.php users link_image login_register', if the users table exist, this command will generate two files namely ../usr_generated/controller/MayaUsersController.php, and ../usr/controller/UsersController.php . The ../usr/controllers/UsersController.php includes a UsersController class that will extend the MayaUsersController class at ../usr_generated/controller/MayaUsersController.php/. The UsersController will no longer be generated if it already existed to prevent ovewriting user codes.

link_image is an optional parameter to include uploadImageAction()

login_register is an optional parameter to include loginRestAction and registerRestAction which are only applicable for users table

Generate View

1) Open your linux terminal

2) Go to ../util folder

3) run 'php generateView.php (table name) [link_image] [login_register]

For example 'php generateView.php users link_image login_register', if the users table exist, this command will generate several files namely

  • [admin dir]/Users.dir/List Users.rest.php - Created if it does not currently exist and simply includes ../usr/view/users/list_users.rest.php
  • [admin dir]/Users.dir/Edit User.hid.rest.php - Created if it does not currently exist and simply includes ../usr/view/users/edit_user.rest.php
  • [admin dir]/Users.dir/New User.rest.php - Created if it does not currently exist and simply includes ../usr/view/users/new_user.rest.php
  • usr/view/users/list_users.rest.php - Created if it does not currently exist and simply includes ../usr_generated/view/users/list_users.maya.php
  • usr/view/users/edit_user.rest.php - Created if it does not currently exist and simply includes ../usr_generated/view/users/edit_user.maya.php
  • usr/view/users/new_user.rest.php - Created if it does not currently exist and simply includes ../usr_generated/view/users/new_user.maya.php
  • usr/view/UserView.php - Created if it does not currently exist and simply extends ../usr_generated/view/UserViewBase.php
  • usr_generated/view/UserViewBase.php - Always generated based on table and performs rendering functions for list,edit and new pages
  • usr_generated/view/users/list_users.maya.php - Always generated based on table and is the primary template html for displaying the list of users
  • usr_generated/view/users/edit_user.maya.php - Always generated based on table and is the primary template html for showing the edit user form
  • usr_generated/view/users/new_user.maya.php - Always generated based on table and is the primary template html for showing the new user form

You should only edit files within usr/view folder.

link_image is an optional parameter to include uploadImageAction() view support

login_register is an optional parameter to include login and register view support

Step 3. Modify generated code to fit your needs

Folder Structure

  • index.php (edit) Main structure of each page
  • home.php (edit) Content of home page
  • config (edit) Contains configuration files
    • paths.cfg.php
    • database.cfg.php
    • security.cfg.php
  • app (edit) MVCs that extends the core maya MVCs
    • model
      • MayaModel.php
      • MenuElement.php
      • Role.php
    • view
    • controller
    • Maya.php
  • usr (edit) MVCs that extends the core generated models from tables
    • model
    • view
    • controller
    • view_bak
    • uploads (files uploaded by the MVC above will be placed here)
  • Admin.dir (edit) Admin's List, View, Edit interface for all tables
    • Users.dir
      • List Users.rest.php - includes usr/view/users/list_users.rest.php
      • Edit User.hid.rest.php - includes usr/view/users/edit_user.rest.php
      • New User.rest.php - includes usr/view/users/new_user.rest.php
    • [Other Tables]
  • css (edit)
  • js (edit) For jquery and javascript plugins
  • lib (edit) For php plugins
  • images (edit) Images needed by developer for website.
  • img (edit) Images default to maya
  • usr_generated (do not edit) Generated MVC from tables
    • model
    • controller
    • model_bak
    • controller_bak
  • maya (do not edit) Core MVC of maya
    • model
    • view
    • controller
  • util (do not edit) Utilities for generating MVCs from tables

Rules which files should be edited

1) Files from index.php down to the images are the files that can be edited

2) Foldes from img,usr_generated,maya and util should not be edited

3) usr_generated are files automatically generated by the utilities which will be discussed later.

Modify Basic Structure of Page

The index.php determines the basic structure of the page. You can basically placed maya in any html theme structure.

Quick Summary of Process to Integrate Maya into a theme index.php

1. Call the core maya files and instatiate core objects on top of the file

2. Call the maya framework to load css/jquery inside the header section of the html

3. Configure menu based on login conditions

4. Render hidden login form and notice form after the menu section

5. Prepare the div.page where to display the dynamically loaded pages

6. Call display controller and all other javascript before the end marker of the html body section.

A very simple structure is shown below:

<?php
session_start
();
ini_set('display_errors''On');
error_reporting(E_ALL E_NOTICE E_WARNING); 

require_once 
'maya/Maya.php';
$maya = new Maya();
$role= new Role();

?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Maya Framework</title>
  <meta content="width=device-width, initial-scale=1.0" name="viewport">
  <meta content="" name="keywords">
  <meta content="" name="description">

  <!-- Favicons -->
  <link href="img/favicon.png" rel="icon">
  <link href="img/apple-touch-icon.png" rel="apple-touch-icon">

  <!-- Csss File -->
  <link href="css/xxxx.css" rel="stylesheet">

  <?php $maya->view->initializeCssAndJquery();?>
  
</head>

<body>

<div>SECTION FOR LOGO MENU HEADERS</div>

<div>
<!--- FOR LOGIN FORMS AND MESSAGES -->
<?php   $maya->view->generateLoginAndNotice(); ?>
</div>

<div class="container page">
<!--- Main section for displaying contents of the site -->
    <?php
    $maya
->controller->display()
    
?>
</div>

<div>FOOTER AREA</div>
<!-- Javascript Files -->
  <script src="js/main.js"></script>
<?php 
$maya
->view->initializeScripts(array('mathjax'=>false,'speak'=>false,'chosen'=>true,'wysiwyg'=>true,'datetimepicker'=>true));
?>
</body>
</html>


Detailed Process to Integrate Maya into a theme index.php

1) You must insert the following on the top most part of the index.php the calls of maya core files

<?php
session_start();

ini_set('display_errors''On');
error_reporting(E_ALL E_NOTICE E_WARNING); 
require_once 
'maya/Maya.php';

$maya = new Maya();
$user= new User()//Optional if you need User object to test for login status;
$role= new Role()//Optional if you need to check roles;
?>

2) You must insert the following right befor end of head section </head>

 <?php $maya->view->initializeCssAndJquery();?>

3) You may have to include the default login and notice form right after the headers, but you could also make your own

<?php   $maya->view->generateLoginAndNotice(); ?>

4) You may override some menus like

    <ul class="nav-menu">
            <li class="menu-active"><a href="#hero">Home</a></li>
        <?php 
        
if (!$role->isUserLoggedIn())
        {
        
?>
            <li class="dropdown"> <a data-toggle="dropdown" href="#" onclick="showLogin()" ><i class="fa fa-user-plus"></i> LOGIN</a></li>
        <?php
        
} else 
        {
        
?>
            <li><a href="#" class="mx-" mx-container="div.page" mx-click="?command=display_rest&path=Admin.dir/Informations.dir/List Informations.rest.php">Informations</a></li>
            <li><a href="#" class="mx-" mx-container="div.page" mx-click="?command=display_rest&path=Admin.dir/Users.dir/List Users.rest.php">Users</a></li>
            <li><a href="?command=logout" class="" style=""><i class="fa fa-user-times"></i>LOGOUT</a></li>
        <?php 
        
}?> 
        </ul>

5) You must insert this code inside the div.page where you need to load dynamically loaded pages. The else portion is the default home page like /home1.php

<?php $maya->controller->display(); ?>

6. All other js files should be called at the end of the html before the </body> as shown below

<?php $maya->view->initializeScripts(array("mathjax"=>false,"speak"=>false,"chosen"=>true,"wysiwyg"=>true,"datetimepicker"=>true));?>

The resulting integration of Maya into a more complex theme index.php is shown below:

<?php
session_start
();
ini_set('display_errors''On');
error_reporting(E_ALL E_NOTICE E_WARNING); 
require_once 
'maya/Maya.php';

$maya = new Maya();
$rolw = new Role();
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Maya Framework</title>
  <meta content="width=device-width, initial-scale=1.0" name="viewport">
  <meta content="" name="keywords">
  <meta content="" name="description">

  <!-- Favicons -->
  <link href="img/favicon.png" rel="icon">
  <link href="img/apple-touch-icon.png" rel="apple-touch-icon">

  <?php $maya->view->initializeCssAndJquery();?>
</head>

<body>

  <header id="header" class="header header-hide">
    <div class="container">

      <div id="logo" class="pull-left">
        <h1><a href="#body" class="scrollto"><img src="img/maya.png" alt="" style="height:40px;vertical-align:middle" title="" /><span>M</span>aya</a></h1>
      </div>

      <nav id="nav-menu-container">
        <ul class="nav-menu">
            <li ><a href="#" class="mx-" mx-container="div.page"  mx-click="?command=display_rest&path=home.pub.htm" ><i class="fa fa-home"></i> Home</a></li>
            <li><a href="#" class="mx-" mx-container="div.page"  mx-click="?command=display_rest&path=advance.pub.htm"><i class="fa fa-star"></i> Advance Topic </a></li>
        <?php 
        
if (!$role->isUserLoggedIn())
        {
        
?>
            <li class="dropdown"> <a data-toggle="dropdown" href="#" onclick="showLogin()" ><i class="fa fa-user-plus"></i> LOGIN</a></li>
        <?php
        
} else 
        {
        
?>
            <li><a href="#" class='mx-' mx-container='div.page' mx-click="?command=display_rest&path=Admin.dir/Informations.dir/List Informations.rest.php"><i class="fa fa-database"></i> Informations</a></li>
            <li><a href="#" class='mx-' mx-container='div.page' mx-click="?command=display_rest&path=Admin.dir/Finances.dir/List Finances.rest.php"><i class="fa fa-dollar"></i> Finances</a></li>
            <li><a href="#"><i class="fa fa-user" ></i> <?php echo $_SESSION['user_name'];?></a>
                <ul>
                <li><a href="#" class='mx-' mx-container='div.page' mx-click="?command=display_rest&path=Admin.dir/Users.dir/List Users.rest.php"><i class="fa fa-group"></i> Users</a></li>
                <li><a href="#" class='mx-' mx-container='div.page' mx-click="?command=display_rest&path=Admin.dir/Tickets.dir/List Tickets.rest.php"><i class="fa fa-bug"></i> Tickets</a></li>    
                <li><a href="?command=logout" class="" style=""><i class="fa fa-user-times"></i>LOGOUT</a></li>
                </ul>
            </li>
      <?php 
        
}?> 
        </ul>
      </nav><!-- #nav-menu-container -->
    </div>
  </header><!-- #header -->

  <?php $maya->view->generateLoginAndNotice(); ?>

  <section class="<?php echo ($role->isUserLoggedIn()?'padd-section':'');?> text-center wow fadeInUp"  style="margin-top:100px">
    <div class="container page">
    <?php
    $maya
->controller->display()
    
?>
    </div>
  </section>

  <footer class="footer">
    <div class="copyrights">
      <div class="container">
        <p>&copy; Copyrights Maya. All rights reserved. Author: Edgardo Fabian      Since: 2007</p>
        <div class="credits">
          Framework powered by <a href="https://maya.docph.net">Maya</a>
          Html Template by <a href="https://bootstrapmade.com/">BootstrapMade</a> 
        </div>
      </div>
    </div>

  </footer>



  <a href="#" class="back-to-top"><i class="fa fa-chevron-up"></i></a>

  <!-- JavaScript Libraries -->
  <script src="lib/bootstrap/js/bootstrap.bundle.min.js"></script>


  <!-- Template Main Javascript File -->
  <script src="js/main.js"></script>
<?php 
$maya
->view->initializeScripts(array('mathjax'=>false,'speak'=>false,'chosen'=>true,'wysiwyg'=>true,'datetimepicker'=>true));
?>
</body>
</html>

9) All php codes marked by <?php ....?> are required

10) There should always be a <div class='page'> </div> because this is where other pages are loaded via restful process.

Modify Models

1) You should only modify the extended versions of models at usr/model folder. This is to insure that when you change your db and update your models the changes you added will not be overwritten by generaModel.php. The generateModel.php will only overwrite the models at usr_generate/model folders

2) You may override functions from the usr_generated/model folder

3) You should add user functions only to the models at usr/model folder.

Modify Controllers

1) You should only modify the extended versions of controllers at usr/controller folder. This is to insure that when you change your db and update your controllers the changes you added will not be overwritten by generaController.php. The generateController.php will only overwrite the controllers at usr_generate/model folders

2) You may override functions from the usr_generated/controller folder

3) You should add user controller functions only to the controllers at usr/controller folder.

Modify Views

1) Views (List, Edit, New) and View models are automatically generated at usr_generated/view folder by generateView.php.

2) generateView.php also places a default extensions of view models and files at usr/views if not yet available. This is the portion that you can edit.

3) generateView.php also places a default file at the Administration directory for listing, adding and editing of table items. These views simple include the views at usr/view/.

The above is terminal command in linux that assumes the folder structure defined above executed at ../Admin.dir/Users.dir/ directory