https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_b964594d3d957944241961017b9eb19bf02834de44cce93d8e67dd306852dbe346167181e455e33d5268ea01d973d77bb056848546f31794f31a4c31a9da5aa3.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_09f62869dbd00446535ebe8e270406331e6f0ae459deba58094caeadc22d58825ffc99f8c217b496ec112cbb1da8b662d77b0f52eae24cc5631f95695e40d87b.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_e6b7e0bf68aa4a61d5c6a0065ec42e38a0cc53e39a4fbee057b72d4b2297b37c01e716e1e61bac7f240b5a0edbb178d37b62f7ed4ea4ea3d10e46dbe7429f326.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_bfff9e63e857e9ee612e292d4a6edf3ced64d6a756925c953a9d8f77845ff601eca64d73dfa48756b1a9f4a4d6de6127a273bcde16ddeb71a22383460f4e94b0.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_f4dd7e1d73ae5eda35ed5ad6aa965b612dbf483ece3ca50c1e8e30ad8dff1c66a160ed75e958e2db399661d229874783e0834ad813a479437035666b8e9e3386.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_4fce0769137d4cd096989b0349bc3c2bbfca79ac311fdf714c41ab24d87551c7b49b756c8a8de090b0714a0ad0560e49fa532ba5a88875ea4afd78efac464df6.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_85cec8b07d60426b11040e471babca0d2f9c8dc87a9b56e06cad39828f7f67179e29609100f282a574872c9a93fb635b25416300eb4c97bc5a653d00cf6f8dbf.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_6768e5a27d4d357347338621c0d20bd269b126d30eec796193390f2f530fbaea60af84130c46f9786114be65149e661e87d55c339219c90aa76396d7e5b734ef.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_2acd6bdff3b680341e8c727da5169a647123eb8fd0a90253161b4c3af272c15d293bf9bb217008bb13f84d1910b0e166798001f8603b6c026d5c20a76c41d47c.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_53a32281a275ead63ac2b0e8983cec6c2e0c58c6c7c748b93fa9c1dd14d48ece8197f15ecfc995867c165b3a13950e7827331366a458aa4f1560b97ae8f151bb.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_268c9bba6ba649318f0da28c37b09a9bbfa371210f9b6b52faa7fd8ae94abf6b3c3bfeb5df5705c93495ce1152ca58aeabc435d6c6c1bd959025165c3f50e086.js
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Featured
    • Advanced Python Topics
    • AWS Learning Roadmap
    • JWT Complete Guide
    • Git CheatSheet
  • Explore
    • Programming
    • Development
      • microservices
      • Front End
    • Database
    • DevOps
    • Productivity
    • Tutorial Series
      • C# LinQ Tutorials
      • PHP Tutorials
  • Dev Tools
    • JSON Formatter
    • Diff Checker
    • JWT Decoder
    • JWT Generator
    • Base64 Converter
    • Data Format Converter
    • QR Code Generator
    • Javascript Minifier
    • CSS Minifier
    • Text Analyzer
  • About
  • Contact
CodeSamplez.com

CodeSamplez.com

Programming And Development Resources

You are here: Home / Development / Doctrine With CodeIgniter: DB Modeling In CodeIngiter Like A Pro

Doctrine With CodeIgniter: DB Modeling In CodeIngiter Like A Pro

Updated May 24, 2025 by Rana Ahsan 24 Comments ⏰ 10 minutes

doctrine with codeigniter

Are you tired of CodeIgniter’s native database handling and craving the power of a robust ORM? Look no further! This comprehensive guide will show you exactly how to integrate Doctrine with CodeIgniter for a supercharged development experience.

Why Use Doctrine With CodeIgniter?

While CodeIgniter offers a decent Active Record pattern implementation for database operations, many developers (myself included) prefer working with a full-featured ORM. The combination of CodeIgniter’s lightweight framework and Doctrine’s powerful ORM capabilities creates an absolutely fantastic development environment.

I’ve previously covered CodeIgniter basics, but today I’m diving into something that will completely transform your CodeIgniter development experience. Doctrine integration solves one of CodeIgniter’s biggest limitations: the lack of a built-in ORM system.

What You’ll Learn in This Guide

  • How to install and configure Doctrine with CodeIgniter
  • Creating a custom library to handle the integration
  • Generating entity classes from your database automatically
  • Practical examples of using Doctrine within your CodeIgniter applications
  • Setting up the command-line tools for advanced operations

