heavenshell/php-silex-zf-db

There is no license information available for the latest version (dev-master) of this package.

Silex provider for Zend_Db

dev-master 2016-09-21 15:37 UTC

This package is not auto-updated.

Last update: 2024-05-01 17:21:29 UTC


README

Silex Zend_Db extension.

This extension is for the Silex microframework enables use Zend Framework's Zend_Db.

    <?php
    require_once 'silex.phar';
    require_once dirname(__DIR__) . '/src/Zf1/DbExtension.php';

    $zendpath = getenv('ZF_PATH');

    $app = new Silex\Application();
    $app->register(new \Zf1\DbExtension(), array(
        'zend.class_path' => $zendpath,
        'zend.db.adapter' => 'Pdo_Sqlite',
        'zend.db.options' => array(
            'dbname' => __DIR__ . '/test.db',
        )
    ));

    $app->before(function() use ($app) {
        $db    = $app['zend.db']();
        $conn  = $db->getConnection();
        $app['zend.db.connection'] = $conn;

        // When you use Model class, add to namespace.
        // If you not using namespace, use registerPrefix() instead.
        $app['autoloader']->registerNamespace('Model', __DIR__);
    });

    $app->get('/create', function () use ($app) {
        $db = $app['zend.db']();
        $db->insert(
            'entries', array('title' => 'test_title', 'text' => 'test_text')
        );
        $table = new \Model\Entries();
        $row   = $table->fetchAll();
        return json_encode($row->toArray());
    });

Set Zend Framework1 library to your include_path
- Running examples
  Add SetEnv ZF_PATH /Path/To/include_path to .htaccess
- Running tests
  export ZF_PATH=/Path/To/include_path

See more detail http://framework.zend.com/manual/en/zend.db.html