John Davidson

php - Defining model properties in typo3

0 comments
Message:


I'm learning typo3. I have my own Idea model, and this ideas have one and just one category. So my ideas table has a category column with the id of the core system categories from typo3. I understand that in order to set that category property correctly I have to do something the following code. But I don't know what does this mean or how to use ObjectStorage. Any documentation about ObectStorage will be well received.


What does it mean what's between <>? What type of variable is then? ObjectStorage or Category?


/**
* The category of the idea
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category>
*/
protected $category;


My Answer:
php
/**
* The category of this idea
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category>
*/
protected $category;


In this code snippet, the `$category` property of the Idea model is defined as an ObjectStorage object that can hold instances of the Category model. ObjectStorage is a class provided by Extbase that allows you to store and manage collections of objects.

To use ObjectStorage in your model, you can initialize it in the constructor of your Idea model like this:

php
public function __construct() {
$this->category = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}


You can then add and remove Category objects to the `$category` property using methods provided by ObjectStorage, such as `attach()` and `detach()`.

For more information on ObjectStorage and how to use it, you can refer to the official TYPO3 Extbase documentation: https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Extbase/Property/PropertyMapper.html#objectstorage

Rate this post

4 of 5 based on 1622 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us