Let’s get started with this game-changing integration!

Prerequisites

Before diving in, you should have:

  • Basic knowledge of CodeIgniter framework
  • Understanding of what Doctrine is and its basic concepts
  • PHP 5.3+ installed on your server (Doctrine requires namespaces)

Installation and Setup

Step 1: Download and Install Doctrine

First, you need to get your hands on the latest Doctrine ORM package. You have two options:

Option 1: Direct Download

  1. Download the latest Doctrine ORM from the official website
  2. Extract the contents
  3. Copy the extracted ‘doctrine’ directory to your CodeIgniter application’s ‘third_party’ directory

Option 2: Using Composer (Recommended) If you’re already using Composer with CodeIgniter (which is a fantastic practice), simply add Doctrine as a dependency in your composer.json file:

"require": {
    "doctrine/orm": "^2.14"
}Code language: JavaScript (javascript)

Then run composer update to install Doctrine and its dependencies.

Step 2: Create the Doctrine Library

Now, let’s create a custom library to handle the Doctrine initialization. Create a new file named ‘Doctrine.php’ in your ‘application/libraries’ directory:

<?php

use Doctrine\Common\ClassLoader,
    Doctrine\ORM\Configuration,
    Doctrine\ORM\EntityManager,
    Doctrine\Common\Cache\ArrayCache,
    Doctrine\DBAL\Logging\EchoSQLLogger,
    Doctrine\ORM\Mapping\Driver\DatabaseDriver,
    Doctrine\ORM\Tools\DisconnectedClassMetadataFactory,
    Doctrine\ORM\Tools\EntityGenerator;

/**
 * CodeIgniter Doctrine Integration
 *
 * A custom library that initializes Doctrine ORM within CodeIgniter
 * 
 * @author Md. Ali Ahsan Rana
 * @link https://codesamplez.com/
 */
class Doctrine
{
    /**
     * @var EntityManager $em
     */
    public $em = null;

    /**
     * Constructor - Sets up Doctrine integration
     */
    public function __construct()
    {
        // Load database configuration from CodeIgniter
        require APPPATH.'config/database.php';

        // Set up class loading
        require_once APPPATH.'third_party/Doctrine/Common/ClassLoader.php';
        
        $doctrineClassLoader = new ClassLoader('Doctrine', APPPATH.'third_party');
        $doctrineClassLoader->register();
        
        $entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, "/" ));
        $entitiesClassLoader->register();
        
        $proxiesClassLoader = new ClassLoader('proxies', APPPATH.'models');
        $proxiesClassLoader->register();

        // Set up caches
        $config = new Configuration;
        $cache = new ArrayCache;
        $config->setMetadataCacheImpl($cache);
        
        // Set up driver
        $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH.'models/Entities'));
        $config->setMetadataDriverImpl($driverImpl);
        
        $config->setQueryCacheImpl($cache);

        // Proxy configuration
        $config->setProxyDir(APPPATH.'models/proxies');
        $config->setProxyNamespace('Proxies');
        
        // Enable auto-generation of proxy classes for development
        $config->setAutoGenerateProxyClasses(TRUE);

        // Database connection from CI config
        $connectionOptions = array(
            'driver'   => 'pdo_mysql',
            'user'     => $db['default']['username'],
            'password' => $db['default']['password'],
            'host'     => $db['default']['hostname'],
            'dbname'   => $db['default']['database']
        );

        // Create EntityManager
        $this->em = EntityManager::create($connectionOptions, $config);
        
        // Uncomment the line below once to generate entities, then comment it out again
        // $this->generate_entities();
    }
    
    /**
     * Generate entity classes automatically from database tables
     * 
     * @return void
     */
    public function generate_entities()
    {
        // Register MySQL types with Doctrine
        $platform = $this->em->getConnection()->getDatabasePlatform();
        $platform->registerDoctrineTypeMapping('enum', 'string');
        
        // Set up metadata driver from database schema
        $this->em->getConfiguration()
            ->setMetadataDriverImpl(
                new DatabaseDriver(
                    $this->em->getConnection()->getSchemaManager()
                )
            );
        
        // Create metadata factory
        $cmf = new DisconnectedClassMetadataFactory();
        $cmf->setEntityManager($this->em);
        $metadata = $cmf->getAllMetadata();
        
        // Configure entity generator
        $generator = new EntityGenerator();
        $generator->setUpdateEntityIfExists(true);
        $generator->setGenerateStubMethods(true);
        $generator->setGenerateAnnotations(true);
        
        // Generate entities
        $generator->generate($metadata, APPPATH."models/Entities");
    }
}Code language: HTML, XML (xml)

