Git Product home page Git Product logo

codeigniter-with-doctrine-2's Introduction

CodeIgniter with Doctrine

This is a simple CodeIgniter installation with Doctrine 2. It contains sample models in application/models/Entity and usage examples in application/controllers/welcome.php.

The master branch contains an installation of CodeIgniter 3. You can find the CodeIgniter 2 version of this repository in the codeigniter-2 branch.

Dev Mode

Dev mode is disabled by default, but you can enable it by setting $dev_mode = true; in application/libraries/Doctrine.php. This will auto-generate proxies and use a non-persistent cache (ArrayCache). Remember to turn dev mode off for production!

For more information on how to configure Doctrine, read Integrating Doctrine 2 with CodeIgniter 2

codeigniter-with-doctrine-2's People

Contributors

shantanu1227 avatar wildlyinaccurate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codeigniter-with-doctrine-2's Issues

Message: require(application/models/Proxies/__CG__EntityUserGroup.php): failed to open stream: No such file or directory

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 :)

On another system that Linux

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.

Example entities generates MySQL errors

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.

Doctrine quicky consol tools

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/

Fatal error: Class ‘Test’ not found

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!

why no combine smarty

hi Joseph,i like your quick stack CodeIgniter-2-with-Doctrine-2,could you combine smarty on to it?

Unable to perform any queries

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.