single/
    app/
        controllers/
        models/
        views/
    public/
        css/
        img/
        js/

                        
                    
                        
multiple/
     apps/
       frontend/
          controllers/
          models/
          views/
          Module.php
       backend/
          controllers/
          models/
          views/
          Module.php
       public/
       ../
                        
                    
                        
// 
$di = new Phalcon\DI();

// 
$di->set("request", new Phalcon\Http\Request());

..

// 
$request = $di->getShared('request');
                        
                    
                        
use Phalcon\Mvc\Micro;

$app = new Micro();

// 
$app->get(
    '/check/status',
    function () {
        return $this
            ->response
            ->setJsonContent(
                [
                    'status' => 'important',
                ]
            )
        ;
    }
);

$app->handle();
                        
                    
                        
use Phalcon\Loader;

// 
$loader = new Loader();

// 
$loader->registerNamespaces(
    [
       'Example\Base'    => 'vendor/example/base/',
       'Example\Adapter' => 'vendor/example/adapter/',
       'Example'         => 'vendor/example/',
    ]
);

// 
$loader->register();
                        
                    
                        
// 
$router = new \Phalcon\Mvc\Router();

// 
$router->add(
   '/admin/users/my-profile',
   [
       'controller' => 'users',
       'action'     => 'profile',
   ]
);
                        
                    
                        
use Invoices;
use Phalcon\Mvc\Model;

class Customers extends Model
{
    public $cst_id;

    public $cst_name;

    public function initialize()
    {
        $this->hasMany(
            'cst_id',
            Invoices::class,
            'inv_cst_id'
        );
    }
}
                        
                    
                        
$phql  = 'SELECT * '
       . 'FROM Formula\Cars '
       . 'ORDER BY Formula\Cars.name';
$query = $manager->createQuery($phql);

$phql  = 'SELECT Formula\Cars.name '
       . 'FROM Formula\Cars '
       . 'ORDER BY Formula\Cars.name';
$query = $manager->createQuery($phql);

$phql  = 'SELECT c.name '
       . 'FROM Formula\Cars c '
       . 'ORDER BY c.name';
$query = $manager->createQuery($phql);

$phql = 'SELECT c.* '
      . 'FROM Cars AS c '
      . 'ORDER BY c.name';
$cars = $manager->executeQuery($phql);

foreach ($cars as $car) {
    echo "Name: ", $car->name, "\n";
}
                        
                    
                        
use Phalcon\Mvc\Model\Transaction\Failed;
use Phalcon\Mvc\Model\Transaction\Manager;

try {

    // 
    $manager = new Manager();

    // 
    $transaction = $manager->get();

    // 
    $invoices = Invoices::find(
        'inv_cst_id = 123'
    );

    foreach ($invoices as $invoice) {
        $invoice->setTransaction($transaction);
        if ($invoice->delete() == false) {
            // 
            foreach ($invoice->getMessages() as $message) {
                $transaction
                    ->rollback($message->getMessage());
            }
        }
    }

    // 
    $transaction->commit();

    echo "";

} catch (Failed $e) {
    echo " ", $e->getMessage();
}
                        
                    
                        
use Phalcon\Cache;
use Phalcon\Cache\AdapterFactory;
use Phalcon\Storage\Serializer\SerializerFactory;

$serializerFactory = new SerializerFactory();
$adapterFactory    = new AdapterFactory($serializerFactory);

$options = [
    'defaultSerializer' => 'Json',
    'lifetime'          => 7200
];

$adapter = $adapterFactory
    ->newInstance('apcu', $options);

$cache = new Cache($adapter);
                        
                    
                        
<html>
    <body>
    <div class='top'>
        <?php $this->partial('shared/ad_banner'); ?>
    </div>
    <div class='content'>
        <h1>Robots</h1>
        <p>
            Check out our specials for robots:
        </p>
        ...
    </div>
    <div class='footer'>
        <?php $this->partial('shared/footer'); ?>
    </div>
    </body>
</html>
                        
                    
                        
