天道酬勤,学无止境

model-view-controller

MVC 在视图之间传输数据(MVC Transfer Data Between Views)

问题 我刚开始学习 MVC 并试图了解它是如何工作的。 我不想将用户发送到所有编辑、插入和列表操作的不同视图。 在我的示例应用程序中,一个视图包含一个项目列表,在列表下方有一个表单(用于插入新项目),其操作为“{Controller}/Create”,但没有创建视图。 当用户插入一个新项目时,它使用 httpverb post 发布到 Create 操作并创建项目并使用 RedirectToAction 方法返回到 List 操作。 但是我无法以这种样式向用户显示任何消息(错误、信息等),因为我无法在创建操作和列表操作之间传递数据。 我怎样才能做到这一点? 回答1 您需要使用 Post Redirect Get PRG 模式。 请阅读Kazi Manzur Ra​​shid在这篇博文中使用 PRG 模式进行数据修改部分。 http://weblogs.asp.net/rashid/archive/2009/04/01/asp-net-mvc-best-practices-part-1.aspx 这种方法使用TempData来维护重定向之间的ModelState数据。 [HttpPost, ValidateAntiForgeryToken, ExportModelStateToTempData] public ActionResult Create(FormCollection

2021-11-29 19:37:20    分类:技术分享    model-view-controller   view   transfer

file_get_contents() 期望参数 1 是有效路径(file_get_contents() expects parameter 1 to be a valid path)

