PHP code example of daycry / doctrine

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

    

daycry / doctrine example snippets


$psr4 = [
    'Config'      => APPPATH . 'Config',
    APP_NAMESPACE => APPPATH,
    'App'         => APPPATH,
    'Daycry\Doctrine' => APPPATH .'ThirdParty/doctrine/src',
];

$doctrine = new \Daycry\Doctrine\Doctrine();
$data = $doctrine->em->getRepository( 'App\Models\Entity\Class' )->findOneBy( array( 'id' => 1 ) );
var_dump( $data );


$doctrine = \Config\Services::doctrine();
$data = $doctrine->em->getRepository( 'App\Models\Entity\Class' )->findOneBy( array( 'id' => 1 ) );
var_dump( $data );


protected $helpers = [ 'doctrine_helper' ];



$doctrine = doctrine_instance();
$data = $doctrine->em->getRepository( 'App\Models\Entity\Class' )->findOneBy( array( 'id' => 1 ) );
var_dump( $data );



//Mapping de database to entities classes
php cli-config.php orm:convert-mapping --namespace="App\Models\Entity\" --force --from-database annotation .

//Generate getters & setters
php cli-config.php orm:generate-entities .

//Generate proxy classes
php cli-config.php orm:generate-proxies app/Models/Proxies


    composer dump-autoload


$datatables = ( new \Daycry\Doctrine\DataTables\Builder() )
            ->withColumnAliases(
                [
                    'id' => 'qlu.id'
                ]
            )
            ->withIndexColumn( 'qlu.id' )
            ->withQueryBuilder(
                $this->doctrine->em->createQueryBuilder()
                    ->select( 'qlu.param, q.param, q.param, qs.id as param, qlu.param, qlu.param' )
                    ->from( \App\Models\Entity\Class::class, 'qlu' )
                    ->innerJoin( \App\Models\Entity\Class::class, 'qs', \Doctrine\ORM\Query\Expr\Join::WITH, 'qs.id = qlu.*' )
                    ->innerJoin( \App\Models\Entity\Class::class, 'ql', \Doctrine\ORM\Query\Expr\Join::WITH, 'ql.id = qlu.*' )
                    ->innerJoin( \App\Models\Entity\Class::class, 'q', \Doctrine\ORM\Query\Expr\Join::WITH, 'q.id = ql.*' )
            )
            ->withRequestParams( $this->request->getGet( null ) );
        
        $response = $datatables->getResponse();

        echo \json_encode( $response );



    ->setUseOutputWalkers( false )


$datatables = ( new \Daycry\Doctrine\DataTables\Builder() )
            ->withColumnAliases(
                [
                    'id' => 'qlu.id'
                ]
            )
            ->withIndexColumn( 'qlu.id' )
            ->setUseOutputWalkers( false )
            ->withQueryBuilder(
                $this->doctrine->em->createQueryBuilder()
                    ->select( 'qlu.param, q.param, q.param, qs.id as param, qlu.param, qlu.param' )
                    ->from( \App\Models\Entity\Class::class, 'qlu' )
                    ->innerJoin( \App\Models\Entity\Class::class, 'qs', \Doctrine\ORM\Query\Expr\Join::WITH, 'qs.id = qlu.*' )
                    ->innerJoin( \App\Models\Entity\Class::class, 'ql', \Doctrine\ORM\Query\Expr\Join::WITH, 'ql.id = qlu.*' )
                    ->innerJoin( \App\Models\Entity\Class::class, 'q', \Doctrine\ORM\Query\Expr\Join::WITH, 'q.id = ql.*' )
            )
            ->withRequestParams( $this->request->getGet( null ) );
        
        $response = $datatables->getResponse();

        echo \json_encode( $response );



public function testDataTableSearchColumnWithOr()
    {
        $doctrine = new \Daycry\Doctrine\Doctrine($this->config);
        $request = \Config\Services::request();

        $datatables = ( new \Daycry\Doctrine\DataTables\Builder() )
            ->withColumnAliases(
                [
                    'id' => 't.id',
                    'name' => 't.name'
                ]
            )
            ->withIndexColumn('qlu.id')
            ->setUseOutputWalkers(false)
            ->withCaseInsensitive(false)
            ->withColumnField('name')
            ->withQueryBuilder(
                $doctrine->em->createQueryBuilder()
                    ->select('t.id, t.name')
                    ->from(\Tests\Support\Models\Entities\Test::class, 't')
            )
            ->withRequestParams(
                array(
                    'draw' => 1,
                    'start' => 0,
                    'length' => 10,
                    'search' => array('value' => '', 'regex' => true ),
                    'columns' => array(
                        array(
                            'data' => 'id',
                            'name' => 'id',
                            'searchable' => true,
                            'orderable' => true,
                            'search' => array('value' => '[OR]1,3', 'regex' => false)
                        ),
                        array(
                            'data' => 'name',
                            'name' => 'name',
                            'searchable' => true,
                            'orderable' => true,
                            'search' => array('value' => '', 'regex' => false)
                        )
                    ),
                    'order' => array( array( 'column' => 0, 'dir' => 'asc') )
                )
            );

        echo $response = json_encode($datatables->getResponse());

    }