core icon indicating copy to clipboard operation
core copied to clipboard

Models and DCA -> load and save_callbacks (Feature)

Open danielhoover opened this issue 10 years ago • 6 comments

Hello my dearest Contao Core Developers,

There were several opportunities where it would have been nice if the Models use the defined load and save_callbacks from the dca. I assume you have thought about this one too - and I wonder why you have decided, that this is not implementable - or haven't you thought about this feature?

Small example:

Let's say you have a module that extends tl_news and gives the opportunity to import news from a crappy CMS to awesome contao. Within that interface you get almost every data and assign it to the NewsModel. For example:


$importedNewsEntries = $this->getEntriesFromSomewhere();

foreach($importedNewsEntries as $newsEntry)
{
   $newsObj = new NewsModel();
   $newsObj->headline = $newsEntry->title;
   //.... other stuff like data, subheadline and so on is imported...

  //now if you save the $newsObj
  $newsObj->save(); //wouldn't it be nice if tl_news->generateAlias() is triggered?
}

Just an idea - do you think this would be a nice feature - that is not too hard to implement? I know, that the Models where designed to replace the usual $this->Database->prepare("UPDATE tl_whatever SET ...") bla bla - but don't you think a connection to the dca would be useful?

Kind regards Daniel

danielhoover avatar Nov 06 '15 08:11 danielhoover

@danielhoover you don´t must save the entry by self. Do return the new value

baumannsven avatar Nov 06 '15 08:11 baumannsven

@baumannsven I'm not sure if I understand fully what you mean? I know, that I can implement the tl_news->generateAlias() feature within the module - but why copying something where the creator of the dca already has taken care of?

danielhoover avatar Nov 06 '15 08:11 danielhoover

@contao/developers What do you think about this?

leofeyer avatar Mar 20 '18 17:03 leofeyer

I totally understand and like the idea. I don't know if there are any issues in case of BC?

bytehead avatar Mar 20 '18 17:03 bytehead

The only problem I have is that DCA files are meant to run in the context of a data container like DC_Table and not within a model.

leofeyer avatar Mar 20 '18 17:03 leofeyer

This will never work correctly imho. We should rather target for Doctrine entities to support their lifecycle callbacks.

aschempp avatar Mar 21 '18 13:03 aschempp