Complete Doctrine 1.2x Integration with Zend Framework 1.10+

To achieve complete Doctrine 1 integration with Zend Framework some glue is required, Benjamin Eberlei has created a complete solution thats straight forward, easy to use and understand.

This project tries to offer a complete Integration of Doctrine 1 with Zend Framework. The following components belong to this Integration:

  • Zend_Application Resource
  • Zend Framework Modular Project Support
  • Zend_Tool Provider for Doctrine Model Generation, Migrations and Fixtures
  • Zend_Paginator Adapter for Doctrine Queries
  • Dynamic Zend_Form generation from Doctrine Models

This integration requires the latest Doctrine version 1.2.2 to work completely

Get it!

SVN Export or Externals

Github offers SVN Read support for a while now, you can either use svn export or svn:externals to include ZFDoctrine into your project or into your PHP Include Path.
svn checkout http://svn.github.com/beberlei/zf-doctrine.git

Git Clone

git clone git://github.com/beberlei/zf-doctrine.git
If you follow the tutorial and installation steps your will get this in ZFTool.

Zend Framework Command Line Console Tool v1.10.4
Actions supported by provider "Doctrine"
Doctrine
zf create-project doctrine dsn zend-project-style library-per-module single-library
zf build-project doctrine force load reload
zf create-database doctrine
zf drop-database doctrine force
zf create-tables doctrine
zf generate-sql doctrine
zf dql doctrine
zf load-data doctrine append
zf dump-data doctrine individual-files
zf generate-models-from-yaml doctrine
zf generate-yaml-from-models doctrine
zf generate-yaml-from-database doctrine
zf generate-migration doctrine class-name from-database from-models
zf excecute-migration doctrine to-version
zf show-migration doctrine
zf show doctrine

Read it ALL at beberlei’s zf-doctrine at master – GitHub.

Understanding the stack index for Zend Framework Controller plugins

Simon R Jones writes a very helpful article about the stack index (the order you fire plugins) and how to customize it;

Zend Framework Controller plugins are a powerful way to inject logic into your controller system at various points, such as before and after an action dispatch. Plugins are run in the order they are added, though it is possible to change the order by defining a custom stack index. ZF internal plugins such as Zend_Controller_Plugin_ErrorHandler, which displays a nice Error 404 page, has a stack index of 999 to ensure it runs at the end of any plugin cycle. However, it’s not so obvious from the ZF manual how to set a custom stack index.

For example, you may have a common admin system layout that does various things to your admin page layout before the page is displayed…

more at simon r jones.

Using Different Databases with Zend Framework 1.10.4+

Jeroen Keppens wrote a very good article about using multiple databases that I defenitely found very useful;

A while ago I wrote about a custom application resource for loading multiple DBs. I received a lot of questions and decided it was time for a follow-up on how to use multiple DBs in ZF.

One of the first experiments I did with Application Resources was writing a application resource for loading multiple databases. We generally connect to multiple databases in reporting applications or in scripts where we want to aggregate data from the main database to an offsite database. Since that post I received a lot of questions on how to integrate this in the models and how to join different databases in queries using zend framework. In this post I’ll explore how to do both. Since in the meantime someone has used the idea and added a multiple db resource to the Zend Framework, I will use the “official” application resource loader instead of my own.

This tutorial was made with Zend Framework 1.10.4.

via Jeroen Keppens

OxyBase v1.0.0 – it is an active project!

In one of Zend Framework mailing lists, people were wondering if this project is live, so answer is yes – we are live and this is active project. Actually we are preparing v1.0.0 which will have the same features set OxyBase has now, but in addition to that we are adding something that in PHP world is not used widely but I think it will be. I was implementing those technologies in my current project at work with my team and I wanted to test it first before creating and publishing anything. Because then it would be only theory-based-components that would fail in real world.

What I am talking here about is CQRS architecture, DDD approach, Event Sourcing. These are pretty new things and specially in PHP world, and I think we are those – maybe first ones who does it in PHP.

In new release OxyBase will have components that will help you to use those technologies, to speed up development and generally to create better quality software. Exact new features:

  • Framework for the CQRS architecture’s read side
  • Framework for the CQRS architecture’s write side
  • DDD, domain models base classes that will provide functionality for Event Sourcing
  • Bounded Context infrastructure components code generator, you will focus ONLY on the domain model, all the rest will be generated by OxyBase
  • Improved domains logic (from v1.0.0 domains are called bounded contexts aka sub-systems)
  • We will integrate external tools that will be used to handle database changes
  • We will include so called build scripts that are used for application deployment and you will be able easily customize those for your own needs

