[TYPO3-mvc] Howto check if object with a specific uid is related to an object (m:n relation)?

Henjo Hoeksma me at henjohoeksma.nl
Wed Nov 16 21:02:04 CET 2011


Hi Roland,

what you do here is extending your object model with a property of
something it can reach already. To me that doesn't sound too clean ;-)

Since you already have the type related to your Download object, I would go
for writing a viewhelper that returns true (or the string
class="important") after giving it the objects of the download types and
checking from within your viewhelper if it exists.

Thinking DDD: do you really need to have a m:n relationship from download
to type? Can one download really have multiple types? I might not
understand what you are trying to achieve, but if it can't, make it a n:1
relationship (types can have multiple downloads, but a download can only
have one type).

Then from within your downloads controller you can simply say
{f:if(condition:download.downloadType.type=1, then:'class=Important')} ...

Kind regards,

Henjo

Problems are small because we learned how to deal with them.
Problems are big because we need to learn how to deal with them.


On Wed, Nov 16, 2011 at 18:04, Roland <most.wanted at gmx.at> wrote:

> i found a solution - i do not know, if it is a clean one:
>
> --- Download.php ---
>
> /**
>  * Checks, if Download is of type #1.
>  *
>  * @return boolean
>  */
> public function getStatusType1() {
>        $types = $this->getTypes();
>        foreach ($types as $type) {
>                if ($type->uid == 1)
>                        return 1;
>        }
>        return 0;
> }
>
> --- /Download.php ---
>
> then i use something like this in my fluid template:
>
> --- quote ---
>
> <f:if condition="{download.**statusType1} == 1">...</f:if>
>
> --- /quote ---
>
> what do you think - is this a good solution? Can you do it better/cleaner?
>
>
> kind regards.
>
> roland
> ______________________________**_________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc@**lists.typo3.org<TYPO3-project-typo3v4mvc at lists.typo3.org>
> http://lists.typo3.org/cgi-**bin/mailman/listinfo/typo3-**
> project-typo3v4mvc<http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc>
>


More information about the TYPO3-project-typo3v4mvc mailing list