Ko Joseph ahau. Nō Ōtautahi, Aotearoa ahau.
I'm Joseph and I'm from Christchurch, New Zealand.
If you want to know about my experience and my projects, you can find them here.
A simple installation of CodeIgniter 3 with Doctrine 2
Home Page: https://wildlyinaccurate.com/codeigniter-2doctrine-2-installation/
License: MIT License
Ko Joseph ahau. Nō Ōtautahi, Aotearoa ahau.
I'm Joseph and I'm from Christchurch, New Zealand.
If you want to know about my experience and my projects, you can find them here.
first, thank you for your nice work. i hope get your help.
I get some error, please see following info:
class Blog extends CI_Controller
{
// Doctrine EntityManager
public $em;
public function __construct()
{
parent::__construct();
$this->load->library('doctrine');
$this->em = $this->doctrine->em;
}
public function view()
{
$user = $this->em->getRepository('Entity\User')->find(1);
echo $user->username . '<br/>' . $user->email;
}
}
A PHP Error was encountered
Severity: Warning
Message: require(application/models/Proxies/__CG__EntityUserGroup.php): failed to open stream: No such file or directory
Filename: Proxy/ProxyFactory.php
Line Number: 92
we should do some things undel Proxies folder?
can you make some CURD sample?
Thanks :)
I am a newbie with doctrine . I am using this code with hardly any modification . I am not able to figure out as to how I could perform queries . As none of the methods mentioned online is working .
Thank You
Doctrine 2.5 has been released.
Doctrine 2.5
So please update this library.
I wanted to try your application, but I'm on Mac OSX and I've the problem that Doctrine.php and doctrine.php (Doctrine and doctrine, etc.) conflict (case insensitive). Is it possible for you to rename files which have the same name in the same folder ?
Many thanks.
First of all, many many thanks for your effort merging Doctrine 2 and CI 2!
When I cloned the master branch and I tried to execute the ./application/doctrine orm:schema-tool:create
commando. MySQL gave me the following two errors:
Schema-Tool failed with Error 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group (id)' at line 1' while executing DDL: ALTER TABLE user ADD CONSTRAINT FK_8D93D649FE54D947 FOREIGN KEY (group_id) REFERENCES group (id)
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group (id)' at line 1
The cause is fairly easy. You created a Entity named Group and named the table "group" but group is a keyword in MySQL.
I fixed the problem by renaming the table names for both User and Group to users and groups respectively.
Then the sql code generated is valid and accepted by MySQL.
Entity class generated via the console with convert-mapping:
application/models/Foo/Test.php
<?php
namespace Foo;
use Doctrine\ORM\Mapping as ORM;
/**
* Test
*
*@Table(name="test")
*@Entity
*/
class Test
{
/**
* @var integer $id
*
*@Column(name="id", type="integer", nullable=false)
*@Id
*@GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string $name
*
*@Column(name="name", type="string", length=8, nullable=false)
*/
private $name;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Test
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
}
Doctrine.php
<?php
// http://wildlyinaccurate.com/integrating-doctrine-2-with-codeigniter-2
use Doctrine\Common\ClassLoader,
Doctrine\ORM\Tools\Setup,
Doctrine\ORM\EntityManager;
class Doctrine
{
public $em;
public function __construct()
{
require_once __DIR__ . '/Doctrine/ORM/Tools/Setup.php';
Setup::registerAutoloadDirectory(__DIR__);
// Load the database configuration from CodeIgniter
require APPPATH . 'config/database.php';
$connection_options = array(
'driver' => 'pdo_mysql',
'user' => $db['default']['username'],
'password' => $db['default']['password'],
'host' => $db['default']['hostname'],
'dbname' => $db['default']['database'],
'charset' => $db['default']['char_set'],
'driverOptions' => array(
'charset' => $db['default']['char_set'],
),
);
// With this configuration, your model files need to be in application/models/Entity
// e.g. Creating a new Entity\User loads the class from application/models/Entity/User.php
$models_namespace = 'Foo';
$models_path = APPPATH . 'models';
$proxies_dir = APPPATH . 'models/Proxies';
$metadata_paths = array(APPPATH . 'models');
//Setup::registerAutoloadDirectory(__DIR__);
// Set $dev_mode to TRUE to disable caching while you develop
$config = Setup::createAnnotationMetadataConfiguration($metadata_paths, $dev_mode = true, $proxies_dir);
$this->em = EntityManager::create($connection_options, $config);
$loader = new ClassLoader($models_namespace, $models_path);
$loader->register();
}
}
Controller class:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class My_Controller extends CI_Controller {
// Doctrine EntityManager
public $em;
function __construct() {
parent::__construct();
$this->load->library('doctrine');
$this->em = $this->doctrine->em;
}
function index() {
$user = new Foo\Test;
}
}
In the debugger I can see that Doctrine.php registers my ‘Foo’ classloader with the correct namespace and includepath. When it comes to execute $user = new Foo\Test; the invoked classloader object’s namespace is ‘Doctrine’ and the includepath is application/libraries/Doctrine therefore loadClass() fails. This seems to be the class loader registered via Setup::registerAutoloadDirectory(DIR); line 15 of Doctrine.php
Any idea what is happening here? Would be very grateful for any suggestions as to how to fix this!
add 2 lines after
line 48 "$config->setMetadataDriverImpl($driverImpl);"
in /application/libraries/Doctrine.php
$driver = new YamlDriver(array(APPPATH . 'yaml'));
$config->setMetadataDriverImpl($driver);
can use :
1 creat yaml from schema
./doctrine orm:convert-mapping -v --from-database yml ./application/yaml/
2 creat entity from yaml
./doctrine orm:generate-entities --generate-annotations=true --update-entities=true ./models/
hi Joseph,i like your quick stack CodeIgniter-2-with-Doctrine-2,could you combine smarty on to it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.