I was wondering if there were any good pre-built ways to implement an EAV design pattern in Zend Framework?
I am trying to decide if I should create my own implementation or use one that has already been built.
Use Doctrine with MongoDB Document Mapper http://www.doctrine-project.org/
Zend Framework 2.0 has automated install for Doctrine with Composer, so it means Zend People also offer this as an Option apart from the built-in Zend_Db.
Using EAV on a document-oriented NoSQL database system like MongoDB or CouchDB is way much better than implementing a Hack over Traditional Relational Databases like MySql ( something that Magento did ). NoSQL Databases are better at implementing Sparse Matrix type Data.
Check out Zend Framework EAV on Google Code.
Digitalus CMS uses the EAV pattern, and is based on MySQL. It is true that Mongo or Couch might be more appropriate, but MySQL is often an easier choice because you don't have to install anything. I have tried using SimpleDB, but the local MySQL version is 4x faster. SQLite also works very well.
There are a lot of opponents to this approach, and their claims are largely founded. Any time I need to be able to query data I use a standard relational approach, but EAV shines when you are working with very loosely structured data like the content on a web page.
Digitalus uses an approach where there is the base CMS item model that handles all of the EAV logic. This model also handles a write-through cache so the system ultimately serves content as fast as a flat file system.
All the purists are probably technically correct, but fast and easy have a place in my toolbox.
Related
Maintaining database views in mysql is sometimes cumbersome. When you change a referred table you have to alter the table and there is no clean way to do that in migrations (DB::unprepared()). I guess using query scopes in models is more maintainable. Isn't it? Does it has negative effect on the performance.
I don't know how big your project is and I don't have many elements to judge this situation perfectly.
However, working with views means depending on the underlying database system. Obviously it has its pros and cons, but I would prefer to decouple my software components.
What if you change, in the future, switching from MySQL to MongoDB?
Maybe, you could use a cache system, like Redis or Memcached (and Laravel already has a ready-to-use service for it).
As I told you before, I am making this suggestion basically because I think about the software scalability and components decoupling.
Here you can learn about the basic use of the Cache Service: http://laravel.com/docs/5.1/cache
Also, if you have some confidence with design patterns, you can implement a really elegant solution using some stacked repositories alongside the decorator pattern.
You can find some interesting articles about the topic here:
http://culttt.com/2014/02/03/laravel-4-cache-service/
http://culttt.com/2014/04/23/decorator-pattern/
Yes, they're about Laravel 4 but the concept can be easily adopted in a Laravel 5.* project.
Hope it was useful!
EDIT: as I told in the following comments, if you don't want to start with something like Redis or Memcached, you can always use the filesystem-based Cache.
I am starting a new (and first) project with Symfony2, but I didn't choise Database engine yet. And it could be MySQL or NoSQL engines like MongoDB or others, or also it could be changed along the proyect cycle.
So, I would like to start working without limitation of choising Doctrine, Doctrine for Mongo or others. And allowing posibility of changing only model layer without big impact on controllers, and classes.
Recomendations? Comments? Best Practices?
Hope this tutorial will help you to get some knowledge. However try to learn the main concepts before doing any major development.
I am leading a new project where we're convinced that MongoDB is the right choice for database. We have decided that the architecture would be SOA, so the web part will be developed using Symfony and the service part will be developed using light-weight REST framework Tonic.
Now, in the service part, we'll be communicating with MongoDB and for that, we have looked into a number of available MongoDB libraries: Doctrine MongoDB ODM, Mondango, ActiveMongo, MongoRecord, etc. However, we are not sure which one to pick.
I was wondering if anyone can share their experience with these libraries so that we can make the right choice. Here are some of the properties we consider the library should have:
Plain PHP classes for defining documents (instead of array/config files)
Support for references
Efficiency in operations
Easy to understand API
Looking forward to your views!
Personally I would go with Doctrine2 ODM. Seen as you have already decided on Symfony as your framework for doing the heavy lifting the pair are well aligned as far as I understand. You should be able to use this https://github.com/doctrine/DoctrineMongoDBBundle to integrate the two pretty quickly.
The doctrine setup ticks all the boxes you've set for your project goals and is fairly easy to get working with. Most importantly, it's an active project so bug fixes/features/documentation updates happen fairly regularly.
We use a similar setup, except zend framework instead of Symfony, and we're very happy with the results.
Hope this helps.
I've recently come on board with a PHP application. There has not been much design put into the app - there is a front controller, however, view, model and controller code is usually mixed together.
I would like to slowly start refactoring the code beginning with moving all the SQL queries into appropriate models. Having looked at a few frameworks, it seems that most frameworks are setup with the assumption that an app will be developed from scratch using that framework.
Is there a good framework that I can just kind of plug-in so that I can use the model libraries and then perhaps later on, integrate more of the app into the framework? Would Doctrine be a good tool for something like this? Or should I just setup my own models without relying on third-party libraries?
If you have an existing php application, then there is no point to migrate it to some framework. Frameworks help you to develop project faster - you already have one. At this point adding framework on top of what you have will only make your application more complex and, most likely, slower.
Instead of trying to find some magical framework, you should invest in refactoring (apply some OOP principles, like SOLID) and documenting the existing code. Maybe start incrementally add some unit-tests.
P.S. Doctrine is an ORM ( 1.x implements activerectord , 2.x - something like a datamapper ). ORMs are for people who are extremely lazy, misguided or do not understand SQL. By moving your existing SQL queries to ORMs code you will make it all only slower. Additionally, you will encounter problems when migrating complicated queries. Just dont do it.
I've just started rewriting a site in Kohana, and I'm quite happy with it. It seems flexible and powerful. It's very similar to CodeIgniter, but a little more modern (more of the latest PHP features are used).
If you want only MVC (not HMVC or more difficult) frameworks for simple adoptation with existing application you should touch CodeIgniter. ActiveRecords is very easy for refactoring from existing sql-queries. You even can use default or hand made functions or classes for building queries in its models.
But default, Codeigniter isn't enough flexible for difficult or multi-namespacing applications.
Im migrating a site using Zend and Doctrine2.
The site wasn't OOP in any sense but it was divided between logic view and dal. The migration is still in process (new features are coded with framework, existing feature gets migrated only when big changes are needed).
Both frameworks are non intrusive, and the most valuable thing you get for me is to standarize things.
Are there any PHP ORM projects which supports MySQL and NoSQL databases such as MongoDB?
I am currently using RedBean to do MySQL ORM, however I woud like to introduce MongoDB to the applicatoin and perhaps even replace some of the MySQL with MongoDB in the future.
An ORM that can allow me to easily transition between both would be nice. However, I tend to not like ORM that requires too much configuration (i.e. YAML, XML etc). RedBean is very nice in that it allows one to easily get things working without too much configuration.
Yes, doctrine supports various RDBMS and NoSQL storages as well
Docrine 2 contains both an ORM and ODM for NoSQL databases (MongoDB and CouchDB are supported), and its theoretically possible to hook up Doctrine to anything else.
We're working on some adapter-based ORM called UniMapper in our company.
It provides a uniform API for accessing stuff from different kinds of databases, protocols, and 3rd party APIs. You can even associate between entities from different storages. And it should be even faster than Doctrine. Try it give us some feedback :-).
MongoDB will be supported very soon, but you can write extension on your own, it's very easy.
However the quick start is not complete, you can ask me or somebody from our team.