PHP code example of jmrg / chip-modules

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

    

jmrg / chip-modules example snippets


// Load file...
ConfigModule::init('path/to/file/config.yaml');

// Getting config...
$c = config(); // Return the config as array.

// Creates a new object to the configuration.
$config = new \Chip\Modules\Router\RouterConfig();
$config->setBaseNamespace("\\Namespace\\to\\controllers") // Namespace source path.
    ->attachRouterFiles('path/to/endpoints/router.php'); // Location for the file router.

// Dispatch resquest.
$r = \Chip\Modules\Router\Router::up($config);
$r->dispatch();

// File router.php

// Methods availables according to HTTP verbs: get(), post(), put(), pat(), delete(), options().
$router->get('/hellow-world', function () {
    return 'Hellow World!!';
});

// To response multiple HTTP verbs:
$router->match(['get', 'post'], '/hellow-world', function () {
    return 'Hellow World!!';
});

// In the file configuration environment, we have a sections with the
// connections to the different databases, we only must send
// a connections name to configure de database.

\Chip\Modules\Model\Manager::db('nameDatabase');

// In the case of models, these must extend from \Chip\Modules\Model\Model
class User extend \Chip\Modules\Model\Model
{
    // Something code..
}

// Recomended to use name "guest" for the session.
\Chip\Modules\Session\Session::of('Guest'); 

// To get the session to use a guest() method.
// This returns an instance of Hoa Session. Check out the documentation
// of lirary for any information https://github.com/hoaproject/Session
$session = guest();

// Define path to views and cache.
ViewComponent::config(
    '/path/to/source/views',
    '/path/to/cache'
);

// Load the view...
view(
    'name-view',
    ['param1' => 'Hello', 'param2' => 'World!!']
);

// To build views check out the documentation https://laravel.com/docs/5.1/blade

// Create a new isntance Mailer class.
$mailer = \Chip\Modules\Mailer\Mailer::create();

// To send emails or making config aditionals check out the documentation https://github.com/PHPMailer/PHPMailer