IMPORTANT ⚠️: This implementation requires PHP 5.3+ because it uses namespaces. Make sure your server supports this version or higher.

Step 3: Create Required Directories

You’ll need to create two directories inside your ‘application/models’ folder:

  1. application/models/Entities – This will store your entity classes
  2. application/models/proxies – For Doctrine’s proxy classes

Step 4: Load the Library

To use Doctrine in your application, you need to load it. The best approach is to autoload it by adding ‘doctrine’ to your autoload.php config file:

$autoload['libraries'] = array('database', 'doctrine');Code language: PHP (php)

Generating Entity Classes From Your Database

One of the most powerful features of Doctrine is the ability to generate entity classes directly from your existing database structure. The generate_entities() method in our Doctrine library handles this process.

Pro Tip 💡: Only call the generate_entities() method once when you first set up your application or when your database structure changes. Comment it out after running it once to avoid performance issues.

How Entity Generation Works

The entity generation process:

  1. Examines your database schema using Doctrine’s DatabaseDriver
  2. Creates metadata for each table structure
  3. Generates PHP entity classes with proper annotations
  4. Places these classes in your application/models/Entities directory

When you run your application with the generate_entities() method uncommented, Doctrine will create entity classes for all your database tables.

A Real-World Example: Contact Form

Let’s apply what we’ve learned to a practical example – handling a contact form submission with Doctrine.

Step 1: Create the Database Table

First, create a table in your MySQL database:

CREATE TABLE `pd_contact` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `email` varchar(50) NOT NULL,
  `subject` varchar(100) NOT NULL,
  `message` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;Code language: JavaScript (javascript)

Step 2: Generate the Entity Class

After running your application with the generate_entities() method active, Doctrine will create a PdContact.php entity class in your application/models/Entities directory. It should look something like this:

<?php
/**
 * PdContact
 *
 * @Table(name="pd_contact")
 * @Entity
 */
class PdContact
{
    /**
     * @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=50, nullable=false)
     */
    private $name;

    /**
     * @var string $email
     *
     * @Column(name="email", type="string", length=50, nullable=false)
     */
    private $email;

    /**
     * @var string $subject
     *
     * @Column(name="subject", type="string", length=100, nullable=false)
     */
    private $subject;

    /**
     * @var text $message
     *
     * @Column(name="message", type="text", nullable=false)
     */
    private $message;

    // Getters and setters are automatically generated
    // ...
}Code language: HTML, XML (xml)

Step 3: Create a Model for Business Logic

Now, let’s create a model that will handle the business logic for our contact form:

<?php
require_once(APPPATH."models/Entities/PdContact.php");

use \PdContact;

/**
 * Home model for contact form operations
 */
class Homemodel extends CI_Model
{
    /**
     * @var \Doctrine\ORM\EntityManager $em
     */
    var $em;

    public function __construct()
    {
        parent::__construct();
        $this->em = $this->doctrine->em;
    }

    /**
     * Add contact messages to database
     * 
     * @return bool
     */
    function add_message()
    {
        // Create a new entity instance
        $contact = new PdContact();
        
        // Set properties from form data
        $contact->setName($this->input->post("name"));
        $contact->setEmail($this->input->post("email"));
        $contact->setSubject($this->input->post("subject"));
        $contact->setMessage($this->input->post("message"));

        try {
            // Save to database
            $this->em->persist($contact);
            $this->em->flush();
            return true;
        } catch(Exception $err) {
            log_message('error', $err->getMessage());
            return false;
        }
    }
    
    /**
     * Get all contact messages
     * 
     * @return array
     */
    function get_all_messages()
    {
        return $this->em->getRepository('PdContact')->findAll();
    }
}Code language: HTML, XML (xml)

Step 4: Use in Your Controller

Finally, you can use this model in your controller:

<?php
class Contact extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('homemodel');
    }
    
    public function index()
    {
        $this->load->view('contact_form');
    }
    
    public function submit()
    {
        if ($this->homemodel->add_message()) {
            $this->session->set_flashdata('success', 'Message sent successfully!');
        } else {
            $this->session->set_flashdata('error', 'Failed to send message.');
        }
        
        redirect('contact');
    }
}Code language: HTML, XML (xml)

Tip 💡: Level up your web development skill with our codeigniter learning roadmap

