PHP code example of elcreator / aphalcon

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

    

elcreator / aphalcon example snippets


// core/custom/config/aphalcon.php
return [
    // null → Phalcon\Di\FactoryDefault; or a class name / callable returning a DiInterface
    'di' => null,

    // The CMS connection, as a Phalcon PDO adapter under this service name
    'db' => ['connection' => null, 'service' => 'db'],

    // Phalcon\Di\ServiceProviderInterface classes (or callables taking the DI):
    // the site's models and services
    'providers' => [
        App\Providers\ModelsProvider::class,
    ],

    // null → a Micro built from routes.handlers; or a class name / callable
    // returning a Phalcon\Mvc\Micro or Phalcon\Mvc\Application
    'app' => null,

    'routes' => [
        'prefix' => 'app',          // mounted at /app/...; '' mounts nothing
        'middleware' => ['web'],
        'handlers' => [             // Micro only: Collection classes, or callables (Micro $app, DiInterface $di)
            App\Routes\Api::class,
        ],
    ],

    'frontend' => [
        'takeover' => false,    // true: Phalcon serves the whole front end (see below)
        'fallback' => true,     // hand what it cannot render back to the CMS parser
    ],

    'latte' => ['function' => 'phalcon'],   // the Latte function name; '' for none
];

final class Article extends Phalcon\Mvc\Model
{
    public function initialize(): void
    {
        $this->setSource($this->getDI()->get('tablePrefix') . 'articles');
    }
}

// core/custom/config/alattex.php
return ['evo_tags' => false];

final class Api
{
    public function __invoke(Phalcon\Mvc\Micro $app, Phalcon\Di\DiInterface $di): void
    {
        // GET /app/articles → views/articles.latte, rendered by aLatteX
        $app->get('/articles', function () use ($app) {
            return $app->cms->respond('articles', [
                'articles' => Article::find(['order' => 'id DESC']),
            ]);
        });

        // GET /app/articles.json → an array is JSON
        $app->get('/articles.json', function () {
            return Article::find()->toArray();
        });

        // A string, an echo, or status/headers set on $app->response all work too
        $app->get('/missing', function () use ($app) {
            $app->response->setStatusCode(404);

            return $app->cms->view('not-found');
        });
    }
}

'frontend' => ['takeover' => true],

$app->get('/latest', function () use ($app) {
    return $app->site->document((int) $app->documents->latest(1)[0]->id);
});
bash
cd core
php artisan package:install"Elcreator\aPhalcon\aPhalconServiceProvider"
latte
<h1>{$pagetitle}</h1>
<p>{phalcon('greeter')->greet($pagetitle)}</p>

<ul>
    <li n:foreach="phalcon('articles')->latest(5) as $article">
        <a href="{$evo->makeUrl($article->document_id)}">{$article->title}</a>
    </li>
</ul>

{var $di = phalcon()}