标签: controller

来自ControllerContext的ActionDescriptor

鉴于我只能访问ControllerContext而不是Action____Contexts获取当前正在执行的ActionDescriptor的最佳方式是什么?

到目前为止,我发现的唯一方法是:

new ReflectedControllerDescriptor(context.Controller.GetType())
    .FindAction(context, context.RouteData.GetRequiredString("action"));
Run Code Online (Sandbox Code Playgroud)

这是最佳方法吗?

这个类被命名的事实ReflectedControllerDescriptor让我想知道这个操作是否会付出沉重的代价,因为它会在每个页面请求上执行?与此相关的是此类内部缓存还是我应该实际缓存ReflectedControllerDescriptors?

c# controller controllercontext asp.net-mvc-3

14
推荐指数
1
解决办法
2865
查看次数

来自控制器的Rails验证

有一个联系页面,提供输入姓名,电话,电子邮件和消息,然后发送给管理员的电子邮件.没有理由在DB中存储消息.

题.如何:

  1. 在控制器中使用Rails验证,完全不使用模型,或者

  2. 在模型中使用验证,但没有任何数据库关系

UPD:

模型:

class ContactPageMessage
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming

attr_accessor :name, :telephone, :email, :message
validates :name, :telephone, :email, :message, presence: true
validates :email, email_format: { :message => "???????? ?????? E-mail ??????"}

def initialize(attributes = {})
    attributes.each do |name, value|
      send("#{name}=", value)
    end
end

def persisted?
  false
end
end
Run Code Online (Sandbox Code Playgroud)

控制器:

def sendmessage
cpm = ContactPageMessage.new()
if cpm.valid?
    @settings = Setting.first
    if !@settings
        redirect_to contacts_path, :alert => "Fail"
    end
    if ContactPageMessage.received(params).deliver
        redirect_to contacts_path, :notice => "Success"
    else …
Run Code Online (Sandbox Code Playgroud)

validation controller model ruby-on-rails

14
推荐指数
2
解决办法
2万
查看次数

在AngularJS中使用.controller方法时无法访问$ location

我在表单上使用ng-submit将数据推送到Firebase,一切都按预期工作.我想做的是同时改变观点.在提交按钮本身我有ng-click设置来使用$ location执行一个函数.如果我将changeView函数放在.controller方法中,我就无法使用$ location(具体来说,它说 - "错误:'undefined'不是一个对象(评估'$ location.path')").任何帮助都是超级的.

// This doesn't work and throws the error
myApp.controller('CtrlName', ['$scope', 'angularFireCollection',
    function($scope, angularFireCollection, $location) {

         $scope.changeView = function(view) {
             $location.path(view);
         }

    }
]);



// This works as expected, but I'm name spacing my functions globally and I will have to change how I'm accessing my Firebase, which isn't really desired.   
function CtrlName($scope, angularFireCollection, $location) {

    $scope.changeView = function(view) {
        $location.path(view);
    }

}
Run Code Online (Sandbox Code Playgroud)

这是我的模板:

<form role="form" ng-submit="tactics.add(tactic)">
    <div class="form-group">
        <label>Select Method</label>
            <select class="form-control" ng-model="tactic.type">
                <option>Email</option> …
Run Code Online (Sandbox Code Playgroud)

controller angularjs firebase angularfire

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

将XInput调用转换为MAC OS X上的DirectInput调用(从PS3模拟x360控制器)

很多游戏都在使用x360控制器,但没有正确映射到PS3 DS3控制器......

MotionInJoy使用"模拟360控制器"进行清理,但它仅适用于PC.还有另一个仅限PC的项目:x360ce:https://code.google.com/p/x360ce/

这是一个问题:mac os x有什么解决方案吗?如果没有,为什么!

macos controller ps3 directinput xinput

14
推荐指数
1
解决办法
2612
查看次数

我们可以将多个参数传递给控制器​​中的功能吗?