Using Doctrine’s Command Line Tools

Doctrine provides powerful command line tools for various operations like schema validation, entity generation, and more. Let’s set them up for use with CodeIgniter.

Creating the CLI Configuration

Create a file named cli-config.php in your project’s root directory:

<?php
$system_path = 'system';
$application_folder = 'application';

define('BASEPATH', str_replace("\\", "/", $system_path));
define('APPPATH', $application_folder.'/');

// Include composer autoloader if using composer
include __DIR__."/vendor/autoload.php";

// Include our Doctrine library
include __DIR__."/application/libraries/doctrine.php";

// Initialize Doctrine
$doctrine = new Doctrine();
$em = $doctrine->em;

// Set up helper set for command line tools
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
    'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
    'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));

return $helperSet;Code language: HTML, XML (xml)

Using the Command Line Tools

Now you can use Doctrine’s command line tools. Here are some examples:

# Validate your schema
./vendor/bin/doctrine orm:validate-schema

# Generate proxy classes
./vendor/bin/doctrine orm:generate-proxies

# Create schema from entities
./vendor/bin/doctrine orm:schema-tool:createCode language: PHP (php)

Advanced Usage Tips

1. Working with Repository Classes

For complex queries, you can create custom repository classes:

<?php
// In Entity class
/**
 * @Entity(repositoryClass="PdContactRepository")
 */
class PdContact
{
    // ...
}

// In Repository class
class PdContactRepository extends \Doctrine\ORM\EntityRepository
{
    public function findRecent($limit = 5)
    {
        return $this->createQueryBuilder('c')
                    ->orderBy('c.id', 'DESC')
                    ->setMaxResults($limit)
                    ->getQuery()
                    ->getResult();
    }
}Code language: HTML, XML (xml)

2. Handling Relationships

Doctrine makes it easy to work with relationships between entities:

<?php
/**
 * @Entity
 */
class User
{
    /**
     * @OneToMany(targetEntity="PdContact", mappedBy="user")
     */
    private $contacts;
    
    public function __construct()
    {
        $this->contacts = new \Doctrine\Common\Collections\ArrayCollection();
    }
    
    // ...
}

/**
 * @Entity
 */
class PdContact
{
    /**
     * @ManyToOne(targetEntity="User", inversedBy="contacts")
     */
    private $user;
    
    // ...
}Code language: HTML, XML (xml)

3. Using DQL for Complex Queries

Doctrine Query Language (DQL) is extremely powerful for complex data retrieval:

