Ascend PHP - Documents

* I know I need to format these tutorials better; this was thrown together. Clean up coming soon!

Intro

Ascend PHP Framework is about taking programmers development to the next level; to Ascend.

Ascend has been developed to provide similar simplistic development to Laravel but with a slimer base line of code.

Ascend provides regularily used development requests and automate them for rapid development such as REST API's, permissions for users, and more.

Benchmark

Laravel = 300ish

Phalcon = 1400ish

Ascend = 1200ish

Ascend is 3x faster than Laravel but only slightly less than phalcon

Minimum Requirements

Requires:

  • PHP 5.4+
  • MySQL 5+
  • PHP PDO Extension

Install

Read readme.txt

Local Development

Run 'php ascend serve'

Apache Setup

Coming Soon

Nginx Setup

Coming Soon

File Structure

Folders:

  • App - Stores specific files for this application
  • App/CommandLine - Custom command line classes
  • App/Controller - Middleman which controls data from Models to Views aka Database to Display
  • App/Model - Structure of tables for database and helpful functions
  • App/View - Framework code for content to display to users
  • public - Files for the public to see
  • public/js - Javascript
  • public/css - CSS
  • public/fonts - Fonts
  • storage - Files to be stored
  • storage/cache - Cache files
  • storage/data - Data files
  • storage/log - Log files
  • vendor - Third parties through composer

Files:

  • App/config.php - Configurations
  • App/config.sample.php - Example Configurations
  • App/route.php - List of routes for applications
  • App/route-examples.php - List of route examples
  • ascend - Command line tools

Setup REST API

Coming Soon

Command Line

In command line run "php ascend" and get help + a list of commands.

Command: "php ascend db:migrate" to load in database

Create First Page

  • Open App/routes.php
  • Go below Route::get('/', 'GuestController@viewIndex');
  • Add Route::get('/', 'GuestController@viewTest');
  • Save App/routes.php
  • Open App/Controller/GuestController.php
  • Create new public function viewTest(){}
  • Inside function viewTest() add return Route::getView('guest/test');
  • Save App/Controller/GuestController.php
  • Create App/View/guest/test.php
  • Open App/View/guest/test.php
  • Start with <?php
  • Next $title = 'Title of page in browser window bar';
  • Next ob_start();
  • Next <div class="row"> (We use bootstrap by default but can use anything you want)
  • Next <p>Welcome to my first page</p>
  • Next </div>
  • Next $container = ob_get_contents();
  • Next ob_end_clean();
  • Next ob_start();
  • Next $javascript = ob_get_contents();
  • Next // Javascript goes here
  • Next ob_end_clean();
  • Next require_once '_template.php';
  • Save App/View/guest/test.php
  • Go to [domain]/test

--> Explained <--

  • First we created a route
  • Next we created a public function in an already existing Controller
  • Inside that function we reference Route class which is a AscendPHP Core library
  • Route class has a static function called getView which goes into the App/View folder and displays
  • So Route::getView('guest/test') references App/View/guest/test.php
  • Next we create the view file guest/test.php
  • Inside guest/test.php we have 3 variables we create; $title, $container, $javascript
  • - All of these are within _template.php so any variables you want to reference can be
  • * Also, I wrapped $container and $javascript in ob... because writing code is like writing it in a php file so if you want to partial it out later

Change Template

  • First, complete Create your first page
  • Next, open App/View/guest/_template.php
  • Above, $container = ob_get_contents(); add echo @$footer;
  • Save App/View/guest/_template.php
  • Open App/View/guest/test.php
  • <footer class="footer">
  • <div class="container">
  • <span class="text-muted">Place sticky footer content here.</span>
  • </div>
  • </footer>
  • Save App/View/guest/test.php
  • Go to [domain]/test now should have a footer

Create First Model

  • Create file App/Model/Book.php
  • <?php namespace App\Model; // Define namespace
  • use Ascend\Bootstrap as BS; // Bootstrap has config variables and other core things
  • use Ascend\Model; // Define Ascend Core Model class
  • class Book extends Models { // All models extend Model class
  • protected $table = 'books'; // Name of table in database
  • protected $fillable = ['book_category_id', 'name', 'is_active']; // Fields access by AscendPHP
  • protected $structure = [ // Structure of fields in database
  • 'id' => 'int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY',
  • 'book_category_id' => 'int unsigned NOT NULL',
  • 'name' => 'varchar(255) NOT NULL',
  • 'is_active' => 'tinyint NOT NULL',
  • ];
  • } // End of Book class
  • Save App/Model/Book.php
  • Note: By default created_at, updated_at, deleted_at is added to every model
  • Go to command line and make sure you are at root of framework
  • Note: App, public, storage, vendor should be in this folder
  • Run php ascend db:migrate
  • Note: db:migrate will install models into database and also make alters

Model Seed

  • Open App/Model/Book.php
  • After protected $table, $fillable, $structure; add protected $seed = [];
  • Inside array of see add model fields with values. Example:
  • protected $seed = [
  • ['book_category_id' => 1, 'name' => 'Best Websites', 'is_active' => 1], // 1
  • ['book_category_id' => 1, 'name' => 'Best Cook Books', 'is_active' => 1], // 2
  • ['book_category_id' => 2, 'name' => 'Best Parks', 'is_active' => 1], // 3
  • ];
  • Save App/Model/Book.php
  • Command line run php ascend db:migrate

Models > Add easy access functions

  • Create App/Controller/BookController.php
  • <?php namespace App\Controller;
  • use Ascend\Request; // AscendPHP Core for getting Requests aka $_GET / $_POST
  • use Ascend\Route; // AscendPHP Core access routing of files
  • use Ascend\Model\Book; // Reference Book Model
  • class GuestController extends Controller {
  • public function viewBooks() {
  • $rows = Book::all(); // ::all() gets all results no filter check other than deleted_at
  • return Route::getView('book/index', ['books' => $rows]);
  • // Gets view App/View/book/index.php
  • // 2nd parameter is an array of variables to pass to view
  • // Key turns into variable in view by extract() within Route class
  • // Value is the data to pass in
  • }
  • }
  • Save App/Controller/BookController.php
  • Create App/View/book/index.php
  • <ul>
  • <?php foreach ($books AS $book): ?>
  • <li><?=$book['name'];?></li>
  • <?php endforeach; ?>
  • </ul>
  • Save App/View/book/index.php
  • Open App/routes.php
  • Route::get('/books', 'BookController@viewBooks');
  • Save App/routes.php
  • Go to [domain]/books
  • Now see a list of books

Create Custom Command Line Commands

  • Go to App/CommandLine/AppExample.php and copy as ServerInfo.php
  • Change App/CommandLine/ServerInfo.php class anem to ServerInfov
  • Change protected $command = 'server:info';
  • Change protected $name = 'Get Server Info';
  • Change protected $detail = 'Get Server Info';
  • Go to command line and run php ascend server:info
  • Comment out $cmdArguments and both $this->output... lines
  • Add inside public function run()
  • $this->output('PHP Version: ' . phpversion());
  • Go to command line and run php ascend server:info
  • Also, can set this up on a cronjob to run as often as you like
1