PHP code example of glivers / roline

1. Go to this page and download the library: Download glivers/roline library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

glivers / roline example snippets


 namespace Models;

/**
 * Product Model
 *
 * Represents products in the catalog with stock tracking and timestamps.
 * Manages product inventory, availability, and catalog operations.
 *
 * @author Your Name
 * @copyright Copyright (c) 2026
 * @license MIT License
 * @version 1.0.0
 */

use Rackage\Model;

class ProductModel extends Model
{
    // ==================== MODEL PROPERTIES ====================

    /**
     * Database table name for this model
     *
     * Defines which database table this model maps to. Used by the
     * Query builder for all database operations on this model's records.
     *
     * @var string
     */
    protected static $table = 'products';

    // ==================== TABLE COLUMNS ====================

    /**
     * Unique product identifier
     * @column
     * @primary
     * @autonumber
     */
    protected $id;

    /**
     * Product name or title
     * @column
     * @varchar 255
     */
    protected $name;

    /**
     * Stock quantity available
     * @column
     * @int
     * @default 0
     */
    protected $quantity;

    /**
     * When the product was added to catalog
     * @column
     * @datetime
     */
    protected $created_at;

    /**
     * When the product details were last updated
     * @column
     * @datetime
     */
    protected $updated_at;

    // ==================== MODEL METHODS ====================

    // Add your business logic methods here
}

return [
    'author' => 'Your Name',                    // Appears in @author tags
    'copyright' => 'Copyright (c) 2026',        // Appears in @copyright tags
    'license' => 'MIT License',                 // Appears in @license tags
    'version' => '1.0.0',                       // Appears in @version tags
];

 namespace Models;

/**
 * User Model
 *
 * Represents authenticated users in the system.
 * Handles user accounts, authentication, and profile data.
 *
 * @author Your Name
 * @copyright Copyright (c) 2026
 * @license MIT License
 * @version 1.0.0
 */

use Rackage\Model;

class UserModel extends Model
{
    // ==================== MODEL PROPERTIES ====================

    /**
     * Database table name for this model
     *
     * @var string
     */
    protected static $table = 'users';

    /**
     * Enable automatic timestamp management
     *
     * @var bool
     */
    protected static $timestamps = true;

    // ==================== TABLE COLUMNS ====================

    /**
     * Unique user identifier
     * @column
     * @primary
     * @autonumber
     */
    protected $id;

    /**
     * User's full name
     * @column
     * @varchar 255
     */
    protected $name;

    /**
     * Unique email address for login
     * @column
     * @varchar 255
     * @unique
     */
    protected $email;

    /**
     * Hashed password
     * @column
     * @varchar 255
     */
    protected $password;

    /**
     * Account status flag
     * @column
     * @tinyint
     * @default 1
     */
    protected $is_active;

    /**
     * When the user registered
     * @column
     * @datetime
     */
    protected $created_at;

    /**
     * When the user profile was last updated
     * @column
     * @datetime
     */
    protected $updated_at;
}

 namespace Controllers;

use Rackage\Controller;
use Models\UserModel;

class AuthController extends Controller
{
    public function register()
    {
        UserModel::save([
            'name' => 'John Doe',
            'email' => '[email protected]',
            'password' => password_hash('secret', PASSWORD_DEFAULT)
        ]);
    }

    public function getUsers()
    {
        $users = UserModel::where('is_active', 1)->all();
        return $users;
    }
}

/**
 * Handle published action
 *
 * @return void
 */
public function getPublished()
{
    View::render('posts.published');
}



use Rackage\Registry;

/**
 * Add Status To Posts
 *
 * Migration: add_status_to_posts
 * Created: 2025-01-15 14:30:22
 *
 * This migration was auto-generated by comparing your current database
 * schema with the previous migration state.
 */

/**
 * Run the migration (apply changes)
 */
