1. Go to this page and download the library: Download ray/cake-database-module 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/ */
ray / cake-database-module example snippets
use Ray\Di\AbstractModule;
use Ray\CakeDbModule\CakeDbModule;
class AppModule extends AbstractModule
{
protected function configure()
{
$this->install(new CakeDbModule('sqlite:///'));
// or
$this->install(new CakeDbModule('mysql://root@localhost/cake_db'));
}
}
use Ray\Di\AbstractModule;
use Ray\CakeDbModule\CakeDbModule;
class AppModule extends AbstractModule
{
protected function configure()
{
$config = [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'username' => 'root',
'password' => 'root',
'database' => 'cake'
];
$this->install(new CakeDbModule($config));
}
}
ConnectionManager::config('default', $config);
use Ray\Di\AbstractModule;
use Ray\CakeDbModule\CakeDbModule;
class AppModule extends AbstractModule
{
protected function configure()
{
$this->install(new CakeDbModule('default'));
}
}
use Ray\CakeDbModule\DatabaseInject;
class MyThing
{
use DatabaseInject;
}
use DateTime;
use Ray\CakeDbModule\Annotation\Trasactional;
use Ray\CakeDbModule\DatabaseInject;
class MyThing
{
use DatabaseInject;
/**
* This will run inside a new transaction
*
* @Transactional
*/
public function storeSomething()
{
$this->db->insert(
'posts',
['name' => 'First', 'show_on' => new DateTime('+3 days')],
['created' => 'datetime']
);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.