鉴于我只能访问ControllerContext而不是Action____Contexts获取当前正在执行的ActionDescriptor的最佳方式是什么?
到目前为止,我发现的唯一方法是:
new ReflectedControllerDescriptor(context.Controller.GetType())
.FindAction(context, context.RouteData.GetRequiredString("action"));
Run Code Online (Sandbox Code Playgroud)
这是最佳方法吗?
这个类被命名的事实ReflectedControllerDescriptor让我想知道这个操作是否会付出沉重的代价,因为它会在每个页面请求上执行?与此相关的是此类内部缓存还是我应该实际缓存ReflectedControllerDescriptors?
有一个联系页面,提供输入姓名,电话,电子邮件和消息,然后发送给管理员的电子邮件.没有理由在DB中存储消息.
题.如何:
在控制器中使用Rails验证,完全不使用模型,或者
在模型中使用验证,但没有任何数据库关系
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) 我在表单上使用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) 很多游戏都在使用x360控制器,但没有正确映射到PS3 DS3控制器......
MotionInJoy使用"模拟360控制器"进行清理,但它仅适用于PC.还有另一个仅限PC的项目:x360ce:https://code.google.com/p/x360ce/
这是一个问题:mac os x有什么解决方案吗?如果没有,为什么!
我正在使用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) 好吧,一切都在标题中,但我会解释一下:-)
我的rails应用程序包含许多表单(Ajaxified或不Ajaxified).
为了防止用户提交两次或更多的表格,我使用Javascript.
有一个Ajaxified表单的场景:
现在我想添加服务器端代码,以便在用户绕过javascript时保持真正干净.
有什么建议?
javascript forms controller ruby-on-rails double-submit-problem
如何获取Controller的所有操作列表?我搜索但找不到示例/答案.我看到一些推荐使用反射的例子,但我不知道如何.
这是我想要做的:
public List<string> ActionNames(string controllerName){
}
Run Code Online (Sandbox Code Playgroud) 我可以在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.
我是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位于此处的文件 …
是否有书面的任何功能上的差异return render 'edit'和render 'edit' and return?这两种语法都安全吗?
该return render语法有点更简洁,但render and return提倡正式在这里避免双重渲染错误.
return render将返回render方法返回的任何值,并从控制器方法render and return返回a nil.
controller ×10
php ×2
action ×1
angularfire ×1
angularjs ×1
arguments ×1
asp.net-mvc ×1
c# ×1
codeigniter ×1
directinput ×1
firebase ×1
forms ×1
javascript ×1
laravel-5 ×1
macos ×1
model ×1
mysql ×1
ps3 ×1
routes ×1
spring-mvc ×1
validation ×1
xinput ×1