Dolibarr: Better support for OOP, add MVC pattern

Created on 19 Dec 2016  Â·  20Comments  Â·  Source: Dolibarr/dolibarr

Feature Request

Separate html from php functions, don't make echo "<tag>$variable</tag>";

Suggested implementation

New folder in every module folder called "view"
Generic function for load view. For example:
//Actual php behaibour like Controller
Render view in Module (Product)
echo $view->render('list,$products);

//View inside (/product/view/list.php)

<table>
<?php 
if(!empty($products)):
   foreach($products as $product):
?>
<tr>
<td><?php echo $product->id;?></td>
<td><?php echo $product->name;?></td>
<td><?php echo $product->barcode;?></td>
</tr>
<?php 
   endforeach;
endif;
?>
</table>
Discussion Issue Stale (automatic label)

Most helpful comment

Hi,

I would like this kid of pattern. Because it will be easy to create a new theme if the php and html were separated like wordpress. Now is a nightmare to edit the css that contain php. crazy in 2017 they but together css and php and html in the same file. Hope this will change for the version 7.

All 20 comments

That would probably be a lot more easier for us business users (non developers) so we can add bits of html to pages on the fly without affecting the database and core of the set up etc.

I doubt anyone in the team would agree to this though as it sounds like a big job and a massive change for dolibarr.

This has been discussed times and times again on the mailing list. It comes up every so often.
I'd also love to have a more modern codebase but, as noted, this would be a huge undertaking and our mentor @eldy still prefers the current pattern. Good luck convincing him ;)
The rationale for the current pattern is explained in the wiki.

If you're willing to contribute such a change, make a plan, submit it to the community and take baby steps so that the changes are digestible by the maintainers.

Hi,

I would like this kid of pattern. Because it will be easy to create a new theme if the php and html were separated like wordpress. Now is a nightmare to edit the css that contain php. crazy in 2017 they but together css and php and html in the same file. Hope this will change for the version 7.

See my pull request #6320

I like the idea to reduce code in layers, don't mix html and php in the middle of functions, methods or clases. Is a bad practice and spaguetti code. @rdoursenaud @eldy if check de product code add and edit are really similar and have basic the same layout template form if we use the same template we reduce a lot of copy paste code. I'dont like the file.tpl. prefixes of extension or file.class.php is and old deprecated practice, if you already have a folder tpl or class. We need to upgrade the code more compatible with autoloaders.. and use PSR Standart. Other CRM like Sugar made this change.

@acericonia you forgot JS. Yes, this is giving me nightmares…

Hi,

Guys I don't know which version will move with MVC, they still stick with the all version of dev and they don't went to make a all new dev structure because it can delay the schedule. Maybe the version 10 or late will integrate this. hope before because dolibarr is lagging for other ERP.

This is my first attempt, in baby steps as @rdoursenaud says. I will improve the commit to pass the declarations or other changes that are in the middle of the view to the original php and load the same template for the modification. So that @eldy evaluate again to see if it convinces my change.

Yes, if goodwill, like yours gnovaro, is showed to change the structure, surely Eldy would be more keen on accepting...
At the moment, as he's reviewing/implementing everything (almost, no?) in Dolibarr he has the last word. If someone says my desk is dusty, i will not let him clean it before i sort all my mountain of paper on it ;)
Imagine he says yes, we can start implementing this pattern and give each one responsible for a task...
HOW, practically saying, is it possible to integrate the changes, without making a big mess in between ?
Is it possible to work on 3 versions, one with old pattern, another one with new pattern only, and a third one with 2 patterns mixed ?
HOW LONG ? how much time it could take one week 10 persons, one month 10 persons, 1 year 2 persons ?
Changing pattern means focusing all effort on the change, for one version, no bugfix, no NEW, no integration of external modules developped with old pattern, for a loooong time ?
Thanks for noob answers :)

Eldy is a old school developer maybe the developers community may change his responsibility and make reform. They can't continue like this way. We are in 2017 and this kind of development is not allow to do on a Enterprise ERP solution. They don't think about the partner and developers that make services for small business. Because this old school development is a nightmare for edit files and change layout. I don't want to say like this but maybe they have to fire Eldy.

If you look others like Vtiger, etc... man Dolibarr look like windows 2003 application.

@acericonia : please go help Vtiger making money for the sake of your mind
What's the goal of making a shiny ERP ?
you know what looks like Oracle or Sage ERP's in some "real" business applications ?
like some commodre 64 screen. and yes they sell it by billions...

@BebZ You don't need to know me OK and skills , I'm not interesting you. I just giving my point of view. And Some will agree and others not. So fuck you if what I say is not for you.

Oh if you want what I do or done look back my GitHub, maybe you will some answers before you write some stipid word like who are you and what is your skills.

I'm agree with @BebZ on this case

Is it possible to work on 3 versions, one with old pattern, another one with new pattern only, and a third one with 2 patterns mixed ?
HOW LONG ? how much time it could take one week 10 persons, one month 10 persons, 1 year 2 persons ?
Changing pattern means focusing all effort on the change, for one version, no bugfix, no NEW, no integration of external modules developped with old pattern, for a loooong time ?

It's a massive job, and the product has to continue to live !
But everyone can already do it, begin with your own module.

Then yes of course I'm not always agree with @eldy but without him I don't think that Dolibarr would have this progression !

On an open source project, it's always possible to criticize but firstly, we should try to help the community !

Yes @laudeco You speak correctly, but did you saw what @BebZ wrote. This is not how to speak. I know it's massive job, but you don't need to shift one time. Step by step integrate a pattern. or maybe the developers community communicate and say with version will go this way or if they want to do.

Of course, but his own module could be a good starting point no ?

Thanks @gnovaro for the HOW part ;) !
if i take an extract from your link :
"
ShitController needs to account for using the new application framework while also supporting the old way of doing things (pre-5.0). As we said above, the action is DetailView. If the ShitController finds a file named: DetailView.php in the Leads module, it will load this file, otherwise it will check if the controller has a method named: action_detailview() which will then handle the request. There are several more configuration options which allow us to map actions directly to views or even map actions directly to files, but I will leave those until later.

This is all well and good, but what about when the developer wants to implement their own action_detailview()? In order to do this, the developer can simply drop a custom controller.php file into custom/modules/Leads.

By that token, the developer’s custom controller would be named controller.php and the class name would be: LeadsController, basically ucfirst(module).’Controller’.
"

@acericonia : go Vtiger plan

Guys, please keep the discussion friendly and focused on the tech. This kind of behavior is unnecessary and won't be tolerated.

Man @BebZ you have a problem, as @rdoursenaud said focus on supporting dolibarr by making submit bugs or features suggestions. I'm above you so I wan't continue to disuse with you.

Best regard.

This issue is stale because it has been open 1 year with no activity. If this is a bug, please comment to confirm it is still present on latest stable version. if this is a feature request, please comment to notify the request is still relevant and not yet covered by latest stable version. Without comment, this issue will be closed automatically by stale bot in 15 days.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

borsti67 picture borsti67  Â·  5Comments

asolslk picture asolslk  Â·  4Comments

esprit-libre picture esprit-libre  Â·  3Comments

Sylvain089 picture Sylvain089  Â·  4Comments

truefriend-cz picture truefriend-cz  Â·  5Comments