Symfony2 - the good way to add an image in our entity - entity-framework

Actually I have a "Movie" entity and I want to add a new attribute like "picture". Of course I have to add this attribute in my entity "Movie".
But I was wondering if I have to set some parameters like size, extension in my mapping comments.
Then, as I have not created yet my add for and edit form... I add manually datas in my database for testing my scripts.
Does the "picture" column contain only the name of the image like "toto.png" ?
If it's the case, what is the directory which will save the images ?

Assuming you use Doctrine as ORM, I suggest reading up on file uploads in the Symfony documentation. It describes the fields to create, form and upload handling. But yes, you basically store the filename in the field "picture" and create additional functions to help figure out the true path to the file.

Related

typo3 tx-news create a custom record type

i know how to create new news types thats stated here https://docs.typo3.org/p/georgringer/news/main/en-us/Tutorials/ExtendNews/AddCustomType/Index.html
But is it possible to extend it so that i can make a complete unique record type?
For example:
I want something like: "News Tag 2" - so a different type of record with different fields i can save.
Is that possible?
Thank you.
You can do that by writing your own extension which contains the new type as Exbase model. Then you can attach it to the news record by extending the news domain model

How to disable Edit/Hide/Delete in TCA for TYPO3 Extbase Domain Model?

As the title already says, I want to make a specific Extbase domain-model completely "read only" .. It is a custom Log-Entry model that shall be viewable but must not be modified via backend (they are being generated during certain controller actions).
I do not use the TYPO3 log system intentionally, because I want to have a separate log with its own db-table etc.
I do know about the readOnly property for columns, but I`d like to disable any modification-functions in the list view also.
Thanks in advance, Oliver
There's not only option "readOnly" for columns, this option can also be set for the whole table:
$GLOBALS['TCA']['yourTable']['ctrl']['readOnly'] = 1;
Have a look at EXT:static_info_tables, the records from this extension are not editable.

How to use Entity, Mapper, Service and Hydrator in ZF2

I am making a ZF2 app. I am using entities, mappers and services (e.g. UserEntity, UserMapper, UserService) to manage the objects/models. Properties in the entities are CamalCased (e.g. FirstName, LastName) while in the database, fields are using underscore (first_name, last_name). I will plan to use a hydrator to map the properties and db-fields when retrieving or saving. The service object (UserService) will be used to communicate with the mapper to retrieve and save data models using the mapper. The hydrator will convert the result of mapper and convert them into proper entities.
The thing I am confused is that when the service (UserService) need to provide some cirteria - for example to find all users with a specific 'last name', will the service use the database field names (last_name) or entity properties name (LastName)?
If the db field name is used in the Service, so any change in the db structure will require me to update the service also, which completely fails the reason of using the whole approach.
If you take a look at the ClassMethods:hydrate method (https://github.com/zendframework/zf2/blob/master/library/Zend/Stdlib/Hydrator/ClassMethods.php) you will see that it just copies the properties from one object to another. You have the option of converting the property names to/from camelCase but that's it.
If you change a column name in your database then you will need to change corresponding property name in your object. And vice versa. Which I believe is the crux of your question?
If you want to make table column names be independent of your method names then you need something that lets you define an actual mapping table somewhere. Change a column or method name and you only need to update the configuration mapping table.
Not a ZF2 expert so I could be wrong but it doesn't look like any of the supplied hydrators support this.
I do know that Doctrine 2 supports it.

Foreign entity in form into different kind of input

I have two entities: product and category (Symfony 2.3).
I want to create a form in which an user can choose a product by first selecting the category. A user selects the category by clicking on image, then I want to set the image's value into a hidden input, but I don't see how can I change a foreign entity choice list to a hidden input (http://symfony.com/doc/current/reference/forms/types/entity.html).
How can I accomplish this? (how to change form input to hidden)
If I set cascade validation to true, will it for example check if a category really exist. (To prevent putting products with non-existing category from malicious users) ?
Part 1
To do this you need to use a data transformer to do two things:
transform an entity into an identifier that is either a string or integer so a form can render it as a hidden field.
transform the string or integer identifier into the entity when the form is submitted so that the parent entity can be saved with the correct relationship
The symfony docs I linked to above (here too) actually walk though an entire example of using a data transformer with a form.
As a shameless plug (because I believe it is helpful) I have written a little tutorial on using a data transformer for a hidden field with an entity id: http://lrotherfield.com/blog/symfony2-forms-entity-as-hidden-field/
Part 2
If you are using the data transformer then you don't need to worry about malicious users. The data transformer will fail because it will not be able to reverse transform the category from the fake id. In my tutorial the transformer will throw a Symfony\Component\Form\Exception\TransformationFailedException exception.
You can also write a validator (potentially using a call back) if you wanted that checks that the submitted category is real if you want an error to show in the form. Doctrine wont allow you to persist a fake category relationship as the foreign key constraint will fail.

TYPO3 Extension Error: Cannot create empty instance of the class

My FE plugin created using extension builder shows me the following error :
Cannot create empty instance of the class "TYPO3\CMS\Extbase\Persistence\ObjectStorage" because it does not implement the TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface.
What does it mean and how do I resolve it?
TYPO3 version 6.1.0
My Domain Object named Subject has relations Category_Id m:n relation and Location_Id 1:n relation . I did not map these two to any table during the creation of the extension.
How do I mention this in the extension that these relations are related to certain tables (Category_table and Location_table)and are to be looked in their respective domain model objects to retrieve data ?
The problem is a little confusing, I hope I made myself clear
Thank You
You need to set up the relation within the TCA.
Make sure to clear the cache and to remove the typo3temp/Cache/.
Then you will need to annotate your model properly such that extbase can resolve the reference.
Remember: TCA for core and annotation for extbase