SitePoint Sponsor |
|
User Tag List
Results 26 to 50 of 72
Thread: [MVC] Implementation issues
-
May 18, 2005, 12:35 #26
- Join Date
- Oct 2004
- Posts
- 88
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by 33degrees:
What exactly do you mean by 'figure out'? I'd say that a model is generally picked based, in some way, on the request, which makes it the controller's domain.
Details here
-
May 18, 2005, 12:53 #27
- Join Date
- May 2003
- Location
- London, On.
- Posts
- 1,127
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Skimmed some posts, as I'm not really up-to-snuff on all the latest Pattern Terminology.
It took a while for me to get everything working seemlessly, but thus far it works well and haven't encountered any unsurmountable snags.
Here's an overview of what I do, and it works. Not sure if it falls into any given setup as described above.
- Front Controller (index.php) receives all requests.
- Front Controller performs pre-filters.
- Front Controller chooses and creates Application Controller based on request.
- Application Controller runs pre-filters.
- Application Controller chooses and created a Data Source.
- Application Controller chooses and creates a Model, and passes in the Data Source and the request.
- Model returns XML to Application Controller.
- Application Controller chooses and creates View, based on request, and passes XML to it.
- View loads necessary XSL files, performs XSLT and outputs results.
- Application Controller runs post-filters and tidies up.
- Front Controller runs post filters and tidies up.
-
May 18, 2005, 13:01 #28
- Join Date
- Oct 2001
- Posts
- 656
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by 33degrees
-
May 18, 2005, 13:34 #29
- Join Date
- Aug 2004
- Location
- California
- Posts
- 1,672
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I wish we could agree on when to use "fetch." It is commonly used to mean "get data from a database" as opposed to "load" with usually implies "get (all) data from a file" or "read" which implies a stream, whether a file, device or port. Which is pretty confusing and I imagine worse for those for which English is not their first language.
Think of how those words apply to a book, for example. To fetch a book means to go get it and bring it back. To load a book means to put it into something. To read a book means to scan the text inside it.
Maybe "access" or "get" for variables?Christopher
-
May 18, 2005, 13:52 #30
- Join Date
- Mar 2004
- Location
- Sweden
- Posts
- 180
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Very interesting discussion, keep it flowing
Originally Posted by kyberfabrikken
Originally Posted by DarkAngelBGE
Originally Posted by DarkAngelBGE
Also, I wonder why you need the CommandDictionary (storing commands?). Wouldn't it be much more simple to just fetch the Command from the filesystem. For instance like this:
PHP Code:function getCommand ($commandName)
{
$file = '/commands/' . $commandName . 'Command.class.php';
require_once($file);
$class = $commandName . 'Command';
}
-
May 18, 2005, 14:26 #31
- Join Date
- May 2003
- Location
- Berlin, Germany
- Posts
- 1,829
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
@Overrunner: About the several Actions. Why would this be inflexible? You just create an Action object and pass it to an existing Action object, like
PHP Code:$action1->addChildAction($action2);
Yes, my command is as of now more or less only a controller, since it does not do much more than holding a controller. Might need it for more stuff later though.
CommandDic is simply my way of having an ActionMap which I can populate in different ways depending on whether I deal with the AdminPanel or not. It really is only for programming closer to the problem as of now.
-
May 18, 2005, 14:45 #32
- Join Date
- Sep 2003
- Location
- Glasgow
- Posts
- 1,690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I'm getting a bit behind in this topic but...
Originally Posted by DarkAngelBGE
-
May 18, 2005, 15:01 #33
- Join Date
- May 2003
- Location
- Berlin, Germany
- Posts
- 1,829
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
@Overrunner: Actuallly I have refactored it all now. I just pass a Collection of Controller identifiers and the request to the fc, which tries to map the request to the list, loads a controller file dynamically and executes the controller. Thanks for your notification, I was coding blindfolded.
So for now I got rid of CommandDictionary and Command. At my house a Controller is an Action. Weird, but ok yes?
-
May 18, 2005, 15:30 #34
- Join Date
- Sep 2003
- Location
- Glasgow
- Posts
- 1,690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
-
May 18, 2005, 18:16 #35
- Join Date
- Aug 2004
- Location
- California
- Posts
- 1,672
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I think McGruff's explaination is an excellent one. Controllers probably got their name from association with electro-mechanical controllers. Those controllers tell a device to do something (e.g. a valve to open/close) but are neither the device itself (i.e. the valve), nor the mechanism the controller talks to (i.e. motor and gearbox).
Christopher
-
May 18, 2005, 20:04 #36
Originally Posted by Captain Proton
Here's an overview of what I do, and it works. Not sure if it falls into any given setup as described above.
Originally Posted by Viflux
Also, if you need to display data from, say, 100 rows in your database, doesn't that make for a big XML file to have in memory? Still, I find the idea of doing view using XSL very interesting...
-
May 18, 2005, 20:18 #37
Originally Posted by DarkAngelBGE
In the controller
PHP Code:<?php
/**
* Author: Tim Koschützki
* Date Started: April 7th, 2005
*/
require_once('IssueController.php');
class DeleteIssueController extends IssueController {
public function DeleteIssueController (&$dao,$input=null) {
parent::__construct($dao, $input);
}
public function execute() {
if(!isset($this->input['submit'])) {
require_once(ISSUE_VIEW_PATH.'DeleteIssueItemView.php');
$this->model->listIssue($this->input['id']);
$this->setView(new DeleteIssueItemView($this->model, $this->lang));
} else {
$success=0;
if($this->model->deleteIssue($this->input['id'])) {
$success=1;
}
require_once(ISSUE_VIEW_PATH.'IssueItemHasBeenDeletedView.php');
$this->setView(new IssueItemHasBeenDeletedView($this->model, $this->lang, $success));
}
}
}
?>
PHP Code:<?php
/**
* Author: Tim Koschützki
* Date Started: April 7th, 2005
*/
require_once(LIB_PATH.'Template.php');
require_once('IssueView.php');
class DeleteIssueView extends IssueView {
//! A constructor.
/**
* Constucts a new IssueItemView object
* @param $model an instance of the IssueModel class
*/
public function __construct(&$model,&$lang) {
parent::__construct(&$model,&$lang);
}
//! A manipulator
/**
* Renders a single issue
* @return void
*/
private function deleteIssueItem() {
$tmp =& new Template('delete_issue_confirm');
$tmp->setValue('{ISSUE_ID}',$this->model->ID);
$tmp->setValue('{ISSUE_TITLE}' => $issue['title']);
$tmp->parse();
return $issueTemplate->fetch();
}
public function display () {
$tmp =& new Template('standard');
$tmp->setValue('{HEADER}',$this->header());
$tmp->setValue('{FOOTER}',$this->footer());
$tmp->setValue('{NAVBAR}',$this->navbar());
$tmp->setValue('{CONTENT}',$this->deleteIssueItem());
$tmp->parse();
return $tmp->fetch();
}
}
?>
Also, since the model already contains the data the ID of the item to be deleted, there's no longer any need for the controller to pass it seperately and for the view to store it.
Other than that, it looks good to me!
-
May 18, 2005, 20:32 #38
Originally Posted by kyberfabrikken
Originally Posted by atu
-
May 18, 2005, 21:36 #39
- Join Date
- Sep 2003
- Location
- Glasgow
- Posts
- 1,690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by 33degrees
- Front Controller (index.php) receives all requests.
- Front Controller performs pre-filters.
- Front Controller chooses and creates Application Controller based on request.
- Application Controller runs pre-filters.
- Application Controller chooses and created a Data Source.
- Application Controller chooses and creates a Model, and passes in the Data Source and the request.
- Model returns XML to Application Controller.
- Application Controller chooses and creates View, based on request, and passes XML to it.
- View loads necessary XSL files, performs XSLT and outputs results.
- Application Controller runs post-filters and tidies up.
- Front Controller runs post filters and tidies up.
Front Controller (index.php) receives all requests.
Front Controller performs pre-filters.
Front Controller chooses and creates Application Controller based on request.
Application Controller selects a view and tells it to update itself
Front Controller runs post filters and tidies up.
Last edited by McGruff; May 18, 2005 at 22:21.
-
May 18, 2005, 21:45 #40
- Join Date
- Sep 2003
- Location
- Glasgow
- Posts
- 1,690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Captain Proton
-
May 18, 2005, 22:09 #41
- Join Date
- May 2003
- Location
- Berlin, Germany
- Posts
- 1,829
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks Degrees for your code sample. What do the others think of what Degrees posted?
-
May 18, 2005, 23:07 #42
- Join Date
- May 2003
- Location
- Berlin, Germany
- Posts
- 1,829
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hrm actually I dunno. I think this is not really important whether the controller tells the model to select an issue or the view tells the model to select the issue. This code does not manipulate the model in any way, the model is still independant of the presentation. I agree though that everything that manipulates the model should be in the controller. That's what Fowler's been saying as well.
-
May 19, 2005, 00:17 #43
- Join Date
- Oct 2004
- Posts
- 88
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by McGruff
This (SMART) may or may not be a good design but it's certainly not MVC.
IMO following 100% the mvc definition results in overcomplicated design.
-
May 19, 2005, 00:25 #44
- Join Date
- May 2003
- Location
- Berlin, Germany
- Posts
- 1,829
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by atu
-
May 19, 2005, 00:44 #45
- Join Date
- Oct 2004
- Posts
- 88
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by DarkAngelBGE
Which one do you regard as the MVC definition?
-
May 19, 2005, 01:41 #46
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by overrunner
It allows me to combine different strategies for mapping the request ... actualy it makes it possible to use TemplateView for some pages and DispatcherView for others.
Originally Posted by 33degrees
Originally Posted by 33degrees
This way you won't have big xml-documents in memory, since the ViewHelper will just fetch what is needed.
-
May 19, 2005, 02:03 #47
- Join Date
- May 2003
- Location
- Berlin, Germany
- Posts
- 1,829
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
Anyone willing to elaborate on whether the controller should use the model to say fetch(!, not manipulate) some data from the datasource and then pass the model to the view or whether the view should use the model to fetch the data. Does it matter much? WHat are the Pros and Cons?
Too bad Fowler does not say anything about that in PoEAA. He simply states that the controller is responsible for manipulating the model. That's alright. But should fetching some data from the datasource also be considered as manipulating the model? Sounds like it does it not?
-
May 19, 2005, 03:27 #48
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by DarkAngelBGE
Originally Posted by DarkAngelBGE
Originally Posted by DarkAngelBGE
-
May 19, 2005, 04:30 #49
- Join Date
- May 2003
- Location
- London, On.
- Posts
- 1,127
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by 33degrees
I don't actually create an XML file, I just pass around XML stored in a variable. No different than storing all your content in a variable, in an unorganized state.
-
May 19, 2005, 04:42 #50
- Join Date
- May 2003
- Location
- Berlin, Germany
- Posts
- 1,829
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
Maybe I did not understand what you meant though.
Bookmarks