model-view-controller

MVC best practice

允我心安 提交于 2020-01-03 20:07:13
问题 I'm new to MVC (i'm using codeigniter) and was wondering where I should put a "cut_description" function. My model retrieves a list of events including their description. If the description is too long, I would need to cut it after the first n words, and add a "read more" link, so the view doesn't get too cluttered. What would be the best practice? add the logic to cut after n words to the model add the logic to the controller add it to the view? I think 3 would be the easier (I have to loop

Validate form input in Domain Objects setters?

两盒软妹~` 提交于 2020-01-03 17:35:49
问题 Since I got into learning about MVC I have always validated my form data in my controllers which is a habit I picked up while skimming through CodeIgniters code but I have learned that its way of doing certain operations is not the best, it just gets the job done. Should all form data be validated by the domain objects? And if so should it be done in the setters like so public function setFirstName($firstName) { // Check if the field was required if(!$firstName) { throw new

passing a parameter to the link_to method

旧城冷巷雨未停 提交于 2020-01-03 17:07:44
问题 How do you pass a parameter through the MVC using the link_to method? view: <%= link_to "Remove Tag", remove_tag_issue_path(issue)%> How do I use the link_to method, to utilize the remove_tag action? issues_controller.rb def remove_tag(parameter) @issue.remove_it(parameter) end issue.rb def remove_it(parameter) self.users.delete(User.find(parameter)) end 回答1: In controller def remove_tag @issue.remove_it(params[:my_param]) end And in view <%= link_to "Remove Tag", remove_tag_issue_path(issue,

Can a Controller have database queries (MySQL)? If yes, when?

风格不统一 提交于 2020-01-03 16:53:42
问题 I am reading lots of tutorials on MVC, so my question, can a perfect PHP MVC framework have database queries in Controller? As I understand, the most comfortable way is to put all database queries in Model, right? And if I have POST or smth, I just pass that POST to Model and it makes all inserts and etc. ? Or I am missing something? And if Controller can have a database queries, in which situation would it be? 回答1: No controller may not have any db related code - any DB queries may be stored

How can I go through a Set in JSP? (Hibernate Associations)

寵の児 提交于 2020-01-03 10:40:56
问题 So I am pretty new to JSP. I have tried this a few ways. Ways that would make sense in PHP or automagicy frameworks... I am probably thinking too much in fact... I have a hibernate one to many association. That is class x has many of class y. In class x's view.jsp. I would like to grab all of class y, where the foreign key of y matches the primary key of x and display them. It seems that hibernate properly puts this stuff into a set. Now, the question is how can I iterate through this set and

MVC PHP - Sending mail from Model

倖福魔咒の 提交于 2020-01-03 10:19:19
问题 I am having problem to figure whenever I should send mail from the Model or the Controller. The thing is In the controller i use like This is regarding PHP. In Controller: if (Post::get()){ $this->model->registerUser( ... ); $this->model->mailSendUserActivation(); // assign something to view. } In Model: public function mailSendUserActivation(){ $mail = new \com\Mail(); // assign stuff to mail from API classes and other functions in model. $mail->send(); } Is this correct ? Or should the mail

pass model from one action to another action in same controller

删除回忆录丶 提交于 2020-01-03 09:04:39
问题 I am trying to pass my model List< Models.Statement > statementList from one action to another but i am receiving null value in the 2nd controller. Please suggest what is wrong here. Even tried with: return RedirectToAction("WriteInTemplate", new { statementList = statementList }); Please help. public ActionResult SendPdfStatement(string InvoiceNumber) { try { InvoiceNumber = InvoiceNumber.Trim(); ObjectParameter[] parameters = new ObjectParameter[1]; parameters[0] = new ObjectParameter(

pass model from one action to another action in same controller

孤者浪人 提交于 2020-01-03 09:04:03
问题 I am trying to pass my model List< Models.Statement > statementList from one action to another but i am receiving null value in the 2nd controller. Please suggest what is wrong here. Even tried with: return RedirectToAction("WriteInTemplate", new { statementList = statementList }); Please help. public ActionResult SendPdfStatement(string InvoiceNumber) { try { InvoiceNumber = InvoiceNumber.Trim(); ObjectParameter[] parameters = new ObjectParameter[1]; parameters[0] = new ObjectParameter(

Update JavaFX scene graph from a Thread

泪湿孤枕 提交于 2020-01-03 04:24:50
问题 I need to update my GUI based on client input. Calling my controller class method, from the background task works. But it can't update the GUI, because it is not the JavaFX application thread..please help. I tried many of the related Q & A, but I am still confused. Should I use Platform. runLater or Task ? Here's my class where I create an instance of controller class public class FactoryClass { public static Controller_Gui1 createGUI() { FXMLLoader fxLoader = new FXMLLoader(); fxLoader

Decoupling the model and input checking

一个人想着一个人 提交于 2020-01-03 03:39:27
问题 Is it a good practise to decouple input checking from a model and have it handled elsewhere, say by a controller? If so, how could this be done from an MVC or DDD standpoint? 回答1: It is a good practice to perform UI validation. E.g. if Your domain object expects date time, it is correct if UI part of application ensures it will receive from user correct string, will parse it to date time and pass it to domain object. Bad example: UI part validates if bank account has enough money for transfer