标签: controller

使用Zend中的BaseController扩展IndexController

我正在尝试使用全局基本控制器来扩展我的控制器:

class BaseController extends Zend_Controller_Action {
 // common controller actions
    public function listAction() {
        // do stuff
    }
}

class IndexController extends BaseController {
 // index controller specific actions
}

class LoginController extends BaseController {
 // login controller specific actions
}
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:PHP致命错误:第3行的/var/www/Zend/project/application/controllers/IndexController.php中找不到类'BaseController'

关于如何让Zend"看到"这个控制器的任何想法?

php zend-framework controller class

10
推荐指数
2
解决办法
7793
查看次数

如何通过rspec测试控制器中更新的会话变量

我正在尝试使用rspec编写测试,测试会话变量是否已正确更改:

这是我要测试的GamesController的一部分:

def change_player
  if session[:player] == 0
    session[:player] = 1
  else
    session[:player] = 0
  end    
end
Run Code Online (Sandbox Code Playgroud)

这是我的game_spec.rb文件:

require "spec_helper"

describe GamesController do
 describe "#change_player" do
   it "should change player to 1" do
     session[:player] = 0

     get :change_player

     assigns(session[:player]).should == 1
   end
 end
end
Run Code Online (Sandbox Code Playgroud)

这是我运行测试时收到的错误消息:

Failures:

  1) GamesController#change_player should set player to 0
     Failure/Error: session[:player] = 0
     NameError:
       undefined local variable or method `session' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x00000103b3b0d8>
     # ./spec/features/game_spec.rb:6:in `block (3 levels) in <top (required)>'

Finished in 0.01709 seconds
1 example, …
Run Code Online (Sandbox Code Playgroud)

controller rspec ruby-on-rails

10
推荐指数
1
解决办法
7876
查看次数

Simple Injector - 没有为此对象定义的无参数构造函数

我有一个新的MVC Web项目,我在MVC和WebApi中使用.我在我的全局文件中使用以下代码设置了Simple Injector(来自nuGet的2.5.2版本)

// Register Injectors
SimpleInjectorConfig.Register();
Run Code Online (Sandbox Code Playgroud)

在我的SimpleInjectorConfig.cs文件中

public class SimpleInjectorConfig
{
    public static void Register() {
        // Create the container as usual.
        Container container = new Container();

        // services
        container.Register<IService, MyService>();

        // data
        container.Register<IRepository, MyRepository>();

        // Register your types, for instance using the RegisterWebApiRequest
        // extension from the integration package:
        container.RegisterMvcControllers(
            System.Reflection.Assembly.GetExecutingAssembly());

        container.RegisterMvcAttributeFilterProvider();

        // This is an extension method from the integration package.
        container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

        // verify its all ok
        container.Verify();

        // add dependency
        GlobalConfiguration.Configuration.DependencyResolver = 
            new SimpleInjectorWebApiDependencyResolver(container);
    }
} …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc dependency-injection controller simple-injector

10
推荐指数
1
解决办法
8637
查看次数

访问ASP.NET MVC应用程序中的控制器/操作列表

我们知道在幕后,ASP.NET MVC框架将使用反射来确定哪些控制器/操作可以执行,基于哪些类派生自System.Web.Mvc.Controller哪些类,哪些方法返回一个ActionResult对象.

对我的问题 - 是否可以从我的MVC应用程序中访问此控制器/操作列表?

(我可以通过在当前程序集上使用反射来自己完成,但如果列表已经由ASP.NET MVC构建,我宁愿重新使用这些工作,而不是自己重新发明轮子.)

reflection asp.net-mvc action controller

9
推荐指数
2
解决办法
3914
查看次数

在模型验证失败的Rails中哪里呈现注释控制器?

我在我的rails应用程序中有一个简单的视频模型has_many评论.我在视频的节目页面上显示这些评论.当我提交表格时,一切正常; 但是,如果评论模型上存在验证错误,那么我的系统就会爆炸.如果评论模型上存在验证错误,我只想再次渲染视频的显示页面,并显示验证错误样式.如何在我的创建操作中执行此操作?非常感谢!

class CommentsController < ApplicationController
  def create
    @video = Video.find(params[:video_id])
    @comment = @video.comments.build(params[:comment])
    if @comment.save
      redirect_to @video, :notice => 'Thanks for posting your comments.'
    else
      render # what? What do I render in order to show the video page's show action with the validation error styling showing? Please help!
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

controller ruby-on-rails render

9
推荐指数
2
解决办法
3030
查看次数

RSpec - @controller是零

我有一个非常基本的RoR网站,需要开始为它编写一些RSpec测试.我有一个"关于"页面,不需要登录用户,并由我的PagesController控制.从浏览器运行时,about页面效果很好.我试图简单地尝试测试它,就像在RoR教程中那样.

我正在使用Rails 3,RSpec 2.7.0,Windows

pages_controller.rb:

class PagesController < ApplicationController
    def about
    end
end
Run Code Online (Sandbox Code Playgroud)