And much more, like documentation, samples etc.

Now one thing that I want to say is that with this release we are focusing on big projects with complex business logic. If you are looking for framework to build simple websites, this is not what you are looking for.

Release date is not set, but we plan to have it at the end of this summer.

I really hope you will enjoy using it as much as I enjoy it now in my daily work.

via OxyBase.

Zend Framework 1 and Doctrine 2 integration – modular setup

Elink Media posts a followup;

I’ve created a new branch on my Github project “zf1-doctrine2″. The “modular_setup” branch shows how we could setup Zend Framework with the modular approach, while still be able to use Doctrine 2 as the ORM for each module.

Oh well, the idea is to make each module decoupled with the rest of the application, so really, you could use whatever database handling mechanism in each module.

Check it out from my Github project here.

Reference

via Zend Framework 1 and Doctrine 2 integration – modular setup.

Akrabat_Db_Schema_Manager: table prefix support

Rob Allen posts; I’ve updated Akrabat_Db_Schema_Manager so that it now supports table prefixes.

It uses the application.ini key of resources.db.table_prefix as I couldn’t think of a better one 🙂 and then uses that for the schema_version table’s name and also makes it available in your change objects.

For example, if application.ini contains resources.db.table_prefix = “myapp”, then the manager will create the table myapp_schema_version to store the current version of the schema. In your change classes, you can then do this:

001-Users.php:

class Users extends Akrabat_Db_Schema_AbstractChange
{
function up()
{
$tableName = $this->_tablePrefix . 'users';
$sql = "
CREATE TABLE IF NOT EXISTS $tableName (
id int(11) NOT NULL AUTO_INCREMENT,
username varchar(50) NOT NULL,
password varchar(75) NOT NULL,
role varchar(200) NOT NULL DEFAULT 'user',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
$this->_db->query($sql);

$data = array();
$data['username'] = 'admin';
$data['password'] = sha1('password');
$data['role'] = 'admin';
$this->_db->insert($tableName, $data);
}

function down()
{
$tableName = $this->_tablePrefix . 'users';
$sql= "DROP TABLE IF EXISTS $tableName";
$this->_db->query($sql);
}

}

which will create a table called myapp_users. Note that you are responsible for using the prefix property as the change classes cannot enforce what you do within the up() and down() methods. It also follows that you’ll have to ensure that your models also use the correct prefix.

I have also made a change to the provider (Akrabat_Tool_DatabaseSchemaProvider) so that it loads the correct application.ini file based on the data in the project’s profile. This shouldn’t affect anyone using Akrabat_Db_Schema_Manager, except that we no longer define APPLICATION_ENV and APPLICATION_PATH for you.

Enjoy!

via Rob Allen’s DevNotes.

Zend Framework 1 and Doctrine 2 Integration

Elink Media posts; Doctrine 2 is in beta. It is for sure one of the most exciting things that caught my attention recently.

As a Zend Framework user, I started looking into ways to integrate Doctrine 2 with Zend Framework (currently in version 1).

The same as any other times, the solutions are already out there. The integration’s already been done by Giorgio Sironi’s nakedphp project.

So … I borrowed code from nakedphp and put up a skeleton ZF projects myself.

My sample project is available on Github. You can find it here.

Have a play, let me know if anything. Hope it’ll help people like myself, who cannot wait to try out new and cool things.

Reference

Zend Framework 1 and Doctrine 2 Integration | Elink Media.

Transparent Logging with Zend_Log

Lebesold publishes another screencast; First of all, I’d like to thank you all for your patience! Zendcasts takes quite a bit of time and research to put together and I’m deeply touched by all your support.
On a personal note, my wife and I are heading out of North America in a week to visit Namibia and South Africa for 3 months. I’m going to do my best to keep up Zendcasts on a weekly basis, however my connectivity and upload speed will be limited. We’ll see how it goes!

Now for today’s episode:

I was working on a project for a client the other day and noticed a couple of lines in the ErrorController for automatically logging errors with Zend_Log. In 10 minutes, you can have a fully integrated logging framework. I also implement a singleton pattern for reusing your Zend_Log configuration (defined in the application.ini) anywhere else in your application.
Grab a copy of the project or browse the repository.
Enjoy!

Watch @ Zendcasts.