Skip to content

01. How To's

Simon Striekwold edited this page Mar 22, 2018 · 7 revisions

Installation

  1. Download the framework from github, you can find the most recent version on the releases tab.

  2. Unzip Smts_Base-master.zip and place the framework folder into your web-root, for example C:/xampp/htdocs/.

  3. Optionally, change the framework folder to your project name.

  4. Edit the following lines in your base/config.php file:

    BaseUrl, DataBaseName, DataBaseUser, DataBasePassword.

    For more information on what you should change them to, see the Config wiki entry.

  5. Run the database setup at /dev/setup, this will create the database and add some default users.

Add a page

A page is an Action, a Controller is a group of actions bound by a category, and a View is the HTML used to display an Action to the user.

For simple and advanced examples see the files pagesController and usersController respectively.

In the following example the controller will be called foo and the action bar, to view this page you would go to /foo/bar. To add a new Controller, Action, and View you need to create two files: controllers/foo_controller.php and views/foo/bar.php. To only add an Action and view simply add the method to an existing Controller and change foo to that Controllers name.

<?php // controllers/foo_controller.php

    class fooController extends Controller {

        public static function bar() {

            Smts::Render('foo/bar');

        }

    }
<!-- views/foo/bar.php -->
<div class="row">
    <div class="col">
        <h1>Your content</h1>
    </div>
</div>

Add a database table / model

  • First create the database table using the setup tool.

    • In the base/database_struct.php file in the getStructure method add a new array entry at the top of the array. The key of that entry is what the table will be called and the value is an array.

    • In that array add the names of the columns as keys, and the datatype and length as values.

    • If your table contains any primary keys add them to the primaryKeys array entry, with the table name as key and the name of the primary key as value.

    • Now go to /dev/setup and reload the database with the new structure.

  • Then to add the model, create a file in the models folder with the name of the database table suffixed with .php.

    Below is an example of a simple user Model.

    <?php // models/user.php
    
        class User extends model {
    
            public $id;
            public $name;
    
            public function rules() {
                return [
                    [ ['name'], 'required' ],
                    [ ['name'], 'unique' ],
                    [ ['name'], 'type_string' ],
                ];
            }
    
            public function attributes() {
                return [
                    'name' => 'Name'
                ];
            }
    
            public static function find( $id ) {...}
    
            public function save() {...}
    
            public function delete() {...}
        }

Clone this wiki locally