如果您按照官方Model-Glue文档提供的快速入门指南,请在此处找到:
看起来"模型"是执行应用程序操作的类.在这个例子中,他们创建了一个Translator将一个短语翻译成Pig Latin的类.从这里可以很容易地推断出程序逻辑也应该是"模型",例如数据库操作类和HTML帮助程序.
但是,我最近收到了一个关于我在这里询问有关MVC的问题的答案:
使用MVC,我如何设计视图,以便它不需要知道控制器设置的变量?
在其中一个答案中,提到MVC中的"模型"应该是控制器填充数据的对象,然后将其传递给视图,并且视图将其用作强类型对象来呈现数据.这意味着,对于上面提供的模型胶水例如,应该已经是一个翻译器,一个翻译观点,一PigLatinTranslator类,和Translation看起来像这样的模式:
component Translation
{
var TranslatedPhrase = "";
}
Run Code Online (Sandbox Code Playgroud)
这个控制器会像这样使用它:
component TranslatorController
{
public function Translate(string phrase)
{
var translator = new PigLatinTranslator();
var translation = new Translation();
translation.TranslatedPhrase = translator.Translate(phrase);
event.setValue("translation", translation);
}
}
Run Code Online (Sandbox Code Playgroud)
视图将呈现如下:
<p>Your translated phrase was: #event.getValue("translation").TranslatedPhrase#</p>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,PigLatinTranslator它只是一个驻留在某处的类,不能被视为模型,控制器或视图.
我的问题是,ColdFusion Model-Glue的模型与MVC模型不同吗?或者是快速入门指南,他们提供了一个糟糕的MVC示例,以及我在上面列出的正确方法的代码?或者我完全偏离了所有这一切?
我的Yii应用程序中有一些静态视图.
对我来说,为该视图编写一个空操作似乎毫无意义(我确实需要布局,因为有些小部件是动态的,就像显示用户登录/注销的那些等).
如果可能的话,它是如何完成的?
好的,我有一个RootViewController.m并在那里定义了一个方法:
-(void)doSomethingParent
{
NSLog(@"Parent is doing something after child has asked");
}
Run Code Online (Sandbox Code Playgroud)
然后我添加了一个childViewController.view,如下所示:
if (self.child == nil) {
ChildViewController *cvc = [[ChildViewController alloc]
initWithNibName:nil bundle:nil];
self.child = cvc;
[cvc release];
}
[self.view insertSubview: child.view atIndex:0];
Run Code Online (Sandbox Code Playgroud)
现在,我认为如果我可以从孩子那里调用我的doSomethingParent方法,那将非常有用.所以我想我会这样做:
@implementation ChildViewController
@class RootViewController;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[super doSomethingParent];
}
Run Code Online (Sandbox Code Playgroud)
但是xCode告诉我"找不到-doSomethingParent"......但我把@class放在那里?!不应该找到它吗?我不想导入整个东西,因为我认为@class足以让孩子知道父母有一个名为doSomethingParent的方法...
我会非常感谢任何建议.提前致谢!
iphone model-view-controller cocoa-touch objective-c parent-child
public class CheckMetadataAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
// get model
// get metadata for each model property
// set viewdata if metadata X exists
}
}
Run Code Online (Sandbox Code Playgroud)
老问题是:如何在自定义ModelMetadataProvider中访问ViewData?那是不行的.
我按照rob conery制作的StoreFront MVC应用程序视频tuturial.我注意到Commerce.MVC.Web引用了Commerce.MVC.Data和Commerce.MVC.Services.这是因为Commerce.MVC.Web需要Commerce.MVC.Data,因为其中定义了实体.什么是仅引用Commerce.MVC.Services的更好方法.我是否需要将实体纳入服务?或任何建议?
粗体文本来自Commerce.MVC.Data:
Commerce.MVC.Data
Commerce.MVC.Services- reference the Commerce.MVC.Data
Commerce.MVC.Web - reference both the Commerce.MVC.Data and Commerce.MVC.Services
Run Code Online (Sandbox Code Playgroud)
这里是CatalogController的示例代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Commerce.MVC.Data;
using Commerce.MVC.Services;
namespace Commerce.MVC.Web.Controllers {
public class CatalogController : Controller {
#region .ctor
ICatalogService _catalogService;
public CatalogController(ICatalogService catalogService) {
_catalogService = catalogService;
}
#endregion
#region ViewData
/// <summary>
/// Class used for transferring data to the View
/// </summary>
public class CatalogData {
public CatalogData() { }
public CatalogData(List<Category> categories, …Run Code Online (Sandbox Code Playgroud) 应该何时制作新型号或控制器?是否只有控制器与相应的视图1对1一起使用,并且控制器和模型是这样的?或者,控制器的功能是否与任何特定视图无关?例如,投票,如果所有投票代码都在投票控制器中,或者在具有使用投票的观点的控制器之间传播.似乎投票控制员可能是最好的.
//standard routing
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
//the custom route I added
routes.Add(
new Route("Fish/Image",
new ImageHandlerRouteHandler()
)
);
Run Code Online (Sandbox Code Playgroud)
我认为这会使用我,ImageHandlerRouteHandler但我得到的Fish/Image只是404.
我正在研究遗留项目,将其转换为基于注释的MVC.我在onsubmit方法中注意到很多次,其中遵循以下模式:
public ModelAndView onSubmit(Command command) {
try {
service.doSomeBusinessLogic(command);
}
catch (ServiceException) {
//return one type of model and view here
}
//return another type of model and view here
}
Run Code Online (Sandbox Code Playgroud)
直觉上,这里的异常处理是错误的,但我不确定春天给我的替代解决方案是什么?任何想法或者这不是我想的反模式吗?
是否保证'change:property'事件总是在 'change'事件之前触发?这是一个例子:
MyModel = Backbone.Model.extend({
property1: 'value1',
property2: 'value2'
});
var myModel = new MyModel();
myModel.bind('change:property1', function () { alert("change pty1"); })
.bind('change', function () { alert("change"); })
.bind('change:property2', function () { alert("change pty2"); });
Run Code Online (Sandbox Code Playgroud)
是否保证绑定到'change'的函数最后会被触发?
我在我的应用程序中使用MVC,但差别很小:4层.它包含Model,View,Control和Orchestrator.这是主控制器,并且是一次说哪个视图控制器处于活动状态的控制器.
因此,我必须让我的入口点调用此Orchestrator类,它将创建一个控制器,该控制器将创建将显示的视图.每当视图关闭时,应用程序也必须停止并完成.
但是,我无法在Main.c函数中使用Application.Run,在Program.cs中运行一个不是表单的类.如何实现我希望的架构?
c# ×3
php ×2
architecture ×1
asp.net-mvc ×1
backbone.js ×1
cocoa-touch ×1
codeigniter ×1
coldfusion ×1
coldfusion-9 ×1
iphone ×1
java ×1
javascript ×1
metadata ×1
model-glue ×1
objective-c ×1
parent-child ×1
spring ×1
view ×1
viewdata ×1
winforms ×1
yii ×1