这是我到目前为止所做的:
请参阅此处的代码:http://pastebin.com/pxUpUvv6
请注意,给定的代码只是一个示例,因此控制器,模型,视图尚未到位.此外,它可能是错误的 - 如未经测试 - 但现在无关紧要.
::call_model(),其中包括来自core/models /的相应模型,然后从相应的模型类调用我们使用的相同方法.::call_view()',其中包括core/views /的相应视图.对应的控制器,模型,视图的示例:
Controller_Products::list()在核心/控制器/ Controller_Products.phpModel_Products::list()为核心/模型/ Model_Products.php实际上,我觉得这个结构有点不舒服.Dunno,它似乎远非可扩展,可模糊......
core{, /controllers, /models/, …我正在研究自己的MVC框架.下面是我到目前为止的示例控制器.
我有办法将模型加载到我的控制器中,也可以查看文件.
我想为我的网站提供不同的模板选项.我的模板只是一个页面布局,它将从我的控制器创建的视图插入到模板文件的中间.
/**
* Example Controller
*/
class User_Controller extends Core_Controller {
// domain.com/user/id-53463463
function profile($userId)
{
// load a Model
$this->loadModel('profile');
//GET data from a Model
$profileData = $this->profile_model->getProfile($userId);
// load view file and pass the Model data into it
$this->view->load('userProfile', $profileData);
}
}
Run Code Online (Sandbox Code Playgroud)
这是模板文件的基本概念......
DefaultLayout.php
<!doctype html>
<html lang="en">
<head>
</head>
<body>
Is the controller has data set for the sidebar variable, then we will load the sidebar and the content
<?php if( ! empty($sidebar)) { ?> …Run Code Online (Sandbox Code Playgroud) 我不知道如何处理一个简单的guice示例.阅读完文档后,我完成了以下工作:
GuiceServletContextListener,并将该侦听器添加到web.xml中serve("*.jsp").with(IndexController.class);在配置servlet中在我完成之后如何使用依赖注入?假设我有一个index.jsp,IndexController.class(servlet),以及两个名为Person和Order with Person的类,具体取决于Order.如何通过guice将Order依赖注入到Person构造函数中,在我这样做之后,我需要返回说这个人的命令列表回到控制器?我过去使用过Ninject和ASP.NET MVC,这很简单,但我对如何用Guice实现最简单的DI示例感到很困惑.谢谢.
我正在使用远程form_for进行show动作,以根据此表单传递的参数检索内容.
= form_tag modelname_path(@modelname), :id=>"select_content_form", :remote => true, :method => 'get' do
= text_field_tag :content_type, params[:content_type], :id=>"select_content_type"
= submit_tag "submit", :name => nil, :id=>"select_content_submit"
Run Code Online (Sandbox Code Playgroud)
我改变控制器中的内容如下:
# Default params to "type1" for initial load
if params[:content_type]
@content_type = params[:content_type];
else
@content_type = "type1"
end
case @content_type
when "type1"
# get the content
@model_content = ...
when "type1"
# get the content
@model_content = ...
Run Code Online (Sandbox Code Playgroud)
我的问题是,上述方法是否是我们唯一可以为params设置默认值的方法,还是我们能够以更好的方式进行.这有效,但我想知道这是否是正确的方法.
更新 根据下面的建议,我使用以下内容并在defaults.merge行上出错:
defaults = {:content_type=>"type1"}
params = defaults.merge(params)
@content_type = params[:content_type]
Run Code Online (Sandbox Code Playgroud) 首先,我是RoR的新手,所以答案可能很明显,在这种情况下我道歉.我环顾四周,找不到任何有用的东西.
我正试图在我的应用程序的每个网页的标题上都有一个搜索表单,它将搜索我所有"桶"的名称.这是相关代码:
在app/views/layouts/_header.html.erb中(在导航栏中):
<% search_form_for @q do |f| %>
<%= f.label :name_cont %>
<%= f.text_field :name_cont %>
<%= f.submit %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
在app/controllers/buckets_controller.rb中:
def index
unless params[:q].blank?
@q = Bucket.search(params[:q])
@buckets = @q.result.paginate(:page => params[:page])
else
@buckets = Bucket.find(:all, :limit => 5).paginate(:page => params[:page])
end
end
Run Code Online (Sandbox Code Playgroud)
我理解最后一部分并不是那么好:我想要做的就是如果我只是访问存储桶索引页面(而不是通过搜索),我会显示最近创建的5个存储桶.当我在标题表单中搜索某些内容时,我会访问索引页面,但只显示搜索到的内容.(处理它的更好方法是将搜索页面与索引页面分开吗?)
我发现这个问题几乎完全相同,但是@q如果每个页面都有表格,我仍然不知道如何处理- 当然我不必改变每个控制器的每一个动作?
提前抱歉,因为我的愚蠢,我的愚蠢!
model-view-controller ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 ransack
该应用程序正在使用express 3.以下是从数据库中获取数据的路径的准系统示例:
var Post = mongoose.model('Post')
app.get('post/:id/loompas', function(req, res) {
Post.getLoompas(function(err, data){
res.render('x', data)
})
})
Run Code Online (Sandbox Code Playgroud)
凡Posts.getSomeData被定义为实例方法中/models/post.js,有时访问外部的API:
PostSchema.method('getLoompas', function(callback){
var post = this
API.get('y', function(x){
this.save(x)
callback(x)
})
})
Run Code Online (Sandbox Code Playgroud)
这开始闻起来,看起来并不像Schema定义那样.方法的集合可能会变得非常大.
建议采用哪些设计模式来区分这些问题并避免使用极其胖的模型?外部API调用的服务层?有什么有趣的解决方案吗?
我试图在一个视图中使用两个模型,并使用它们两个模板.我和Marionette一起工作.这是我初始化视图:
main_app_layout.header.show(new APP.Views.HeaderView({
model: oneModel,
model2 : twoModel}
));
Run Code Online (Sandbox Code Playgroud)
这是我的观点:
APP.Views.HeaderView = Backbone.Marionette.ItemView.extend({
template : '#view_template',
className: 'container',
initialize: function() {
//This correctly logs the second model
console.log(this.options.model2);
}
});
Run Code Online (Sandbox Code Playgroud)
这是模板:
<script id="view_template" type="text/template">
<p>{{twoModel_label}} {{oneModel_data}}</p>
<p>{{twoModel_label2}} {{oneModel_data2}}</p>
</script>
Run Code Online (Sandbox Code Playgroud)
它使用oneModel数据正确呈现所有内容,但不会呈现第二个,即使它正确记录它.我正在使用胡子作为我的模板语言.
有人可以帮忙吗?
我有一个控制器,一个带有孩子的孩子可以看到很多孩子的视图.示例:JPanel中的JPanels,其中包含用于控制器传递给模型的按钮和字段.
我正在做的当前方式是在视图中实例化"控制器",它们具有动作侦听器并访问我的模型,这些模型是单例.这工作 - 但它绝对不是MVC.
所以问题是 - 我该怎么办?
是从控制器菊花链的唯一方法:mainview.getSubView().getSubView().getSubView().setActionListener(new AL()); 和:mainview.getSubView().getSubView().getSubView().getSomeTextFieldText();
这似乎非常不切实际[我看不出这种方法的好处]
任何提示或指导都会有所帮助.我看到的没有教程解释了带有子视图的MVC.
在旁注 - 我知道我应该让视图和模型使用observable/observer - 但即使是那些我在设置动作监听器时遇到问题.
我试图在Slim中使用控制器但是不断收到错误
PHP Catchable致命错误:传递给
TopPageController :: __ construct()的参数1 必须是ContainerInterface的一个
实例,Slim\Container的实例给出
我的index.php
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
require 'settings.php';
spl_autoload_register(function ($classname) {
require ("../classes/" . $classname . ".php");
});
$app = new \Slim\App(["settings" => $config]);
$app->get('/', function (Request $request, Response $response) {
$response->getBody()->write("Welcome");
return $response;
});
$app->get('/method1', '\TopPageController:method1');
$app->run();
?>
Run Code Online (Sandbox Code Playgroud)
我的TopPageController.php
<?php
class TopPageController {
protected $ci;
//Constructor
public function __construct(ContainerInterface $ci) {
$this->ci = $ci;
}
public function method1($request, $response, $args) {
//your code
//to …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的mvc应用程序中使用Net Core来实现安全策略.我读过的文章说我需要安装DependencyInjection,我在VS 2017中通过NuGet进行.我收到以下错误:
无法安装包'Microsoft.Extensions.DependencyInjection.Abstractions 2.0.0'.您正在尝试将此软件包安装到以".NETFramework,Version = v4.5.2"为目标的项目中,但该软件包不包含任何与该框架兼容的程序集引用或内容文件.
这个版本对.net 4.5.2来说太新了吗?我应该使用什么版本?
php ×3
java ×2
asp.net-core ×1
backbone.js ×1
c# ×1
guice ×1
javascript ×1
marionette ×1
mongoose ×1
node.js ×1
parameters ×1
ransack ×1
slim ×1
templates ×1