我正在使用codeigniter.我有一个视图文件,我选择一个员工并使用表单操作发送id并选择员工可以执行的服务并将它们存储在一个表中.我已经插入了员工ID和服务ID.现在我需要插入员工姓名.
我的控制器文件是

 class admin_service_limitation extends CI_Controller{
    public function services()
        {
    $id = $this->session->userdata('employee');
    $id_array = $this->input->post("services");
//I need to get the employee name here and store them in a table along with employee id and service id
    for ($i = 0; $i < count($id_array); $i++) {
        if(isset($id_array[$i])&& $id_array[$i]!=""){
        $data_to_store = array('employee_id' => $id, 'service_id' => $id_array[$i]);
        $this->add_service_model->save($data_to_store);
       }
    }
    $data['addservice'] = $this->add_service_model->get_addservices();
    $data['main_content'] = 'admin/service_limitation/newview';
    $this->load->view('includes/template', $data);

    }
Run Code Online (Sandbox Code Playgroud)

在这里我得到了员工ID和服务ID并将它们存储在一个table.That表包含像场employee_id,employee_name和service_id.
我的模型文件:

class sample_model extends CI_Model{ …
Run Code Online (Sandbox Code Playgroud)

php mysql arguments controller codeigniter

14
推荐指数
1
解决办法
2273
查看次数

在rails控制器中,如何防止双重提交(当用户双提交按钮或按两次输入时)?

好吧,一切都在标题中,但我会解释一下:-)

我的rails应用程序包含许多表单(Ajaxified或不Ajaxified).

为了防止用户提交两次或更多的表格,我使用Javascript.

有一个Ajaxified表单的场景:

  • 用户提交表格(clic或enter)
  • javascript禁用提交按钮
  • rails控制器执行操作(如Soap请求或DB中的插入)
  • rails控制器更新页面并在必要时启用提交按钮(如果有错误)

现在我想添加服务器端代码,以便在用户绕过javascript时保持真正干净.

有什么建议?

javascript forms controller ruby-on-rails double-submit-problem

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

如何通过传递ControllerName获取MVC Controller的所有操作列表?

如何获取Controller的所有操作列表?我搜索但找不到示例/答案.我看到一些推荐使用反射的例子,但我不知道如何.

这是我想要做的:

public List<string> ActionNames(string controllerName){




}
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc action controller

13
推荐指数
1
解决办法
6531
查看次数

具有继承性的通用Spring MVC控制器

我可以在Spring MVC中执行以下操作吗?

假设我有一个Base GenericController,如下所示,一个请求映射"/ list"

@Controller
public class GenericController<T>{

    @RequestMapping(method = RequestMethod.GET, value = "/list")
    public @ResponseBody List<T> getMyPage(){
        // returns list of T
    }

}
Run Code Online (Sandbox Code Playgroud)

以下是我的两个控制器

@Controller(value = "/page1")
public class Page1Controller extends GenericController<Page1>{

}

@Controller(value = "/page2")
public class Page2Controller extends GenericController<Page2>{

}
Run Code Online (Sandbox Code Playgroud)

现在我将能够访问URL"/ page1/list"和"/ page2/list",其中第一个转到Page1Controller,第二个转到Page2Controller.

controller spring-mvc

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

laravel 5只有root route工作

我是laravel的新手.我正在使用Ubuntu 15.04.我使用composer和一个使用$ sudo apt-get install lamp-server^命令的灯服务器安装了Laravel Framework版本5.1.7(LTS)(我没有安装Homestead).我PhpStorm 8.0.3用作IDE.

我创建了三条路线和一个控制器.该PagesController.php文件如下所示:

class PagesController extends Controller
{
    public function index()
    {
        return 'Welcome to my homepage!';
    }

    public function about()
    {
        return 'Learn a little about me.';
    }

    public function hello()
    {
        return 'Hello World!';
    }
}
Run Code Online (Sandbox Code Playgroud)

和routes.php看起来像这样:

Route::get('/', 'PagesController@index');

Route::get('about', 'PagesController@about');

Route::get('hello', 'PagesController@hello');
Run Code Online (Sandbox Code Playgroud)

每当我去http://localhost:63342/my-first-app/public/(或http://localhost:63342/my-first-app/public/index.php)它工作正常并向我显示Welcome to my homepage!消息.但每当我去http://localhost:63342/my-first-app/public/hello或者http://localhost:63342/my-first-app/public/about,我得到的是404 Not Found消息.

此外,.htaccess位于此处的文件 …

php controller routes laravel-5

13
推荐指数
4
解决办法
6964
查看次数

在Rails中"return render"vs"render ... and return"

是否有书面的任何功能上的差异return render 'edit'和render 'edit' and return?这两种语法都安全吗?

该return render语法有点更简洁,但render and return提倡正式在这里避免双重渲染错误.

return render将返回render方法返回的任何值,并从控制器方法render and return返回a nil.

controller ruby-on-rails

13
推荐指数
1
解决办法
9180
查看次数