creating an Osclass plugin, outlining every step from setup to implementation of the Model-View-Controller (MVC) framework.

bomboclat1

New member
XNullUser
Joined
Dec 4, 2024
Messages
2
Reaction score
0
Points
1
Location
LND
NullCash
3

1. Conventions and Guidelines

  • Team Prefix: Use a unique prefix to avoid naming conflicts (e.g., mdh_ for "Madhouse").
  • Plugin Naming Rules:
    • Only lowercase letters, numbers, and underscores.
    • Avoid using osc_ or osclass_ to prevent conflicts.
  • Coding Style: Follow PSR-1 and PSR-2 standards.

2. Directory Structure

Your plugin should adhere to the following directory structure:

graphql
Copy code
madhouse_helloworld/
├── assets/ # Static resources (CSS, JS, images, SQL, dependencies)
├── classes/ # Main PHP logic (Models, Controllers)
├── helpers/ # Helper functions
├── views/ # Frontend and backend view templates
├── index.php # Plugin definition and entry point
├── oc-load.php # Imports PHP files for classes, helpers, etc.
└── main.php # Optional (for older Osclass versions)


3. Basic Plugin Setup

  • Create a folder, e.g., /oc-content/plugins/madhouse_helloworld/.
  • Add an index.php file for plugin metadata and hooks:
php
Copy code
/*
Plugin Name: Madhouse HelloWorld
Short Name: madhouse_helloworld
Description: A starter plugin example for Osclass.
Version: 1.2.0
Author: Madhouse
*/

require_once __DIR__ . '/oc-load.php';

function mdh_helloworld_install() {}
osc_register_plugin(osc_plugin_path(__FILE__), 'mdh_helloworld_install');

function mdh_helloworld_uninstall() {}
osc_add_hook(osc_plugin_path(__FILE__) . '_uninstall', 'mdh_helloworld_uninstall');

  • Create an empty oc-load.php file to load dependencies.

4. Model Layer

4.1. Database Schema​

Define the schema in SQL files:

  • Install(assets/model/install.sql):
    sql
    Copy code
    CREATE TABLE IF NOT EXISTS /*TABLE_PREFIX*/t_mdh_helloworld_message (
    `pk_i_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `s_content` VARCHAR(30) NOT NULL,
    PRIMARY KEY (`pk_i_id`)
    );
    INSERT INTO /*TABLE_PREFIX*/t_mdh_helloworld_message (s_content) VALUES ('Hello World');
  • Uninstall(assets/model/uninstall.sql):
    sql
    Copy code
    DROP TABLE IF EXISTS /*TABLE_PREFIX*/t_mdh_helloworld_message;

4.2. Create DAO Class​

Add a DAO (Data Access Object) for database interaction:

php
Copy code
class Madhouse_HelloWorld_Models_Message extends DAO {
private static $instance;

public static function newInstance() {
if (!self::$instance instanceof self) {
self::$instance = new self;
}
return self::$instance;
}

function __construct() {
parent::__construct();
$this->setTableName('t_mdh_helloworld_message');
$this->setPrimaryKey('pk_i_id');
$this->setFields(['pk_i_id', 's_content']);
}
}
 

h_a

Member
XNullUser
Joined
Aug 14, 2021
Messages
133
Reaction score
2
Points
18
NullCash
337
Thank You .....................................................................................
 
Top