Codeigniter with Doctrine for large application - php

I am about to start a project on PHP and selected Codeigniter as a framework to be used after receiving lot of plus comments from Codeigniter-users ;-)
I am not much clear about which ORM to be used with codeigniter. I was advised to use Doctrine. Is there any tool available for codeigniter to create models and db mapping with Doctrine on command line?

You can use Doctrine itself for creating models. Follow the cookbook
http://www.doctrine-project.org/projects/orm/1.2/docs/cookbook/code-igniter-and-doctrine/en
to setup, so then in /application/ you can use
$ ./doctrine [command]
to create models and mappings.
Note: in this moment I'm failing to access any page at the doctrine-project.org site. May be later...

Related

Db migrations in zend framework 2

I was using Yii2 framework for a long time. There is a DB migrations in Yii2 (http://www.yiiframework.com/doc-2.0/guide-db-migrations.html). It helps easily change DB structure by console command.
Is there something similar to Yii2 DB migrations in Zend Framework 2?
In Zend Framework 2 there are some possibilities to manage database migrations. First it depends what you are using to interact with the database. If you are using Doctrine you could use https://github.com/MurgaNikolay/DoctrineMigrationsModule.
If you are using Zend\Db instead, you could use this module: https://github.com/vadim-knyzev/ZendDbMigrations (documentation is in russian...).
There are some general modules that help you managing migrations: https://github.com/vgarvardt/ZfSimpleMigrations (the one with the most activity in the repo) or https://github.com/valorin/zf2-phinx-module that is using Phinx under the hood.
If you want to have a look to something really new, go to https://github.com/baleen/migrations, a really nice project that is being developed. This will probably require some work on your end to put the pieces together.

Using own database wrapper in Symfony

Recently I started learning some Symfony as a side "project". I know with Doctrine you can use MySQL. However, I got my own database class using PDO. How can I implement and use my own database class on Symfony? And in which folder should I place it?
I used the download from here: http://symfony.com/download and the tutorial from http://symfony.com/doc/current/book/installation.html. I couldn't find anything about using an own database class.
You can use it like any other class in php, or you can create symfony service for that class (you have everything about services in symfony2 documentation)
According symfony2 best practices you can put your class in any folder in AppBundle. But if you want to reuse your class on multiple projects you should put it on packagist, and instal it with composer.
But if just you want to learn symfony you should consider using doctrine, because most of the symfony projects are using it.

Starting with existing database on Laravel 5

I have been enjoying working on Laravel for a while now, and am planning to move a fairly large project to Laravel 5.
The new project has fairly large database with numerous tables, and it would take considerable amount of time build migrations, models and controllers individually.
Has anybody worked on this before? What is the best way to go about it?
I have used this great extension to generate migrations as of now - but still for a 200+ tables, it would take quite a long time to do the rest.
Try this one:
https://github.com/reliese/laravel
Reliese Laravel is a collection of Laravel Components which aim is to help the development process of Laravel applications by providing some convenient code-generation capabilities.
How about this: http://packalyst.com/packages/package/ignasbernotas/laravel-model-generator
Model generator Laravel 5 model generator for an existing schema.
It plugs into your existing database and generates model class files
based on the existing tables.
For migrating models and controllers just use artisan commands, you can't get around it any easier than that. For the migrations I can suggest trying to use the following package:
Laravel Database Exporter
It will export your existing DB schemas as Laravel migrations. My suggestion is based on the assumption that you are using MySQL as your RDBMS, because the package I suggested only works with that.

Doctrine 2 Migrations Workflow

I am developing a web application using Zend Framework 2 and Doctrine 2. I'm new to Doctrine 2 in general and Migrations in particular. I was wondering if there are any recommended best practices in using this. Some specific things I'm looking for:
A recommended workflow from development to deployment?
Do you include pre-populating data in migrations?
How to handle reverting to a previous version if migration fails.
Many thanks!
Doctrine has own library for migrations, that includes also Symfony bundle.
For Zend there probably is some bundle as well (maybe seek on Github a bit more)
As for your specific questions:
Nothing special. Basic workflow is nicely described in Symfony bundle documentation. We use it in pretty same way even in a different framework.
Yes, so every developer has fully operational system. For tests we use data-fixtures with minimal required data only.
It's managed by this package itself.
The Doctrine ORM module for ZF2 (DoctrineORMModule) has built-in support for Doctrine ORM migrations. There's a very brief blurb in the documentation about how to configure it. You can then access the migration commands (generate, migrate, etc) through the CLI interface that module provides (vendor/bin/doctrine-module)
As for my personal workflow I generally put initialization or pre-population data - the stuff you initially seed a new installation with - into database fixtures (which Doctrine ORM also supports and there is a ZF2 module for).

Zend 1.11 and Doctrine 2 Auto generate everything needed from already existing database

I am new to ORM and I am really keen to learn it. I successfully managed to install all classes and configurations for Doctrine 2.1 with Zend 1.11.x by following this tutorial.
http://www.zendcasts.com/unit-testing-doctrine-2-entities/2011/02/ Which uses Bisna plugin and doctrine scripts.
Now my problem is he is clearly explaining how to create entities and tables through doctrine classes but do not explain how to auto generate the proxies and repo classes from already existing database which helps me to select, insert and update. I always create my databases using MySQL Workbench.
I also followed the below tutorial as well
http://www.zend.com/en/webinar/Framework/70170000000bSrG-webinar-zf-v-1-doctrine-v-2-20101214.flv
My database is so complex with relationship flowing across every possible way. If I follow the steps which is explained in these tutorials I will never complete my project. Can any one please explain how to start using Doctrine after configuration. Considering I already have a database and my Model folders are empty. I have my folder sructure as below.
C:/zf/library/Doctrine
C:/zf/library/Symfony
C:/zf/library/ZC -- (my model which should contain the proxies and repo of Doctrine. At the moment it contains nothing.)
C:/zf/library/Zend
C:/zf/scripts/doctrine.php
Please help me!
I posted this same post yesterday and no one replied to my post. Please let me know if you need anymore information from me.
Thank you,
Karthik
According to Doctrine you should create your entities first yourself and then create your database schema from these entities.
But because you already have a database you probably don't want that. It is possible to convert your database to Doctrine2 entities in PHP, XML or Yaml.
You should take a closer look at the commandline tools Doctrine offers with the Bisna glue because there you can generate a lot of stuff.
To generate your entities FROM your database consider the following command:
php doctrine.php orm:convert-mapping --from-database php ../library/Application/Entity
You can also define the namespace and a base class which your entities have to extends with: --namespace=namespace and --extends=class.
Doctrine2 warns you to convert your database to entities because not everything could be auto detected or supported. For instance ENUM datatypes are not supported by default in Doctrine2 so converting your database will raise an error.
It's a good idea to check all your entities especially associations before you use them. Hope it helps you.
If I understand your question correctly, you have your entities already configured and need to auto-generate your proxy and repository classes.
Both can be created using the following Doctrine CLI commands from your application's root directory:
php scripts/doctrine.php orm:generate-proxies
php scripts/doctrine.php orm:generate-repositories library/
If you're looking for a way to auto-generate your entity classes, unfortunately I don't think a solution is available for this yet.
A support rep at ORM Designer said they are "working on" this feature and that it is "very demanded." Here's hoping it will be included in ORM Designer 2.0 since there is generally a lot of repetitive work involved in coding/mapping entity classes that could likely be automated.
You can use the orm:generate-entities command if you provide mapping information in either XML or YAML format.
See http://www.doctrine-project.org/docs/orm/2.1/en/reference/tools.html#entity-generation
For development, set proxy generation to be automatic in your config, otherwise, use the orm:generate-proxies command.
Unless you need to customise your repositories, generic ones are created in the entity manager when requested. To specify custom repositories, simply use the repository-class entity mapping attribute.
See http://www.doctrine-project.org/docs/orm/2.1/en/reference/xml-mapping.html#defining-an-entity for an example

Categories