pages_controller_spec.rb:

require 'spec_helper'
describe "PagesController" do
    describe "GET 'about'" do
        render_views
        it "should be successful" do
            get 'about'
            response.should be_success
        end
    end
end
Run Code Online (Sandbox Code Playgroud)

对于它的价值,这是我的spec_helper.rb:

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
    config.include RSpec::Rails::ControllerExampleGroup
    config.mock_with :rspec
    config.fixture_path = "#{::Rails.root}/spec/fixtures"
    config.use_transactional_fixtures = true
    config.infer_base_class_for_anonymous_controllers = false
end
Run Code Online (Sandbox Code Playgroud)

但是当我进行测试时,我得到:

Failures:

1) PagesController GET 'about' should be successful
  Failure/Error: get 'about' …
Run Code Online (Sandbox Code Playgroud)

controller rspec ruby-on-rails

9
推荐指数
1
解决办法
6218
查看次数

子控制器未注入主控制器

我有一个BorderPane(与MainController相关联),BorderPane的FXML用于在BorderPane <fx:include>的底部区域包含一个Label(带有控制器StatusBarController).不幸的是,StatusBarController没有注入到MainController类实例中,我无法理解为什么.

main.fxml:包含状态栏的BorderPane

<fx:root type="javafx.scene.layout.BorderPane" fx:id="borderPane" xmlns:fx="http://javafx.com/fxml" fx:controller="com.example.controllers.MainController">
  <bottom>
    <fx:include source="statusbar.fxml" />
  </bottom>
</fx:root>
Run Code Online (Sandbox Code Playgroud)

statusbar.fxml:Label及其关联的控制器

<Label fx:id="statusbar" text="A label simulating a status bar" xmlns:fx="http://javafx.com/fxml" fx:controller="com.example.controllers.StatusBarController" />
Run Code Online (Sandbox Code Playgroud)

带有StatusBarController字段的MainController:

public class MainController
{
    @FXML
    private StatusBarController statusbarController; // PROBLEM HERE: I would expect the StatusBarController to be injected but this does not happen!


    // Implementing Initializable Interface no longer required on JavaFX 2.2 according to
    // http://docs.oracle.com/javafx/2/fxml_get_started/whats_new2.htm
    // (I also tested this, the initialize() method is being called)
    @SuppressWarnings("unused") // only …
Run Code Online (Sandbox Code Playgroud)

controller code-injection javafx-2 fxml

9
推荐指数
1
解决办法
7375
查看次数

如何在prestashop中生成模块控制器的链接?

在prestashop中生成模块控制器链接的确切方法是什么?另外,应该如何真正命名控制器的类以及url params应该如何镜像?

controller module hyperlink prestashop

9
推荐指数
1
解决办法
3万
查看次数

如何为所有控制器编写动作过滤器

这是一个示例动作过滤器.我们知道当我们编写一个动作过滤器时,我们需要用这样的属性来装饰控制器,以便将它用于任何控制器.

我想知道是否有任何方法可以编写一个动作过滤器,它将适用于所有控制器,我不需要使用动作过滤器属性来装饰所有控制器.有任何想法吗?

[LogActionFilter]
public class HomeController : Controller
{}

public class LogActionFilter : ActionFilterAttribute

     {
          public override void OnActionExecuting(ActionExecutingContext filterContext)
          {
               Log("OnActionExecuting", filterContext.RouteData);       
          }

          public override void OnActionExecuted(ActionExecutedContext filterContext)
          {
               Log("OnActionExecuted", filterContext.RouteData);       
          }

          private void Log(string methodName, RouteData routeData)
          {
               var controllerName = routeData.Values["controller"];
               var actionName = routeData.Values["action"];
               var message = String.Format("{0} controller:{1} action:{2}", methodName, controllerName, actionName);
               Debug.WriteLine(message, "Action Filter Log");
          }

     }
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc attributes controller action-filter

9
推荐指数
1
解决办法
1万
查看次数

SpringBoot @RestController,找到了不明确的映射

嗨,我的Sample中有一个简单的RestController:

@RestController
public class PersonController {

    @RequestMapping(name = "/getName", method = GET)
    public String getName() {
        return "MyName";
    }

    @RequestMapping(name = "/getNumber", method = GET)
    public Double getNumber(){
        return new Double(0.0);
    }
}
Run Code Online (Sandbox Code Playgroud)

我有SampleController用于启动SpringBoot:

@SpringBootApplication
@Controller
public class SampleController {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试运行SampleCotroller时,会发生以下异常:

Caused by: java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'personController' bean method 
public java.lang.Double com.web.communication.PersonController.getNumber()
to {[],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'personController' bean method
public java.lang.String com.web.communication.PersonController.getName() mapped.
Run Code Online (Sandbox Code Playgroud)

问题出在哪里?一个RestController中不能有更多的RequestMappings? …

rest spring controller ambiguous-call spring-boot

9
推荐指数
1
解决办法
6763
查看次数