[TYPO3-mvc] Models and logic
Jochen Rau
jochen.rau at typo3.org
Mon Apr 16 17:22:29 CEST 2012
Hi Toke,
Welcome to Extbase and this list.
> Well, if you're creating a survey, you might want to compare the
> number of questions in the survey to the number of answers given
> from the actual user, inorder to get a persentage of the completion
> of the survey.
I assume that "non DB logic" in you previous post means "transient data"
(= data which not has to be stored in the data base).
There are two different kinds of state mixed up in the given survey example:
- The state of the model (questions and answers), and
- the state of the application (percentage done).
The architecture of the web is stateless (no state should be saved on
the server side). I would sent the state as a http parameter along with
the POST request sent by the form:
http://example.com/survey?givenAnswersSoFar=12
> This you wouldn't want to save in the DB as this isnt really
> anything you'd need there, and it'll change rapidly anyway.
>
> My question is: how do the reflection and autoload react to getters
> and setters in a Domain Model which do not have a corresponding TCA
> field ?
Just fine.
> I'm just trying to figure out how to get the models doing more of
> the stuff which is model logick instead of having it done in the
> controller or view.
>
> EG:
>
> function aModelGetState(){
> $res = array();
> $this->getChildren()->rewind();
> while($this->getChildren()->current->valid()){
> $cur = $this->getChildren()->current();
> $res['children'][$cur->getUid()] = $cur->getState();
> }
> return $res;
> }
>
> I know simplified, but should make my question clearer.
Hmm. I guess this is more a 'hack'.
Best
Jochen
> Regards,
> Toke Herkild
>
> Den 16-04-2012 10:25, Frank Gerards skrev:
> >Hi,
> >
> >+1 with TIM...
> >to be more concrete:
> >DB-related methods shouldn't be handled by a model imho.
> >
> >Children of a model are normally referred in a model-property of type Tx_Extbase_...._ObjectStorage.
> >What exactly do you mean with "state of completion" and "state" ?
> >
> >Persistence mechanisms like the persistAll() method are built-in features of extbase.
> >
> >Greetz,
> >frank
> >
> >
> >-----Ursprüngliche Nachricht-----
> >Von: typo3-project-typo3v4mvc-bounces at lists.typo3.org [mailto:typo3-project-typo3v4mvc-bounces at lists.typo3.org] Im Auftrag von Toke Herkild
> >Gesendet: Montag, 16. April 2012 10:03
> >An: typo3-project-typo3v4mvc at lists.typo3.org
> >Betreff: [TYPO3-mvc] Models and logic
> >
> >Hi all,
> >
> >Having started using Extbase, I've come to the following question:
> >
> >Is it possible to add non DB logic to a model ?
> >
> >Often when doing a MVC project you often got operations which are not really DB logic, but still is part of the model and not the controller, nor the view, but you need those operations inorder for the view to do the right thing.
> >
> >EG: if you have a larger relational three, and you need a combined state of it's completion. you'd have to parse through the different states of the model and it's children, and return an array, containing the total state.
> >ex: this->view->assign('state', $TModel->getState());
> >
> >Regards
> >Toke Herkild
> >_______________________________________________
> >TYPO3-project-typo3v4mvc mailing list
> >TYPO3-project-typo3v4mvc at lists.typo3.org
> >http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>
More information about the TYPO3-project-typo3v4mvc
mailing list