[TYPO3-mvc] Understanding MVC

abo at schmutt.de abo at schmutt.de
Sat Mar 23 09:43:02 CET 2013


Hi, 

i can tell you my approach:

I have usually 1-2 controller, they do the logic what piece to display. 
These pieces are the actions. 
and with forward they can call other actions if necessary. Example: after create new, I redirect to list view. 

I use partials for redandant view pieces,  so they are usable in different actions, even in backend. 

A really great thing are view helper for these tiny pieces of helper code. you can use them for any kind of code that is not tied directly to a model. Not only View stuff.
Using them makes contoller, repository and template cleaner code, as they can carry all the special case logic: if user is admin show more info on this and that, customer wants on group XY a red border, show currency dependant on country selection, ...
Just pass all data in objects to view, and let view helper decide what to display. 

All my advanced code is in repository. This is not the best approach, but it works until I find something better. 
Loading aggregated data from database, calculate table content, save processed data to DB. 
Anything that is special and not working with automatic extbase magic, I use the new SQL functions and do load and storage by myself. Works fine with only 2-3 lines of code... 

As I come from oldschool TYPO3 development, I still use data arrays if they are smarter. They can be processed in Fluid like objects. And you can reuse old code with that: call old functions, get array data and show it with extbase controller and fluid view.

There are Ajax functions as well, if you want to display 5 actions on one page, but I didnt use them yet. 

Best Regards, 
Andrea


Am 22.03.2013 um 11:54 schrieb Robert Schneider <r.schneider at artworx.at>:

> Hi NG,
> 
> now I have to develop another extbase/fluid based extension. But I have a problem understanding how to realize this in general.
> 
> I have used the extension builder which works fine so far. I have checked those actions like create, delete, list and so on. This produces a basic views where I can do all that CRUD stuff (currently, I'm only dealing in the backend, however, the issue is the same for the frontend).
> 
> But this is really basic and I guess it is not the way how it gets usually used. Who wants seperate pages for each object type? A list of customers, a list of orders, a new customer forumalar page, ...
> 
> More likely the view gets designed different. But how to to do this with view files, partial files and the controllers?
> 
> In my case I'd like to have a page where I see on the left side a list of customers and a list of campaigns of the customer which get refreshed if the customer gets changed. On the right side of the page there should be a list of vouchers of the selected customer and the campaign. New customers and campaigns should be added directly 'in the list'. They should get renamed or deleted directly in the lists as well.
> 
> If I have an index action I can display all these things on the page. Now, should this index action be part of the customer controller or should I create another controller?
> 
> And what is if the user wants to add another customer? I don't want to display another page. So I thought I could add a form onto the page that gets shown if it is required. I think this is okay. And I could imagine to have a partial file for the list with its customer specific actions. But now, how do I present the whole page again after submit? I though there would be an add action with a string parameter for the customers name (currently the only property of the customer) that looks like this:
> 
> public function createAction($name) {
>    /** @var $customer Customer */
>    $customer = GeneralUtility::makeInstance(
>        'artworx\\Eldclickbelt\\Domain\\Model\\Customer');
>    $customer->setName($name);
>    $this->customerRepository->add($customer);
> 
>    $persistenceManager = GeneralUtility::makeInstance(
>        'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
>    $persistenceManager->persistAll();
> 
>    $this->forward('index', NULL, NULL, array(
>        'selectedCustomer' => $customer));
> }
> 
> (This diverges from the extension-builders way with create/new. So is this already a bad approach?)
> 
> Should I forward to the index action? Is this correct? I'm feeling unsure with this. I suppose it is bad practice. Is a add.html file better? What should I do?
> 
> In general I would say I do not understand how to build a page with many elements and many different actions of many different controllers. I don't want to have seperate pages for each 'create new' action. And I think it will be wrong if each called action then redirects/forwards to a global index action. Is it common and logical that an action defines what to display next? And how do I deal with actions called via ajax?
> 
> Hm... many questions. I would be very happy if one could provide some hints, concept, ideas. Are there any web sites regarding these themes?
> 
> Thank you and have a nice weekend!
> Robert
> 
> 
> _______________________________________________
> 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