问题 我的图片已成功上传到图片/新闻。 我现在想将该图像保存在数据库中。 但它不断给我上述错误。 我的模型查询是正确的,因为我用它来插入其他数据并且它有效。 用户单击提交后,如何将图像保存到数据库中? 我的控制器: function news() { $config = array( 'upload_path' => "./images/news", 'allowed_types' => "gif|jpg|png|jpeg|JPG", 'overwrite' =>False, 'max_size' => "2048000", 'max_height' => "768", 'max_width' => "1024" ); $this->load->library('upload', $config); $this->load->helper(array('form', 'url')); if($this->upload->do_upload()) { $data = array('upload_data' => $this->upload->data()); $this->load->view('manage_news',$data); } else { $message2 = "Please choose another file type. gif,jpg,png,jpeg

2021-11-29 18:49:54    分类:技术分享    image   codeigniter   model-view-controller   controller   file-get-contents

从 web.config 读取成员资格部分(Reading membership section from web.config)

问题 我已经创建了一个自定义 MembershipProvider 类,到目前为止一切顺利,但是,我不确定如何从 web.config 文件中读取配置设置。 我尝试从 Google 和 Stackoverflow 进行搜索,似乎有人也遇到了我的问题并提出了问题,但没有给出答案。 这应该是一件简单的事情,但我在 Web 开发方面很新,所以从 web.config 读取设置对我来说似乎太技术性了。 这是我的设置: <membership defaultProvider="CustomMembershipProvider"> <providers> <clear/> <add name="CustomMembershipProvider" type="Test.Models.CustomMembershipProvider,Test" passwordFormat="Hashed" connectionStringName="ApplicationServices" minRequiredPasswordLength="8" minRequiredNonalphanumericCharacters="0" maxInvalidPasswordAttempts="5" enablePasswordReset="false" enablePasswordRetrieval="false"

2021-11-29 17:50:57    分类:技术分享    c#   model-view-controller   membership   web-config

如何使用私人提交隐藏个人资料?(How to use private submit to hide from profile?)

问题 当用户通过private提交时,我们如何将提交的信息从提要中隐藏,其他用户可以在他的公开个人资料中看到它? <%= button_tag(type: 'submit', class: "btn") do %> ... <%= button_tag(type: 'submit', class: "btn", id: "2", name: 'private') do %> ... 我们把下面的放在控制器中,但是由于私有按钮会有很多不同的_forms,我必须把它放在每个控制器中还是我们可以把它放在应用程序控制器中? if params[:private] # the private action / What do we need to put here? else # normal submit / and here? 我跟着这个铁路广播剧集几乎到了 T 来构建活动提要:http://railscasts.com/episodes/406-public-activity。 这是公开个人资料的代码: 用户控制器.rb def show @user = User.find(params[:id]) @habits = @user.habits @valuations = @user.valuations @accomplished_goals = @user.goals

2021-11-29 04:32:17    分类:技术分享    ruby-on-rails   ruby   model-view-controller   params   railscasts

Binding data on a model for dynamic nested forms in angularjs

I'm generating nested form from a json object say formObject and binding the values in the json object itself. I'm parsing the values recursively and pulling out the actual data say dataObject at submit. I can retrieve the dataObject in a linear form like this one. http://jsfiddle.net/DrQ77/80/. <select ng-model="Answers[question.Name]" ng-options="option for option in question.Options"> In contrast to the above, http://jsfiddle.net/DrQ77/92/ has some recursion. I've renamed question to element for it to represent both questions & sections. Every section can have multiple questions & again

2021-11-29 03:16:24    分类:问答    javascript   angularjs   model-view-controller

Codeigniter - How to get url variable value inside contoller function?

I have URL like this: http://localhost/sitename/some-post-title/code=24639204963309423 Now I have one findUser function in my controller file public function findUser() { // I have tried with $_GET['code'] } and I am trying to get code variable value inside this function. I have tried with $_GET['code'] but did not worked. Any Idea how to get value inside controller function? Thanks.

2021-11-29 02:44:23    分类:问答    php   codeigniter   model-view-controller   codeigniter-2

MVC or MVP? Which design pattern makes the most sense?

Which do you guys prefer? I've been looking into both and there definitely seems to be some inconsistency in what people call them. I will try and jot down what the differences are and you can correct me if I'm wrong. MVC Model holds references to it's own observers (Views), on updates to the model it notifies observers. Views pass all events and messages to the Controller. Views update their content when they are notified by the model that a change has occured. View holds a reference to the Controller and to the Model. Controller holds the Model and (sometimes) the Views. The Views will call

2021-11-29 01:52:06    分类:问答    model-view-controller   design-patterns   mvp

Can the MVC Design Pattern / architectural pattern be used in Desktop Application Development?

I've just learned what ASP.NET MVC is and I'm wondering if the pattern is ever used in Windows Desktop application development? I'm specifically looking at potentially trying to use it in a Desktop .NET application. Please forgive me if this question is way out in left field in terms of how MVC is suppose to be used. I'm still trying to wrap my head around the details of it.

2021-11-29 01:43:29    分类:问答    asp.net-mvc   winforms   model-view-controller   desktop-application

在 iPhone 编程中传递的 ViewController 参数......如何?(Inter-ViewController parameters passing in iPhone programming... how to?)

问题 我读过:iPhone:如何在 Tabbar 应用程序中的多个 Viewcontrollers 之间传递数据,并想知道它们之间有什么区别 [[UIApplication sharedApplicaton] delegate] 和 extern struct* global ? 从概念上讲,我不明白 [[UIApplication sharedAppplicaton] 委托] 不是一个全球性的东西。 事实上,现在使用脏的全局结构 * 时,这会减少内疚感。 我很快就要开始一个新项目。 所以,我用这个休息来问一个问题:是否有任何最佳实践代码示例来说明如何在两个 ViewController 之间(但不是全局)共享数据? 让我举个例子: 这是一个游戏有一个 NSString *name 来存储玩家的名字有一个 NSInteger 分数来存储玩家的当前分数 GameMainViewController 将更新并显示分数在 GameSettingViewController 中,有一个用于编辑名称的文本字段和一个用于重置分数的按钮 GameMainViewController 负责设置默认名称(如果为零),退出时保存名称和分数,启动时加载两者(如果存在) 所以 我应该把“名字”和“分数”放在哪里? ViewControllers 如何访问和更改值 谢谢! 回答1 您可以在

2021-11-28 23:55:36    分类:技术分享    iphone   model-view-controller   viewcontroller

Cappuccino, Django, AJAX, and fitting it all together - review my architecture!

I'm trying to get my head around Cappuccino. I'd like my StackOverview peers to review the architecture below and see if it makes sense - the aim is to utilize the unique benefits of Django and Cappuccino without doubling up where the technologies overlap... When the web browser requests a 'friendly' URL (eg, /, /articles, etc): DJango's urls.py matches this to a view. The view, rather than doing DJangos typical work of filling in a template with the locals dict, returns the small 'stub' HTML used in a Cappuccino app directly. The client receives the Cappuccino HTML The client requests the

2021-11-28 22:45:22    分类:问答    ajax   django   model-view-controller   json   cappuccino