$query = $this->em->createQuery('
    SELECT c FROM PdContact c
    WHERE c.email LIKE :email
    ORDER BY c.id DESC
');
$query->setParameter('email', '%gmail.com');
$results = $query->getResult();Code language: PHP (php)

Troubleshooting Common Issues

Issue 1: “Class is not a valid entity or mapped super class”

This often happens when:

  • You haven’t generated entity classes correctly
  • The namespace is wrong
  • You’re trying to use an entity without requiring/importing it

Solution: Make sure your entity class has the @Entity annotation and is properly imported.

Issue 2: “Unknown database type enum requested”

Doctrine doesn’t natively support MySQL’s ENUM type.

Solution: Add type mapping in the generate_entities() method:

$platform = $this->em->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');Code language: PHP (php)

Issue 3: “Failed to open stream: No such file or directory”

This usually indicates incorrect file paths.

Solution: Double-check your directory structure and make sure all paths are correct.

Conclusion

Integrating Doctrine with CodeIgniter gives you the best of both worlds – a lightweight, fast framework paired with a powerful ORM system. This combination provides incredible flexibility for your PHP applications, particularly when dealing with complex database operations.

By following this guide, you now have a robust integration that allows you to:

  • Use object-oriented database access
  • Generate entity classes automatically
  • Leverage Doctrine’s powerful query capabilities
  • Maintain clean, maintainable code

Remember to use the generate_entities() method only when necessary, and take advantage of Doctrine’s command line tools for advanced operations.

Have you implemented Doctrine with CodeIgniter in your projects? What challenges did you face? Share your experience in the comments below!

Happy coding with Doctrine and CodeIgniter!

Share if liked!

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Pocket (Opens in new window) Pocket

You may also like


Discover more from CodeSamplez.com

Subscribe to get the latest posts sent to your email.

First Published On: June 15, 2011 Filed Under: Development Tagged With: codeigniter, doctrine, php

About Rana Ahsan

Rana Ahsan is a seasoned software engineer and technology leader specialized in distributed systems and software architecture. With a Master’s in Software Engineering from Concordia University, his experience spans leading scalable architecture at Coursera and TopHat, contributing to open-source projects. This blog, CodeSamplez.com, showcases his passion for sharing practical insights on programming and distributed systems concepts and help educate others.
Github | X | LinkedIn

Reader Interactions

Comments

  1. Mehmet Aydın Bahadır says

    September 8, 2011 at 4:35 AM

    Hi, thanks for this great tutorial. But i have a problem. When i close generate_classes() function, taking an error: Uncaught exception ‘Doctrine\ORM\Mapping\MappingException’ with message ‘Class Actions is not a valid entity or mapped super class.’

    But after open this:
    $this->em->getConfiguration()
    ->setMetadataDriverImpl(
    new DatabaseDriver(
    $this->em->getConnection()->getSchemaManager()
    )
    );

    there’s no error but website is very slow. What can i do? I do everything as you say.

    Reply
  2. dionysis says

    October 28, 2011 at 9:36 AM

    function generate_classes()
    {
    $this->em->getConfiguration()
    ->setMetadataDriverImpl(
    new \Doctrine\ORM\Mapping\Driver\DatabaseDriver(
    $this->em->getConnection()->getSchemaManager()
    )
    );

    $cmf = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory();
    $cmf->setEntityManager($this->em);
    $metadata = $cmf->getAllMetadata();
    $generator = new \Doctrine\ORM\Tools\EntityGenerator();

    $generator->setUpdateEntityIfExists(true);
    $generator->setGenerateStubMethods(true);
    $generator->setGenerateAnnotations(true);
    $generator->generate($metadata, APPPATH.”models/Entities”);
    }

    Reply
  3. Martin says

    November 3, 2011 at 5:37 PM

    Auto generating entity classes code is not working..

    Reply
    • Rana says

      November 21, 2011 at 12:15 PM

      What issue you are having please?

      Reply
  4. nicx says

    January 15, 2012 at 11:18 PM

    hi im totally a newbie with this doctrine, and i willing to learn. i cant figure out how to integrate doctrine and CI, need help. thanks in advance. when i will call the generate classes? DQL is like HQL but netbeans IDE generates entities easily. need help with this doctrine stuff. thanks

    Reply
    • Rana says

      July 16, 2012 at 3:48 AM

      you will need to call the generate class function only once, when you run the application on browser first time. Please let me know specifically in which other area you need help. Thanks.

      Reply
  5. mehmet soylu says

    May 18, 2012 at 5:54 PM

    Fatal error: Uncaught exception ‘Doctrine\DBAL\DBALException’ with message ‘Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.’ in D:\Projects\ci\application\third_party\doctrine-orm\Doctrine\DBAL\Platforms\AbstractPlatform.php:210

    Reply
    • Rana says

      May 19, 2012 at 8:38 AM

      Hi, when did you get this error please? did you created the databases and tables? My tutorial assumes so. by doctrine, its also possible to generate tables structure in db from running the application, but I didn’t cover that part in this tutorial.

      Reply
    • alok kumar saxena says

      February 16, 2016 at 1:13 AM

      Hi hehmet soylu,
      You have to add just two lines of code in generate_class function.

      $platform = $this->em->getConnection()->getDatabasePlatform();
      $platform->registerDoctrineTypeMapping(‘enum’, ‘string’);

      Thanks
      Alok

      Reply
  6. sivaram says

    October 9, 2012 at 4:22 AM

    Class “pdcontact” sub class of “” is not a valid entity or mapped super class.

    i am facing this error what is the actual problem

    Reply
    • Rana says

      November 20, 2012 at 3:34 AM

      You have probably forgot to create the table in database I guess. If not, can you please share the details error screenshot please?

      Reply
  7. Rods says

    December 6, 2012 at 6:37 PM

    Doesn’t work for me! I used git clone…but I’m receiving this error message:
    Message: require_once(application/third_party/Doctrine/Common/ClassLoader.php) [function.require-once]: failed to open stream: No such file or directory

    Filename: libraries/Doctrine.php

    Reply
    • Rana says

      December 6, 2012 at 11:15 PM

      Seems like, your file path is incorrect. can you please verify whether the file ‘ClassLoader.php’ is located at this path “application/third_party/Doctrine/Common/ClassLoader.php”?

      Reply
      • Rods says

        December 7, 2012 at 9:07 AM

        Thank’s very much. It was a wrong file path!

        Reply
  8. Jitesh says

    January 17, 2013 at 2:29 AM

    Hi,

    That’s nice but can you provide the download link for the source code.
    It would help the newbee(beginners a lot).

    Thanks
    Raj

    Reply
    • Md. Ali Ahsan Rana says

      January 17, 2013 at 2:43 AM

      Hi Raj, I actually don’t have the code right now that I used on this tutorial. However, as a reference, you can use my ‘codeigniterplus’ project, https://github.com/ranacseruet/codeigniterplus, it has ready integration of doctrine in codeigniter and there I implemented some basic doctrine functionality. Hope it will help you. Let me know if you need anything else. Keep in touch. Thanks.

      Reply
  9. Latha says

    November 26, 2013 at 1:54 AM

    hi., can anybody help me., how to authenticate username and password stored in db..??? i am newbie to code ignitor and doctrine. help me plz..

    Reply
  10. pusp raj joshi says

    July 31, 2014 at 12:58 PM

    How to fetch data in view?
    (
    [users] => Array
    (
    [0] => Users Object
    (
    [id:Users:private] => 1
    [ipAddress:Users:private] => 127.0.0.1
    [username:Users:private] => administrator
    [password:Users:private] => $2a$07$SeBknntpZror9uyftVopmu61qg0ms8Qv1yV6FG.kQOSM.9QhmTo36
    [salt:Users:private] =>
    [email:Users:private] => [email protected]
    [activationCode:Users:private] =>
    [forgottenPasswordCode:Users:private] =>
    [forgottenPasswordTime:Users:private] =>
    [rememberCode:Users:private] =>
    [createdOn:Users:private] => 1268889823
    [lastLogin:Users:private] => 1406821784
    [active:Users:private] => 1
    [firstName:Users:private] => Admin
    [lastName:Users:private] => istrator
    [company:Users:private] => ADMIN
    [phone:Users:private] => 0
    )

    )

    )

    Reply
    • Md Ali Ahsan Rana says

      August 15, 2014 at 1:32 AM

      You can simply use “$users[0]->getEmail()” (iterate for multiple entries) and similar syntax to show if on view. Hope this helps!

      Reply
  11. Musa Haidari says

    September 20, 2014 at 10:33 PM

    Thank you to mention this part. Only I wanted to mention that I had the same problem but got confused how to solve this. What I did to solve it was to move the following piece code to the constructor of the Doctrine class, before the $this->generate_classes (); so it looks like:

    class Doctrine {

    /**
    * @var EntityManager $em
    */

    public $em = null;

    /**
    * constructor
    */

    public function __construct()
    {

    //Other codes

    //move this piece of code here
    $this->em->getConfiguration()
    ->setMetadataDriverImpl(
    new DatabaseDriver(
    $this->em->getConnection()->getSchemaManager()
    )
    );

    $this->generate_classes();
    }
    } // end of Doctrine class

    Reply
  12. tahseen says

    February 18, 2015 at 12:30 AM

    i have followed your tutorial step by step working fine. when i comment out the function call in constructor and which create the entity classes .. and call the entity class in model it shows this error.

    Class “Options” is not a valid entity or mapped super class.

    any idea please…

    Reply
  13. omur says

    July 28, 2015 at 4:11 AM

    Please help i cant solve this problem.

    Fatal error: Uncaught exception ‘Doctrine\ORM\Mapping\MappingException’ with message ‘Class “Entity\User” is not a valid entity or mapped super class.’ in /home/u172335430/public_html/CI_Doctrine/application/libraries/Doctrine/ORM/Mapping/MappingException.php:336 Stack trace: #0 /home/u172335430/public_html/CI_Doctrine/application/libraries/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php(89): Doctrine\ORM\Mapping\MappingException::classIsNotAValidEntityOrMappedSuperClass(‘Entity\\User’) #1 /home/u172335430/public_html/CI_Doctrine/application/libraries/Doctrine/ORM/Mapping/ClassMetadataFactory.php(117): Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass(‘Entity\\User’, Object(Doctrine\ORM\Mapping\ClassMetadata)) #2 /home/u172335430/public_html/CI_Doctrine/application/libraries/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(318): Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata(Object(Doctrine\ORM\Mapping\ClassMetadata), NULL, false, Array) #3 /home/u172335430/public_html/CI_D in /home/u172335430/public_html/CI_Doctrine/application/libraries/Doctrine/ORM/Mapping/MappingException.php on line 336

    Reply
  14. janis says

    December 1, 2016 at 5:30 AM

    i got this message when test this tutorial Class “PdContact” is not a valid entity or mapped super class.
    so i need help to understantd

    Reply

Trackbacks

  1. Doctrine Native SQL Query Tutorial - CodeSamplez.com says:
    November 28, 2024 at 1:00 PM

    […] As you are possibly using doctrine already, you can skip initialization. Best way to use them as a separate wrapper class for your application as the one I showed before while integrating doctrine with codeigniter. […]

    Reply

Leave a ReplyCancel reply

Primary Sidebar

  • Facebook
  • X
  • Pinterest
  • Tumblr

Subscribe via Email

Top Picks

python local environment setup

Python Local Development Environment: Complete Setup Guide

In-Depth JWT Tutorial Guide For Beginners

JSON Web Tokens (JWT): A Complete In-Depth Beginners Tutorial

The Ultimate Git Commands CheatSheet

Git Commands Cheatsheet: The Ultimate Git Reference

web development architecture case studies

Web Development Architecture Case Studies: Lessons From Titans

static website deployment s3 cloudfront

Host Static Website With AWS S3 And CloudFront – Step By Step

Featured Dev Tools

  • Diff Checker
  • JSON Formatter

Recently Published

python file handling

Python File Handling: A Beginner’s Complete Guide

service worker best practices

Service Worker Best Practices: Security & Debugging Guide

advanced service worker features

Advanced Service Worker Features: Push Beyond the Basics

service worker framework integration

Service Workers in React: Framework Integration Guide

service worker caching strategies

Service Worker Caching Strategies: Performance & Offline Apps

Footer

Subscribe via Email

Follow Us

  • Facebook
  • X
  • Pinterest
  • Tumblr

Demos

  • Demo.CodeSamplez.com

Explore By Topics

Python | AWS | PHP | C# | Javascript

Copyright © 2025

https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_89e20b23a87881c7611cf85c71c0468be67795b6555374f66f600b503bec3fb99500a84262e0f64d2c9b1a65572e1b87a7f58d178614177228fbbe21cdfc554c.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_c402e38f1879c18090377fb6b73b15ac158be453ecda3a54456494fe8aba42b990c293bae5424e5643d52515ffc2067e0819995be8d07d5bba9107a96780775c.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_ffc3511227531cc335353c54c3cbbaa11d0b80e5cb117478e144436c13cd05495b67af2e8950480ed54dbdabcdcef497c90fdb9814e88fe5978e1d56ce09f2cf.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_d57da9abfef16337e5bc44c4fc6488de258896ce8a4d42e1b53467f701a60ad499eb48d8ae790779e6b4b29bd016713138cd7ba352bce5724e2d3fe05d638b27.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_d286e50977f467ebee8fecdcb44e6a6b9a29f2b911dfe58b30ff4f0545aa2b19bca73246e23de9a6d2380bf20e6b8a001b5ba2051042d104c6d411b474fd3368.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_556272a5f9c5e1b26dcf93c48dd6c60d2107db888f97b70498f312c9052331e10005db30e1259f325d650689883af8e7250f282b512037503c7b7dcf03bef034.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_dccc492dbbfdac33d1411f9df909e849c7268fcf99b43007f278cde3a0adc0ae00e8cae5ec81cf255b9a6eae74e239ba1fa935572af77173219cb081f7d2327d.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_00bacf9e36181aac2b666d110cd9d82257f846766e7041b2d7b3c909b458982931ccc9b203e37098fbdfcf43ca359cf04e3824a724a6789fc204196d3a72ad29.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_c1c18b8baf8ed2aa84a8022e80b5422016646101cc3549c023473f24ad731189d3f4e279527a58a60bef61e6f749d51f280c52a82dfdab5075e6bc20bf21b240.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_68b6d1949e90b6a37c5195ae17874e7c2455352144f28a76be0f68f7a941e6d664fa3c931485f2c5463521acdac05ff6642f0c94fa557a087caa9478d162f085.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_bb8058a9e234a7ffaa98891b1df7f6b8e67410e6984568b151daa05113b8c7f89d7b5918ae73f020998a16f7f5a087a13d6a9a5e5d7c301e2ca12fd9d1f8d177.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_647fb67570c6108fb10ae6785a1abdbecac99ffcf80351d0bef17c3cf783dce497b1895fcdaae997dacc72c359fbfb128cc1540dd7df56deb4961e1cd4b22636.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_f7a298a0f1f754623fe3b30f6910ce2c1373f715450750bd7a391571812b00df1917e2be90df6c4efc54dbdfda8616278a574dea02ba2c7a31992768df8db334.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_df30604d5842ef29888c3c1881220dc6d3f8854666d94f0680c5f38aa643c5fb79b10eb9f10998d8856eb24ca265783195937434fd6c2bb8e4846df0277a7fb7.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_f17fe6fb0993f1703181d7ae9e9ea570f3d33a43afd6f2a4567daa1a6745698c7b8193dc72d50991d2dd87cd3dcf663959206607d193a9b57926d061a1f50aef.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_945dcbab2c2a131f3c90f4fb91776b76066d589f84fb55bff25cd5d79a56218000616bfca1f0af9a74f32348693707af49e8fe624de8aa34f1e1c5b6a25709cf.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_65820d252e1b93596de6697fd5f02483f3e2524a0696c7d698b64745edb32bf5831a90e556842f5f88c8209766cc78ca3a41cf783d20236a9f90d4a7ea7b3e72.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_7286884797a1210857e2a36f8ab46604b0034b6abf512380447a5763c873db6a72b8547f660053de0ea69faef1eb64878f39ff4b0ea86c963efab95764a3bf5b.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_cbcf6c279ac6c6a25ae138bf964e64a5fd90d22dcdf8a53b6fe7b72cefa51063bfb0181a6e50dd2acdcae2795619887d1d83b10461e44e5103be756f2588d837.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_47965bc586b95810c925b9df3314e0c9a5cd121e70ca0831f87df0bc034695de4f83ecf2def86f737e14614ee138794473cf32cd3082a5d38db9dec0c1f266fa.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_12aa201cea075846d266536aa222d64d4088b851d87f55dac5e611b77add6826c8ebc6e82650fcd1a9e88a05a0072dedd195719c5f64cd4580a0acd8aee05d92.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_80a4a4c808f46b20177fec8ee1a931010e5d14047c467a7f976cb5b2529b569eeb61558804f2f1a2d2a2347a1e2041500c1b275b1b4c31bbb4b36d8b4183b2b6.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_53e71567875b6621844c01fbe95302f92d03f3291982052c6de43e63110625c184891d3df866f9c787b0a9f8c276dbdce7705f55a219bed65a4ce4976aaf3b63.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_d87ea86dd0e7ecdd5fe7a5bb67becf943e57c3add866b456034d51663d099031bd563e12f61fdccc044969adf938a8584ed22ccd401ab8b669e20e4f92fb54e8.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_35311c3d71a3605fad4e1d6b50f3911311cdcc46418bdf56d6d0308a75a69585269ee7582a335e29989adf308fa1a81a10a2c2d4e257e9d680447a4996f6269e.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_f4fc182ef03c12e9dcadd6febc3dbaa4a29134469057ca9e8ec0be2f2de29a494514ff4b59798e74debf26f78b2df2b3e2665c69b77035761fb463b783202915.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_85c0f2769456e60153b0fd8364b82a035da53384f62de342d9bdca806f3f1ea56486919a00497a18d457949c82bf8bfacc4423fc332074ddf71a49a8fe628fff.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_1b7e49e98f5960d71636812e807832cc98a24f48bc493652ddb2f9c4ce08bc89a8fd5d9550a8e2887d1d8887ce02924a878361c296d21ceba18a56f3ace130bd.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_09eecfdd96206ed13830b4b93cfb2cc75cd38083671a34194437b5734b5bb38712209dc335b07e3266ceb3c3a44a155b9bbe5f3e0e1105b19dd45d3def76f020.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_4c089fbdb88e3b624a6f884d3ba1bf606f003bfcd3742376d0d353cd62181dc663aa3811a56361c3100de488fc4d6595a50de2b26f058921ba74f5f2c1b5be00.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_897ff6ac314c5f5e0f496c6af624bd9abf296a02cb5aeb850b9220b6dc3ce2fc4004cb02ed8b59d59d4b9c9d90f050d6eebc1d08ecaebab2f671f7d9367e6410.js
https://codesamplez.com/wp-content/cache/breeze-minification/js/breeze_mobile_67d1e619e71d36ae00ddcf85ee18628bb4eb64fcb3d6119b463e75cb987013420a21136d19cd03e6634ccc01cfa9af4a357930e4cf6900953b7812efb4f249fb.js