New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.0 RFC: Reintroduce 'AppModel' / Related: Renaming 'Post.php' to 'PostEntity.php' (consistency across MVC domains) #4421
Comments
There's a big problem with this suggestion and it's the implicit assumption that all tables and entities will extend App*. Outside of an app (i.e. plugins) that's not true and moreover the app namespace is a variable, so not-app classes can't use them anyway. It really isn't a chore to create I don't understand the "behavior management across apps" point. If a table uses a behavior that you want to unbind before it does anything - it probably shouldn't be bound by default. This is possibly a hint as to why composition over inheritance is a better idea. |
I feel this is the kind of thing that can easily be done by people that need/want it. The App* were a huge headache in 2.x and that is one of the many reasons they don't exist in 3.x. |
So the path will rather be remove AppController as well (in 3.1? 3.2?)? |
I still think AppController provides enough value to warrant its inclusion. Most AppModel methods I used were hacks around the old ORM's limitations. |
My vote also is to not add or remove any App* class in 3.0. What we have currently is fine. |
So I will close this. Maybe the issue will be revisted in 3.1 (e.g. making things consistent by removal off AppController ... or reintroduction of AppTable and AppEntity. Just to be on the safe side I do think moving to Entity postfix for entities is a good call, but NVM). |
I'd have thought inheriting from one's own AppX classes could provide value in any case. Not everyone necessarily abuses it. 😉 ... That said, one can just inherit from one's own classes. |
👍 |
This just came up in one of our projects. We're adding a No slight against the core team though; they made the call they thought was best. We'll be implementing our own AppTable, modifying our app skeleton to provide it out of the box, and updating our bake templates to produce Table classes that reference it. It's just unfortunately a lot of extra work we didn't have to think about with 2.x. The "simple" path is more complex then it used to be. |
The way that we do this is to catch the global \Cake\Event\EventManager::instance()->on('Model.initialize', function (\Cake\Event\Event $event) {
$event->subject()->addBehavior('CreatorModifier.CreatorModifier');
}); BTW, the plugin I'd recommend for recording creator_id and modifier_id is https://github.com/UseMuffin/Footprint |
@dakota Thanks for the pointer. Ours is a crude version of that, but it'll do for now. If we outgrow it, it's good to have an alternative lined up. I recognize the |
@beporter not only for the core team, I found those classes error prone for everyone else. Do you remember all the times you had to make an exception for a plugin model or any other model because the AppModel was being "too smart"? What is wrong with having your own AppTable, btw? |
@lorenzo :waves hand: This isn't really the place for that. I'm happy to have the conversation in Slack or irc or email (I have no shortage of opinions 😉), but we don't need to pollute this thread with a meta conversation. I have a path available to me to resolve the issue, and my team and I will use it-- nothing more needs to be said here. Thanks all. |
@beporter I'd have loved to see a log of that conversation to see some perspectives. |
I don't see how having a core provided AppTable is any better/different than implementing it on an as needed basis in applications. |
I've written four different drafts trying to come up with an approach that isn't going to start a much, much deeper discussion and all four are abject failures at that. @lorenzo, @markstory: I can't address your questions here, even if I feel like I might have a case to make. I'm willing to just let it go for now. |
Reintroduce 2.x
AppModel.php
in form of 3.xAppTable.php
andAppEntity.php
.Any Table / Entity extends
AppTable
/AppEntity
instead of Core'sTable
/Entity
.Why?
parent::initialize()
)Cons:
AppTable.php
/AppEntity.php
. Does not enforce refactoring into Behaviors, traits, keeps upgrading 2.x to 3.x apps easier.Related:
Reintroducing
AppEntity.php
is one more reason to rename standard Entites toFooEntity.php
instead of simpleFoo.php
.Having
AppTable
andAppEntity
clearly shows off the new features of CakePHP 3 vs CakePHP 2 to newbies and switchers e.g. the App prefix reminds them offAppModel.php
while keeping easy ways to extend all Tables/Entities.As for Behavior management across apps
Maybe there should be a way to register behaviors (and components, helpers) to be loaded and to unregister them to not be loaded so that they should only be loaded right after
initialize()
is called (via events)?This way if you call
parent::initialize()
and then unload (or rather unregister) a component, it will never fetch the php files nor instantiate any object.The text was updated successfully, but these errors were encountered: