PHP code example of xueron / fastd-phalcon

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

    

xueron / fastd-phalcon example snippets



return [
    // 省略了无关配置
    'services' => [
        \Xueron\FastDPhalcon\PhalconServiceProvider::class,
    ],
];


return [
    // 省略了其他配置
    'phalcon' => [
        'debug' => false, // 开启后,会DEBUG日志打印数据库调试日志。DEBUG日志在app.php中配置
        'antiidle' => false, // 开启后,会通过定时器定时访问一下数据库,方式发呆断线
        'interval' => 100, // 防发呆定时间隔,单位秒,建议比mysql的wait_timeout略短
        'maxretry' => 3, // 出现断线,自动重连的尝试次数,尝试多次不成功,worker会退出
    ]
];


namespace Model;

use Xueron\FastDPhalcon\Model\Model;

class Subscription extends Model
{
    // 指定表名称,默认与Model类名相同
    public function getSource()
    {
        return 'subscriptions';
    }
}


use Phalcon\Paginator\Factory;

$builder = phalcon_builder()
                ->columns('id, name')
                ->from('Robots')
                ->orderBy('name');

$options = [
    'builder' => $builder,
    'limit'   => 20,
    'page'    => 1,
    'adapter' => 'queryBuilder',
];

$paginator = Factory::load($options);


use Phalcon\Paginator\Adapter\QueryBuilder as PaginatorQueryBuilder;

        $builder = phalcon_builder()
            ->columns('id, name')
            ->from(Subscription::class)
            ->orderBy('name');

        $paginator = new PaginatorQueryBuilder(
            [
                'builder' => $builder,
                'limit'   => 20,
                'page'    => 1,
            ]
        );

        return json([
            'model' => (Subscription::class),
            'data' => $paginator->getPaginate()
        ]);