What's the difference between a Component and a Model in Craft 3?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I'm trying to familiarize myself with the Craft architecture and I can't understand whether I should be extending craftbaseComponent
or craftbaseModel
for my business logic models. Component seems like a pretty lean class that only adds a few initialization events to Model.
plugin-development craft3 models element
add a comment |Â
up vote
1
down vote
favorite
I'm trying to familiarize myself with the Craft architecture and I can't understand whether I should be extending craftbaseComponent
or craftbaseModel
for my business logic models. Component seems like a pretty lean class that only adds a few initialization events to Model.
plugin-development craft3 models element
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm trying to familiarize myself with the Craft architecture and I can't understand whether I should be extending craftbaseComponent
or craftbaseModel
for my business logic models. Component seems like a pretty lean class that only adds a few initialization events to Model.
plugin-development craft3 models element
I'm trying to familiarize myself with the Craft architecture and I can't understand whether I should be extending craftbaseComponent
or craftbaseModel
for my business logic models. Component seems like a pretty lean class that only adds a few initialization events to Model.
plugin-development craft3 models element
plugin-development craft3 models element
asked Aug 28 at 18:50
Lazlo
1406
1406
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
down vote
accepted
Models are classes that contains abstractions of the reality, for example you could have the model car that contains the technical information about it, how many wheels it has and it's brand. Models are usually not supposed to contain any logic. So it's just a "container" with information
Components are more like services that contains business logic to work with your models, for example the service car would handle the logic to let your car model drive and move and such. Components in Yii2 are mostly (not always) treated as singletons while you want to have many different instances of your models
Thanks for the clarification! I just realized Services in Craft were actually extending Components in Yii. A bit confusing in terminology, but I'm starting to wrap my head around it!
â Lazlo
Aug 28 at 19:51
A minor caveat, and a caution. First the caveat: there is a strong argument that anemic models are an anti-pattern. That said, Robin is correct in stating that this is The Craft Wayâ¢. That leads me to the caution: bear in mind that your service classes "define your pluginâÂÂs API, which your plugin (and other plugins) can access" (source; emphasis added).
â Stephen Lewis
Aug 29 at 6:06
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
Models are classes that contains abstractions of the reality, for example you could have the model car that contains the technical information about it, how many wheels it has and it's brand. Models are usually not supposed to contain any logic. So it's just a "container" with information
Components are more like services that contains business logic to work with your models, for example the service car would handle the logic to let your car model drive and move and such. Components in Yii2 are mostly (not always) treated as singletons while you want to have many different instances of your models
Thanks for the clarification! I just realized Services in Craft were actually extending Components in Yii. A bit confusing in terminology, but I'm starting to wrap my head around it!
â Lazlo
Aug 28 at 19:51
A minor caveat, and a caution. First the caveat: there is a strong argument that anemic models are an anti-pattern. That said, Robin is correct in stating that this is The Craft Wayâ¢. That leads me to the caution: bear in mind that your service classes "define your pluginâÂÂs API, which your plugin (and other plugins) can access" (source; emphasis added).
â Stephen Lewis
Aug 29 at 6:06
add a comment |Â
up vote
5
down vote
accepted
Models are classes that contains abstractions of the reality, for example you could have the model car that contains the technical information about it, how many wheels it has and it's brand. Models are usually not supposed to contain any logic. So it's just a "container" with information
Components are more like services that contains business logic to work with your models, for example the service car would handle the logic to let your car model drive and move and such. Components in Yii2 are mostly (not always) treated as singletons while you want to have many different instances of your models
Thanks for the clarification! I just realized Services in Craft were actually extending Components in Yii. A bit confusing in terminology, but I'm starting to wrap my head around it!
â Lazlo
Aug 28 at 19:51
A minor caveat, and a caution. First the caveat: there is a strong argument that anemic models are an anti-pattern. That said, Robin is correct in stating that this is The Craft Wayâ¢. That leads me to the caution: bear in mind that your service classes "define your pluginâÂÂs API, which your plugin (and other plugins) can access" (source; emphasis added).
â Stephen Lewis
Aug 29 at 6:06
add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
Models are classes that contains abstractions of the reality, for example you could have the model car that contains the technical information about it, how many wheels it has and it's brand. Models are usually not supposed to contain any logic. So it's just a "container" with information
Components are more like services that contains business logic to work with your models, for example the service car would handle the logic to let your car model drive and move and such. Components in Yii2 are mostly (not always) treated as singletons while you want to have many different instances of your models
Models are classes that contains abstractions of the reality, for example you could have the model car that contains the technical information about it, how many wheels it has and it's brand. Models are usually not supposed to contain any logic. So it's just a "container" with information
Components are more like services that contains business logic to work with your models, for example the service car would handle the logic to let your car model drive and move and such. Components in Yii2 are mostly (not always) treated as singletons while you want to have many different instances of your models
answered Aug 28 at 19:24
Robin Schambach
13.6k1427
13.6k1427
Thanks for the clarification! I just realized Services in Craft were actually extending Components in Yii. A bit confusing in terminology, but I'm starting to wrap my head around it!
â Lazlo
Aug 28 at 19:51
A minor caveat, and a caution. First the caveat: there is a strong argument that anemic models are an anti-pattern. That said, Robin is correct in stating that this is The Craft Wayâ¢. That leads me to the caution: bear in mind that your service classes "define your pluginâÂÂs API, which your plugin (and other plugins) can access" (source; emphasis added).
â Stephen Lewis
Aug 29 at 6:06
add a comment |Â
Thanks for the clarification! I just realized Services in Craft were actually extending Components in Yii. A bit confusing in terminology, but I'm starting to wrap my head around it!
â Lazlo
Aug 28 at 19:51
A minor caveat, and a caution. First the caveat: there is a strong argument that anemic models are an anti-pattern. That said, Robin is correct in stating that this is The Craft Wayâ¢. That leads me to the caution: bear in mind that your service classes "define your pluginâÂÂs API, which your plugin (and other plugins) can access" (source; emphasis added).
â Stephen Lewis
Aug 29 at 6:06
Thanks for the clarification! I just realized Services in Craft were actually extending Components in Yii. A bit confusing in terminology, but I'm starting to wrap my head around it!
â Lazlo
Aug 28 at 19:51
Thanks for the clarification! I just realized Services in Craft were actually extending Components in Yii. A bit confusing in terminology, but I'm starting to wrap my head around it!
â Lazlo
Aug 28 at 19:51
A minor caveat, and a caution. First the caveat: there is a strong argument that anemic models are an anti-pattern. That said, Robin is correct in stating that this is The Craft Wayâ¢. That leads me to the caution: bear in mind that your service classes "define your pluginâÂÂs API, which your plugin (and other plugins) can access" (source; emphasis added).
â Stephen Lewis
Aug 29 at 6:06
A minor caveat, and a caution. First the caveat: there is a strong argument that anemic models are an anti-pattern. That said, Robin is correct in stating that this is The Craft Wayâ¢. That leads me to the caution: bear in mind that your service classes "define your pluginâÂÂs API, which your plugin (and other plugins) can access" (source; emphasis added).
â Stephen Lewis
Aug 29 at 6:06
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcraftcms.stackexchange.com%2fquestions%2f27506%2fwhats-the-difference-between-a-component-and-a-model-in-craft-3%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password