{# app/views/products/show.volt #}
{% block last_products %}
{% for prod in products %}
    * Name: {{ prod.name|e }}
    {% if prod.status == 'Active' %}
       Price: {{ prod.price + prod.taxes/100}}
    {% endif  %}
{% endfor  %}
{% endblock %}
                        
                    
// app/messages/en.php
$messages = [
    'hi'      => 'Hello',
    'bye'     => 'Good Bye',
    'hi-name' => 'Hello %name%',
    'song'    => 'This song is %song%'
];

// app/messages/es.php
$messages = [
    'hi'      => 'Hola',
    'bye'     => 'Adiós',
    'hi-name' => 'Hola %name%',
    'song'    => 'Esta canción es %song%'
];

use Phalcon\Mvc\Controller;
use Phalcon\Translate\Adapter\NativeArray;

// UserController.php
class UserController extends Controller
{
    protected function getTranslation()
    {
        // 
        $language = $this
            ->request
            ->getBestLanguage();

        // 
        $fileName = 'app/messages/'
                  . $language
                  . '.php';
        if (file_exists($fileName) {
            require $fileName;
        } else {
            // 
            require 'app/messages/en.php';
        }

        // 
        return new NativeArray(
            array(
                'content' => $messages
            )
        );
    }

    public function indexAction()
    {
        $this->view->name = 'Mike';

        $this->view->t = $this
            ->getTranslation();
    }
}
// user.volt
<p><?php echo $t->_('hi'), ' ', $name; ?></p>
                        
                    
                        
use Phalcon\Forms\Form;
use Phalcon\Forms\Element\Text;
use Phalcon\Forms\Element\Select;

$form = new Form();

$form->add(new Text('name'));

$form->add(new Text('telephone'));

$form->add(
    new Select(
        'telephoneType',
        array(
            'H' => 'Home',
            'C' => 'Cellphone'
        )
    )
);
                        
                    
                        
use Phalcon\Mvc\Controller;

class PostsController extends Controller
{
    public function saveAction()
    {
        $this->flash->error(
            ''
        );
        $this->flash->success(
            ''
        );
        $this->flash->notice(
            ''
        );
        $this->flash->warning(
            ''
        );
    }
}
                        
                    
                        
use Phalcon\Acl;
use Phalcon\Acl\Enum;
use Phalcon\Acl\Role;
use Phalcon\Acl\Adapter\Memory;

// 
$acl = new Memory();

// 
$acl->setDefaultAction(Enum::DENY);

// 
// 
$roles = array(
    'users'  => new Role('Users'),
    'guests' => new Role('Guests')
);

foreach ($roles as $role) {
    $acl->addRole($role);
}
                        
                    
                        
use Phalcon\Db\Adapter\Pdo\Mysql;
use Phalcon\Db\Adapter\Pdo\PostgreSQL;

// 
$container->set(
    'dbMysql',
    function () {
        return new Mysql(
            [
                'host'     => 'localhost',
                'username' => 'root',
                'password' => 'secret',
                'dbname'   => 'tutorial',
            ]
        );
    }
);

// 
$container->set(
    'dbPostgres',
    function () {
        return new PostgreSQL(
            [
                'host'     => 'localhost',
                'username' => 'postgres',
                'password' => '',
                'dbname'   => 'invo',
            ]
        );
    }
);
                        
                    
                        
use Phalcon\Crypt;

$crypt = new Crypt();

$key  = '';
$text = '';

$encrypted = $crypt->encrypt($text, $key);

echo $crypt->decrypt($encrypted, $key);
                        
                    
                        
use Phalcon\Mvc\Dispatcher;
use Phalcon\Events\Manager;

$container->set(
    'dispatcher',
    function () {
        // 
        $manager = new Manager();

        // 
        // 
        $manager->attach(
            'dispatch:beforeExecuteRoute',
            new SecurityPlugin
        );

        // 
        // 
        $manager->attach(
            'dispatch:beforeException',
            new NotFoundPlugin
        );

        $dispatcher = new Dispatcher();

        // 
        // 
        $dispatcher
            ->setEventsManager($manager);

        return $dispatcher;
    }
);