function up()
{
    $db = Registry::get('database-sync');
    $query = $db->query();

    $query->transaction();

    try {
    $db->execute("
        ALTER TABLE posts
        ADD COLUMN status VARCHAR(20) NOT NULL DEFAULT 'draft'
    ");

        $query->commit();

    } catch (Exception $e) {
        $query->rollback();
        throw $e;
    }
}

/**
 * Reverse the migration (rollback changes)
 */
function down()
{
    $db = Registry::get('database-sync');
    $query = $db->query();

    $query->transaction();

    try {
    $db->execute("
        ALTER TABLE posts
        DROP COLUMN status
    ");

        $query->commit();

    } catch (Exception $e) {
        $query->rollback();
        throw $e;
    }
}

// ❌ WRONG - Will be ignored by parser
protected static $username;

// ✅ CORRECT - Will create column
protected $username;

// ❌ WRONG - Terrible visual experience, hard to scan/edit
/** @column @varchar 255 @unique @index @comment "User email" */
protected $email;

// ✅ CORRECT - Each annotation on its own line
/**
 * User email address for login
 * @column
 * @varchar 255
 * @unique
 * @index
 * @comment "User email"
 */
protected $email;

// ❌ WRONG - No description, just annotations
/**
 * @column
 * @varchar 255
 * @unique
 */
protected $email;

// ✅ CORRECT - Description explains the column's purpose
/**
 * User email address for login and notifications
 * @column
 * @varchar 255
 * @unique
 */
protected $email;

// ✅ ALSO GOOD - More detailed description
/**
 * Order status in the fulfillment pipeline
 * @column
 * @enum pending,processing,shipped,delivered,cancelled
 * @default pending
 * @index
 */
protected $status;

/**
 * User age (0-255 range is sufficient)
 * @column
 * @tinyint
 * @unsigned
 */
protected $age;

/**
 * Product inventory count (larger than tinyint range)
 * @column
 * @smallint
 * @unsigned
 * @default 0
 */
protected $stock_quantity;

/**
 * Daily page views (millions of views)
 * @column
 * @mediumint
 * @unsigned
 * @default 0
 */
protected $daily_views;

/**
 * Product quantity in stock
 * @column
 * @int
 * @unsigned
 * @default 0
 */
protected $quantity;

/**
 * Total views counter (can grow very large)
 * @column
 * @bigint
 * @unsigned
 * @default 0
 */
protected $total_views;

/**
 * Product price with cents
 * @column
 * @decimal 10,2
 * @unsigned
 * @default 0.00
 */
protected $price;

/**
 * Temperature reading with decimal precision
 * @column
 * @float
 */
protected $temperature;

/**
 * Geographic coordinate (latitude/longitude)
 * @column
 * @double
 */
protected $latitude;

/**
 * Two-letter country code (fixed length)
 * @column
 * @char 2
 * @default US
 */
protected $country_code;

/**
 * User's email address
 * @column
 * @varchar 255
 * @unique
 */
protected $email;

/**
 * Article content or long description
 * @column
 * @text
 * @nullable
 */
protected $description;

/**
 * Large article body with rich content
 * @column
 * @mediumtext
 */
protected $article_body;

/**
 * Complete book content or massive data dump
 * @column
 * @longtext
 */
protected $full_content;

/**
 * User's birth date
 * @column
 * @date
 * @nullable
 */
protected $birth_date;

/**
 * Store opening time
 * @column
 * @time
 * @default 09:00:00
 */
protected $opening_time;

/**
 * Year the vehicle was manufactured
 * @column
 * @year
 * @nullable
 */
protected $manufacture_year;

/**
 * When the article was published
 * @column
 * @datetime
 * @nullable
 */
protected $published_at;

/**
 * Timestamp when record was created
 * @column
 * @timestamp
 * @default CURRENT_TIMESTAMP
 */
protected $created_at;

/**
 * User profile picture
 * @column
 * @blob
 * @nullable
 */
protected $profile_image;

/**
 * PDF document attachment
 * @column
 * @mediumblob
 * @nullable
 */
protected $document;

/**
 * Video file or large binary data
 * @column
 * @longblob
 * @nullable
 */
protected $video_file;

/**
 * Store or restaurant location
 * @column
 * @point
 * @nullable
 */
protected $location;

/**
 * Delivery route or path
 * @column
 * @linestring
 * @nullable
 */
protected $route;

/**
 * Delivery coverage area
 * @column
 * @polygon
 * @nullable
 */
protected $coverage_area;

/**
 * Generic spatial data
 * @column
 * @geometry
 * @nullable
 */
protected $geo_data;

/**
 * Is the user account active
 * @column
 * @boolean
 */
protected $is_active;

/**
 * User account status
 * @column
 * @enum active,inactive,suspended,banned
 * @default active
 */
protected $status;

/**
 * User permissions (can have multiple)
 * @column
 * @set read,write,delete,admin
 * @nullable
 */
protected $permissions;

/**
 * User settings or metadata
 * @column
 * @json
 * @nullable
 */
protected $settings;

/**
 * Auto-incrementing primary key
 * @column
 * @autonumber
 */
protected $id;

/**
 * Globally unique identifier
 * @column
 * @uuid
 */
protected $id;

/**
 * User's email address
 * @column
 * @varchar 255
 * @unique
 * @comment "Used for login and notifications"
 */
protected $email;

/**
 * User Model
 *
 * @tablecomment "Stores user account data and authentication credentials"
 */
class UserModel extends Model
{
    // ... properties
}

/**
 * Middle name field
 * @column
 * @varchar 100
 * @nullable
 * @after first_name
 */
protected $middle_name;

/**
 * Legacy ID field
 * @column
 * @int
 * @first
 */
protected $legacy_id;

/**
 * Deprecated field - marking for deletion
 * @column
 * @drop
 */
protected $old_field;

/**
 * Email address (renamed from email_addr)
 * @column
 * @varchar 255
 * @rename email_addr
 */
protected $email;

/**
 * Custom primary key
 * @column
 * @varchar 50
 * @primary
 */
protected $user_code;

/**
 * User's email address
 * @column
 * @varchar 255
 * @unique
 */
protected $email;

/**
 * User's middle name
 * @column
 * @varchar 100
 * @nullable
 */
protected $middle_name;

/**
 * Product quantity (never negative)
 * @column
 * @int
 * @unsigned
 * @default 0
 */
protected $quantity;

/**
 * User account status
 * @column
 * @enum active,inactive,suspended
 * @default active
 */
protected $status;

/**
 * Product price (must be positive)
 * @column
 * @decimal 10,2
 * @check price > 0
 */
protected $price;

/**
 * User's last name
 * @column
 * @varchar 100
 * @index
 */
protected $last_name;

/**
 * Article content for search
 * @column
 * @text
 * @fulltext
 */
protected $content;

/**
 * User Model
 *
 * @composite (last_name, first_name)
 * @composite idx_city_state (city, state)
 */
class UserModel extends Model
{
    // ... properties
}

/**
 * Product Model
 *
 * @compositeUnique (sku, warehouse_id)
 */
class ProductModel extends Model
{
    // ... properties
}

/**
 * Log Model
 *
 * @partition hash(user_id) 16
 */
class LogModel extends Model
{
    // ... properties
}

/**
 * ID of the user who created this post
 * @column
 * @int
 * @unsigned
 * @foreign users(id)
 * @ondelete CASCADE
 */
protected $user_id;

/**
 * Order's customer ID
 * @column
 * @int
 * @unsigned
 * @foreign customers(id)
 * @ondelete RESTRICT
 */
protected $customer_id;

/**
 * Product category ID
 * @column
 * @int
 * @unsigned
 * @foreign categories(id)
 * @onupdate CASCADE
 */
protected $category_id;

 namespace Models;

/**
 * User Model
 *
 * Manages user accounts with authentication, roles, and activity tracking.
 * Implements soft deletes and automatic timestamps.
 *
 * @tablecomment "User accounts with authentication and profile data"
 * @composite idx_name (last_name, first_name)
 * @composite idx_location (city, state)
 * @compositeUnique unq_email_deleted (email, deleted_at)
 */

use Rackage\Model;

class UserModel extends Model
{
    protected static $table = 'users';
    protected static $timestamps = true;

    // ==================== PRIMARY KEY ====================

    /**
     * Unique user identifier
     * @column
     * @autonumber
     */
    protected $id;

    // ==================== AUTHENTICATION ====================

    /**
     * User's email address for login
     * @column
     * @varchar 255
     * @unique
     * @comment "Used for authentication and notifications"
     */
    protected $email;

    /**
     * Hashed password
     * @column
     * @varchar 255
     * @comment "Bcrypt hash - never store plain text"
     */
    protected $password;

    /**
     * Password reset token
     * @column
     * @varchar 100
     * @nullable
     * @index
     */
    protected $reset_token;

    /**
     * When reset token expires
     * @column
     * @datetime
     * @nullable
     */
    protected $reset_expires;

    // ==================== PROFILE ====================

    /**
     * User's first name
     * @column
     * @varchar 100
     */
    protected $first_name;

    /**
     * User's last name
     * @column
     * @varchar 100
     */
    protected $last_name;

    /**
     * Phone number with country code
     * @column
     * @varchar 20
     * @nullable
     */
    protected $phone;

    /**
     * City name
     * @column
     * @varchar 100
     * @nullable
     */
    protected $city;

    /**
     * Two-letter state code
     * @column
     * @char 2
     * @nullable
     */
    protected $state;

    /**
     * Birth date for age verification
     * @column
     * @date
     * @nullable
     * @check birth_date < CURDATE()
     */
    protected $birth_date;

    // ==================== ROLES & STATUS ====================

    /**
     * User role level
     * @column
     * @enum user,moderator,admin
     * @default user
     * @index
     */
    protected $role;

    /**
     * Account status
     * @column
     * @enum active,inactive,suspended,banned
     * @default active
     * @index
     */
    protected $status;

    /**
     * User permissions (multi-select)
     * @column
     * @set read,write,delete,manage_users,manage_settings
     * @nullable
     */
    protected $permissions;

    // ==================== ACTIVITY TRACKING ====================

    /**
     * Last successful login
     * @column
     * @datetime
     * @nullable
     */
    protected $last_login;

    /**
     * Failed login attempts counter
     * @column
     * @tinyint
     * @unsigned
     * @default 0
     */
    protected $failed_logins;

    /**
     * Account lockout time
     * @column
     * @datetime
     * @nullable
     */
    protected $locked_until;

    // ==================== METADATA ====================

    /**
     * User preferences and settings
     * @column
     * @json
     * @nullable
     */
    protected $settings;

    /**
     * Email verification status
     * @column
     * @boolean
     * @default 0
     */
    protected $email_verified;

    /**
     * When email was verified
     * @column
     * @datetime
     * @nullable
     */
    protected $verified_at;

    // ==================== SOFT DELETES ====================

    /**
     * Soft delete timestamp
     * @column
     * @datetime
     * @nullable
     * @index
     * @comment "NULL = active, timestamp = deleted"
     */
    protected $deleted_at;

    // ==================== TIMESTAMPS ====================

    /**
     * When the user account was created
     * @column
     * @datetime
     */
    protected $created_at;

    /**
     * When the user account was last updated
     * @column
     * @datetime
     */
    protected $updated_at;
}

// Add new nullable columns first
/**
 * New optional field
 * @column
 * @varchar 100
 * @nullable
 */
protected $new_field;

// Change property name and add @rename
/**
 * Email address (renamed from email_addr)
 * @column
 * @varchar 255
 * @rename email_addr
 */
protected $email;

/**
 * Log Model
 *
 * @partition hash(user_id) 32
 */
class LogModel extends Model
{
    // Distributes data across 32 partitions for faster queries
}

protected static $timestamps = true;

/**
 * @column
 * @datetime
 */
protected $created_at;

/**
 * @column
 * @datetime
 */
protected $updated_at;

/**
 * @column
 * @datetime
 * @nullable
 * @index
 */
protected $deleted_at;

// Query: WHERE deleted_at IS NULL (active records)

/**
 * @column
 * @enum pending,processing,completed,failed
 * @default pending
 * @index
 */
protected $status;

/**
 * @column
 * @int
 * @unsigned
 * @foreign users(id)
 * @nullable
 */
protected $created_by;

/**
 * @column
 * @int
 * @unsigned
 * @foreign users(id)
 * @nullable
 */
protected $updated_by;

// Parent table (users)
/**
 * @column
 * @autonumber
 */
protected $id;  // Creates: INT(11) UNSIGNED

// Child table (posts) - MUST match exactly
/**
 * @column
 * @int
 * @unsigned  // Don't forget this!
 * @foreign users(id)
 */
protected $user_id;

// Make sure you used @rename annotation
/**
 * @column
 * @varchar 255
 * @rename old_column_name  // This is 

// Before
/**
 * @column
 * @varchar 50
 */
protected $email;

// After
/**
 * @column
 * @varchar 255
 */
protected $email;

// Wrong - price needs decimals
/**
 * @column
 * @int
 */
protected $price;

// Right
/**
 * @column
 * @decimal 10,2
 */
protected $price;

// ❌ WRONG - Missing @column
/**
 * @varchar 255
 */
protected $email;

// ✅ CORRECT
/**
 * @column
 * @varchar 255
 */
protected $email;

// ❌ WRONG - Spaces in enum values
/**
 * @column
 * @enum active, inactive, banned
 */
protected $status;

// ✅ CORRECT - No spaces
/**
 * @column
 * @enum active,inactive,banned
 */
protected $status;

// ❌ WRONG - Wrong foreign key syntax
/**
 * @column
 * @foreign users.id
 */
protected $user_id;

// ✅ CORRECT - Use parentheses
/**
 * @column
 * @foreign users(id)
 */
protected $user_id;

// ❌ WRONG - References wrong column
/**
 * @column
 * @int
 * @check quantity > 0
 */
protected $stock;

// ✅ CORRECT - Column name matches
/**
 * @column
 * @int
 * @check stock > 0
 */
protected $stock;

// Option 1: Allow NULL
/**
 * @column
 * @varchar 255
 * @nullable  // Add this
 */
protected $email;

// Option 2: Set default value
/**
 * @column
 * @varchar 255
 * @default ''  // Empty string default
 */
protected $email;
bash
php roline model:create Product
bash
php roline model:table-create Product
bash
php roline
bash
php roline model:create User
bash
php roline model:table-create User
bash
php roline list
bash
php roline model:table-create User
php roline model:table-update User
php roline model:table-schema User
php roline model:table-export User
bash
php roline db:export          # Exports your entire database
php roline db:tables          # Lists all tables
php roline db:create test_db  # Creates a new database
bash
# ✅ RECOMMENDED - Just the name
php roline model:create User      # Creates UserModel.php
php roline model:table-create User

# ✅ ALSO WORKS - With "Model" suffix (auto-stripped)
php roline model:table-update UserModel

# ✅ ALSO WORKS - Case insensitive
php roline model:create user
php roline model:table-update USER

# 💡 CONVENTION - Use PascalCase for readability
User, Post, Product, OrderItem (not user, post, product)
bash
User         → Creates UserModel.php
Product      → Creates ProductModel.php
OrderItem    → Creates OrderItemModel.php
BlogPost     → Creates BlogPostModel.php
bash
php roline model:create <Model> [table]
bash
php roline model:create Product
bash
php roline model:create Product inventory
php roline model:create Data datum
php roline model:create BlogPost posts
bash
php roline model:table-create Product
bash
php roline model:table-update Product
bash
php roline model:table-schema Product
bash
php roline model:delete Product
bash
php roline model:rename Todos Todo

Model renamed successfully!
  Old: application/models/TodosModel.php
  New: application/models/TodoModel.php
bash
php roline model:table-empty Product
bash
php roline model:table-reset Product
bash
php roline model:table-export Product
bash
php roline model:table-export Product products_backup.sql
php roline model:table-export Product products.csv
bash
php roline controller:create Posts
bash
php roline controller:delete Posts
bash
php roline controller:rename Todos Todo

Controller renamed successfully!
  Old: application/controllers/TodosController.php
  New: application/controllers/TodoController.php
bash
php roline controller:complete Posts

Creating complete MVC scaffold for: Posts

1. Creating controller...
   ✓ application/controllers/PostsController.php

2. Creating model...
   ✓ application/models/PostsModel.php

3. Creating views...
   ✓ application/views/posts/layout.php
   ✓ application/views/posts/index.php
   ✓ application/views/posts/show.php
   ✓ application/views/posts/create.php
   ✓ public/css/posts.css

Complete scaffold created successfully!

Next steps:
  1. Add properties to model: php roline model:append Posts
  2. Create database table: php roline model:table-create Posts
  3. Implement controller methods
  4. Customize view templates
bash
php roline view:create posts

View structure created successfully!

  ✓ application/views/posts/layout.php
  ✓ application/views/posts/index.php
  ✓ application/views/posts/show.php
  ✓ application/views/posts/create.php
  ✓ application/views/posts/edit.php
  ✓ public/css/posts.css

Usage in controller:
  View::render('posts/index');
  View::render('posts/show', ['id' => $id]);
bash
php roline view:add posts edit

View file created: application/views/posts/edit.php
Use: View::render('posts.edit')
bash
php roline view:delete posts
bash
php roline view:rename todos todo
bash
php roline table:create categories
bash
php roline table:create users --sql=schema.sql
bash
php roline table:copy users users_backup
bash
php roline table:copy users users_test --empty
bash
php roline table:schema users
bash
php roline table:empty users
bash
php roline table:reset users
bash
php roline table:export users
bash
php roline table:export users users_backup.sql
php roline table:export products products.csv
bash
php roline table:unpartition links
bash
php roline migration:run

Running 3 migration(s)...

  → 2025_01_15_120000_create_users.php
  ✓ 2025_01_15_120000_create_users.php
  → 2025_01_15_130000_add_email_verification.php
  ✓ 2025_01_15_130000_add_email_verification.php
  → 2025_01_15_143022_add_status_to_posts.php
  ✓ 2025_01_15_143022_add_status_to_posts.php

Ran 3 migration(s) successfully!