PHP code example of gp / sys

1. Go to this page and download the library: Download gp/sys 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/ */

    

gp / sys example snippets


// src/DataModel/App.php
namespace App\DataModel;

use System\Core\Data\DataRecord;

class App extends DataRecord
{
    public $id;
    public $name;
    public $version;
    public $description;
    public $author;
    public $created_at;
    public $updated_at;

    public function table(): string { return 'app'; }
    public function primaryKey(): string { return 'id'; }
}

// src/Module/App/Controller/AppController.php
namespace App\Module\App\Controller;

use App\Module\App\View\AppView;
use System\Core\Base\Controller\Controller;

class AppController extends Controller
{
    public function indexPage()
    {
        $view = new AppView();
        $view->addContents($view->getHomePage());
        return $view->get();
    }
}

// src/Module/App/routes.php
use Router\Router;

return [
    ['/', 'app/indexPage'],
    ['/home', 'app/indexPage2'],
];

// src/Module/App/services.php
return [
    'appService' => function() {
        return new \App\Service\AppService();
    },
    'bookService' => BookService::class,
    'test' => [
        'class' => Test::class,
        'params' => [
            'param1' => 'value1',
            'param2' => 'value2',
        ],
        'singleton' => true
    ]
    // Add more services here
];

// src/Module/Crud/autoloads.php
return [
    'helper' => [
        __DIR__ . '/Helper/CrudHelper.php',
    ],
    'service' => [
        'app' => AppService::class
    ],
    'model' => [
        'app' => App::class
    ],
    'library' => [
        'Cache' => Cache::class
    ]
];

public class AppController {
    public function action() {
        $service = $this->load->service->app; // AppService object.
        $model = $this->load->model->app; // App object.
        $library = $this->load->library->cache; // Cache library object.

        // to load not registered class
        $this->loader->service(AppService::class);// service
        $this->loader->model(AppModel::class);// model
        $this->loader->library(Library::class); // library
        $this->loader->helper('helper_file.php'); // helper
    }
}


return [
    'default' => [
        'host' => 'localhost',
        'user' => 'youruser',
        'password' => 'yourpass',
        'database' => 'yourdb',
        'driver' => 'pdo/mysql',
    ]
];