PHP code example of vegas-cmf / dao

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

    

vegas-cmf / dao example snippets


use Phalcon\DiInterface;
use Vegas\DI\ServiceProviderInterface;

/**
 * Class DaoServiceProvider
 */
class DaoServiceProvider implements ServiceProviderInterface
{
    const SERVICE_NAME = 'dao';

    /**
     * {@inheritdoc}
     */
    public function register(DiInterface $di)
    {
        $di->set(self::SERVICE_NAME, function() use ($di) {
            $dao = new \Vegas\Db\Dao\Manager;
            return $dao->setDI($di);
        }, true);
    }

    public function getDependencies()
    {
        return [];
    }
}

$modelName = '\Foo\Models\Bar';
$model = new $modelName;

$daoManager = $this->getDI()->get('dao');

/** @var \Foo\Models\Dao\Bar $dao */
$dao = $daoManager->get($modelName);
// or
$dao = $daoManager->get($model);

/** @var \Foo\Models\Bar $result */
$result = $dao->findById('example_id');

/** @var \Foo\Models\Bar[] $results */
$results = $dao->findAll();