logo
down
shadow

MVC: How to separate Model from Controller


MVC: How to separate Model from Controller

By : Fran gulosh
Date : November 21 2020, 11:01 PM
will help you Model How to work with the data (Create Read Update Delete at least).
Controller Business logic or what to do with the data, your controller is the interconnection between the model and the view, you get stuff from the model, you work with it and you pass it to the view, the user react (click of a btn) using an element in the view and it triggers an event that is cought by the controller, then the controller do stuff ... and basically you start again.
code :


Share : facebook icon twitter icon
Is ASP.NET MVC is really MVC? Or how to separate model from controller?

Is ASP.NET MVC is really MVC? Or how to separate model from controller?


By : Vijaya Kumar
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I think it could be either way. Here would be an implementation is ASP.NET MVC that keeps the logic like you had in your first example.
Model (Respository)
code :
Function switchOn() as bulb
    if !bulb.lightOn then
        bulb.lightOn = true
    end if
        return bulb
End Function

Function switchOff() as bulb
    if bulb.lightOn then
        bulb.lightOn = false
    end if
        return bulb
End Function

Function Motion(senseMotion as boolean) as bulb
    if(senseMotion and !bulb.lightOn) then
         bulb.lightOn = true
    end if
    return bulb
End Function
Function PressSwitchOn() as actionresult
     return view("Bulb", lightRepository.switchOn)
End Function

Function PressSwitchOff() as actionresult
     return view("Bulb", lightRepository.switchOff)
End Function

Function SomethingMoved(byval hasMoved as boolean) as actionresult
     return view("Bulb", lightRepository.Motion(hasMoved))
End Function
Displaying a model associated with a separate controller

Displaying a model associated with a separate controller


By : Gabriella W.
Date : March 29 2020, 07:55 AM
wish of those help At the first look what I see is missing is the correct setup of an one-to-one relation between two models.
Example:
code :
# website_template model
App.WebsiteTemplate = DS.Model.extend
  webLayout: DS.belongsTo("App.WebLayout")

# website_layout model
App.WebLayout = DS.Model.extend
  name: DS.attr("string"),
  thumbnail: DS.attr("string"),
  websiteTemplate: DS.belongsTo("App.WebsiteTemplate")
Ember.Handlebars.registerHelper('equal', function(value1, value2, options) {
  if (value1 === value2) {
    return options.fn(this);
  } else {
    return options.inverse(this);
  }
});
{{#equal webLayouts.id webLayout.id}}
  are equal
{{else}}
  not equal
{{/equal}}
Do I need a separate Model/Controller for each scenario, or can I reuse a single Model/Controller for multiple scenarios

Do I need a separate Model/Controller for each scenario, or can I reuse a single Model/Controller for multiple scenarios


By : Mark Baynes
Date : March 29 2020, 07:55 AM
I wish did fix the issue. There's no compelling reason to limit a Model to a single Controller or to expect that a Controller has only one Model. You could write your entire app in a single Controller (really bad idea, by the way).
Generally, the division is a logical one...a bunch of actions that talk to the same set of Models in one controller. It's more to keep your brain from melting when you open the source file as anything else.
Do I need a separate controller for each model in Laravel?

Do I need a separate controller for each model in Laravel?


By : user290898
Date : March 29 2020, 07:55 AM
To fix this issue No, you don't need a separate Controller. You can return a response right from your routes file:
code :
Route::get('/models', function() {
    return Model::first();
});
Why separate Model and Controller in MVC?

Why separate Model and Controller in MVC?


By : Fernando Cardozo
Date : March 29 2020, 07:55 AM
it should still fix some issue Phalcon's Phalcon\Mvc\Model class, which your models are supposed to extend, is designed to provide an object-oriented way of interacting with the database. For example, if your table is Shopping_Cart then you'd name your class ShoppingCart. If your table has a column "id" then you'd define a property in your class public $id;.
Phalcon also gives you methods like initialize() and beforeValidationOnCreate(). I will admit these methods can be very confusing regarding how they work and when they're ran and why you'd ever want to call it in the first place.
shadow
Privacy Policy - Terms - Contact Us © soohba.com