Zend Framework 2 - Doctrine 2 Model Forms - doctrine-orm

Is there a way to autocreate forms based on the models I defined within Doctrine?
In Django its a basic feature. I found some old sources where someone had tried to implement it by himself... but nothing up-to-date or official-looking
These model forms save loads of time. I do ask myself why people don't complain about this (possibly) missing feature...

Zend 2 cannot create a form from the Entity itself. Doctrine 2 is not even part of the framework or tied to it as close as to Symfony 2.
You may use annotations in your entity to hint all necessary information for creating a form from it using the annotation builder.
For a deeper understanding how this works I would suggest you to look it up in the Zend 2 Documentation.

Related

Zend Framework, Architecture with Doctrine

im learning Zend Framework (3) ... I installed Doctrine because i do not want to write sql queries to learn all other stuff faster....
First Question:
So know i configured a factory that loads me the doctrine entity manager to my Controllers (with DI).
So its really simple to get my entities to my controller ... e.g in my Project Controller createAction i can easy get my user entities to show them in my project form (project <--> user many-to-many).
But know im struggling, would it be better to create repository classes and inject this to my controllers instead of the doctrine entity manager, so i can filtering etc all my entities?
Second question:
When i want to filter my projects (e.g by user)
where should i do this ... in simpler slim projects i created Collection classes and injected them all of my entities and after that i called a filter method in my collection ... but the problem there is, i just loaded all entities from my database to the collection. In larger application i think there are to many entities loaded from the Database?
Third Question (Conclusion):
When i want to load data from the db to my Controllers whats best Practice here?
Load it from the entity manager ?
Load it from a Repository (the Repository load it from the entity manager)?
Load it from a Collection (the Collection loads data from the repository class and the repository loads data from the entity manager)?
I did not thought about Pagination #all... thats what i have to do next ... but there are many questions similar to my other questions.
(I know there is a zend module for this .. but have no idea how this works.. have too learn this too)
Im thankful for every hint, meaning etc.
Answers to this question are possibly all opinion based. I would say it is all about personal preference. There is no such thing as best practice here it all depends on what you will do in your controller. On top of that you can easily get a repository from your entity-manager if you need it:
$userRepository = $entityManager->getRepository('Application\Entity\User');
A more common might be to make a custom UserService (a wrapper class) around your repository/entity-manager that you populate with the custom methods you would like to use with your User resources.
I hope this helps you a bit...

How to add fields to third party app model?

I'm working on a web page which uses Django-quiz app. When you install the django-quiz, you can create quizes, questions etc. in Admin.
Unfortunately, there is no way, how to assign Quiz to my model Language so I'm looking for a way, how to add field Language into the model Quiz.
I've tried this but it does not work. I've tried already to create a proxy model with additional field but I realised that it is not possible in proxy models.
from quiz.models import Sitting,Quiz
class QuizAddLanguage(models.Model):
quiz = models.OneToOneField(Quiz)
language = models.ForeignKey(Language)
Do you know what to do to add field to third party app model?
For this time, OneToOne should be enough - for each language there will be one quiz
Since its one to one then you can just define the relationship on your own language class, django by default, will provide you the reverse lookup meaning
language_obj.quiz
quiz_obj.language
will both be valid.
Here is a relevant Django ticket, which was closed with a resolution of "wontfix" six years ago:
https://code.djangoproject.com/ticket/14969
I think this comment provides some good information:
Comments gives you the *right* way to handle this problem -- you define an interface, and make the model itself pluggable. Not all Django's contrib apps follow this approach, but that doesn't mean we bake monkeypatching into the core -- we fix the contrib apps.
django.contrib.comments is now a standalone app, but it still makes itself relatively easy to customize. Here is the relevant documentation:
https://django-contrib-comments.readthedocs.io/en/latest/custom.html
If a third party app doesn't make itself easy to customize, I would suggest asking the developer to update it and point them to the above links for examples on how to go about doing it.

Ember Validation on models

As, I am using lots of models in my application, there are the cases like, I have to include 2 more models in the route and I merge them using RSVP. I used previously objectcontroller and now I am changing it to controllers... I'd like to replace my validations object from my controller to the models so that I don't have to use model.modelname.property....
Please tell me like is it possible to replace from the controllers to models?
It sounds like Ember Validations does exactly what you want. Please see Brian Cardarella's article entitled Understanding validation graphs for an overview.

Creating templates for authentication forms in Django 1.7

First off, I'm very much a newbie when it comes to Django.
The problem I'm struggling with is in trying to create templates for the built-in authentication forms in Django 1.7 but there is very little that I can find in the way of concrete examples anywhere in the documentation or elsewhere.
I can find plenty of questions and examples that describe how to manually create the templates (or copy them from the Django packages) but from what I understand about the Form class and the built-in authentication forms is that I don't need to manually create the actual form in the template. In fact, it seems more desirable to use the Form classes because that would add ensure that fields are named correctly, that the validation such as max length on text fields is applied, etc.
Can anyone point me to some concrete examples or documentation of what I'm talking about? I've read the following sections already,
https://docs.djangoproject.com/en/1.7/topics/forms/
https://docs.djangoproject.com/en/1.7/topics/auth/default/
https://docs.djangoproject.com/en/1.7/topics/auth/customizing/
In fact, I would say that this question extends to any Form class in general but I'm specifically looking at the authentication forms here because I obviously haven't written these Form classes.
I don't think it should make any difference from what I've read since the same process should apply, but I will say that I'm using the django-authtools package (http://django-authtools.readthedocs.org/en/latest/)
I have the actual authentication system working fine. It logs users in and out, I can enforce that certain urls require the user to be logged in first, etc. so its only the actual form display that is an issue.

Django MongoDB Embedded Models

When I create a class/model specifically for the purposes of being embedded into another class/model, a collection is still written for the former in my mongodb database. The aforementioned does not cause any trouble other than the inconvenience of being there, but I'm still wondering if there is any way for a collection not to be written?
I have a nonrel django project as well. Its just a thing django does (and that the nonrel fork has not specifically addressed), that when you define a model that is not abstract or proxy, it is going to generate a collection (table) during a syncdb. Whether you save anything to that collection is further dependent on your code obviously.
If there is some trick to having a concrete model not create a collection in nonrel django, then I am missing something as well.
It's possible if you use abstract=True for that model.
However, you can't use lazy lookup (aka EmbeddedModelField('SomeModelThatsNotYetDefined') yet (https://github.com/django-nonrel/djangotoolbox/issues/15).