使用域或命令对象验证不能总是合理地检查例如用户输入错误的错误.
例如,在创建"忘记密码"功能时,如果用户输入数据库中不存在的用户名,我希望显示足够的消息.所以控制器动作就是这样的
...
def user = User.find{name==uname}
if(!user) {
// user not found in db, output error and render view again
render view: 'forgotPassword'
return
}
// do reset password stuff
...
Run Code Online (Sandbox Code Playgroud)
如何在<g:hasErros>标记内的视图中显示错误?
flash.message(因为生成的控制器/视图这样做)对我来说似乎不对,因为我不只是显示信息消息,而是一条错误消息.这就是为什么我认为消息应该由<g:hasErros>标签处理并显示为域验证错误.(对于用户来说,它是相同的反馈级别:"由于输入错误而无法工作".
创建@Validateable命令对象似乎也不正确.恕我直言,检查数据库的值实际上不是命令对象中的验证责任?或者是吗?那对我来说似乎有点太复杂了.
那么最好的方法是什么?其他框架(例如检票)提供不同的方法,如error(String msg)和info(String msg),其允许容易处理在视图反馈消息.Grails中是否有类似的概念,我还没有找到它?
我有两个场景Login.fxml和MainView.fxml以及两个不同的控制器LoginController.java和MainViewControler.java
在LoginController中,我执行整个登录过程并获取JSessionID的值并将其存储在对象中,如下所示:
loginGateway = loginGateway(gateway);
Run Code Online (Sandbox Code Playgroud)
现在在MainViewController中我需要使用this对象(loginGateway)来获取getJSessionID并向服务器发出其他请求.但是如何在另一个Controller类(MainViewController.java)中访问此对象?
我正在尝试检索$_POST通过jquery ajax func提交的数据,但似乎没有任何传递.这是我的代码:首先是我的表格:
{{ Form::open('', 'POST', array('id'=>'ajax')) }}
{{ Form::text('_date', '', array('id'=>'datepicker', 'class'=>'app_date')) }}
{{ Form::submit('Go', array('id'=>'go')) }}
{{ Form::close() }}
Run Code Online (Sandbox Code Playgroud)
和jquery:
$('#ajax').submit(function(e){
$.ajax({
url: 'appajax',
type: 'POST',
data: $('.app_date').val(),
dataType: 'json',
success: function(info){
console.log(info);
}
});
e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
......最后在控制器中:
public function post_appajax()
{
return Response::json(Input::get('_date'));
}
Run Code Online (Sandbox Code Playgroud)
在控制台中输出是NULL.我错过了什么?我正在使用目前可从laravel.com下载的laravel 3.谢谢.
我有两个控制器,主页和安全.
在主页中,我显示一个视图,在安全性中,我正在做一些事情,其中一个是电子邮件地址验证.
我想要的是,当电子邮件验证码无效时,显示带有flash消息的主页.为此,我将从安全控制器渲染HomepageController的indexAction,将其作为flash消息的参数.
如何才能做到这一点?我可以从另一个控制者那里渲染一条路线或一个动作吗?
先感谢您.
我的问题是我想在另一个控制器中使用POST DATA而不是GET重定向到操作
RedirectToAction("GenaraleExportPDF", "ExportController", new {
screendata = json, monTitre = monTitre, file = file, block1 = block1, block2 = block2, block3 = block3, block4 = block4
});
Run Code Online (Sandbox Code Playgroud)
这个例子说明了重定向但是在GET Action上.
我目前正在创建一个基于Bootstrap的自定义页面,因此我无法通过CMS.
我创建了一个文件Mypage.php,我放在包含此代码的Prestahop根目录中:
<?php
require(dirname(__FILE__).'/config/config.inc.php');
ControllerFactory::getController('MypageController')->run();
?>
Run Code Online (Sandbox Code Playgroud)
然后我MypageController.php在override/controllers/front中创建了一个包含此代码的控制器:
class MypageControllerCore extends FrontController
{
public $php_self = 'Mypage.php';
public $ssl = true;
public function preProcess()
{
parent::preProcess();
}
public function setMedia()
{
parent::setMedia();
Tools::addCSS(_THEME_CSS_DIR_.'Mypage.css');
}
public function displayContent()
{
$_POST = array_merge($_POST, $_GET);
parent::displayContent();
self::$smarty->display(_PS_THEME_DIR_.'Mypage.tpl');
}
}
Run Code Online (Sandbox Code Playgroud)
最后我Mypage.tpl用我的HTML代码在我的主题目录中放了一个文件.
我自然删除cache/class_index.php但仍然遇到404错误.有任何想法吗?
我正在尝试使用form_for和制作嵌套表单fields_for.经过大量的研究和成功,不再在我的项目上工作了.我只是想重新创建一个railscast,看看我做错了什么.
我正在尝试重新创建在http://railscasts.com/episodes/196-nested-model-form-part-1上找到的示例,因为代码存在,所以不应该那么难,但我可以'设法从调查中创建问题.这是我的代码,直到现在:
rails new surveysays
rails g scaffold survey name:string
rake db:migrate
rails g scaffold question survey_id:integer content:text
rake db:migrate
Run Code Online (Sandbox Code Playgroud)
我正在尝试以完全相同的视频序列进行操作.我的问题模型:
class Question < ActiveRecord::Base
belongs_to :survey
end
Run Code Online (Sandbox Code Playgroud)
我的调查模型:
class Survey < ActiveRecord::Base
has_many :questions, dependent: :destroy
accepts_nested_attributes_for :questions
end
Run Code Online (Sandbox Code Playgroud)
我的调查表格带有嵌套问题字段:
<%= form_for(@survey) do |f| %>
...
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<%= f.fields_for :questions do |builder| %>
<p>
<%= builder.label :content, "Question" %><br/>
<%= builder.text_area :content, :row …Run Code Online (Sandbox Code Playgroud) 我的socialRegisterFactory.pages工厂中设置了一个变量,一旦FaceBook的信息完全加载就会更新.我正在尝试在我的控制器中观察这个变量,以便在加载信息时以及当该变量从false变为true时,watch函数会相应地更新范围.我已经在控制器中注销了工厂的变量,它确实显示正确,但范围没有正确更新.我的$ watch功能有问题吗?
我的控制器:
$scope.pagesLoaded = false;
$scope.$watch(socialRegisterFactory.pages, function(newVal, oldVal){
if (socialRegisterFactory.pages === true) {
alert("true!");
$scope.pagesLoaded = true;
}
}, true);
Run Code Online (Sandbox Code Playgroud)
我的工厂:
var socialRegisterFactory ={
pages: false,
getAvailablePages: function($scope){
return $http.get(settings.urlBase+'social/facebook/pages')
.then(function(resp) {
socialRegisterFactory.pages = true;
angular.copy(resp.data.data, socialRegisterFactory.fbPages);
//$scope.fbPages = socialRegisterFactory.fbPages;
return socialRegisterFactory.fbPages;
});
},
Run Code Online (Sandbox Code Playgroud) 请考虑以下示例.他们的工作方式不同吗
.controller('MyController',function($scope) {
$scope.username = 'World';
$scope.sayHello = function() {
$scope.greeting = 'Hello ' + $scope.username + '!';
};
});
Run Code Online (Sandbox Code Playgroud)
VS
.controller('MyController', ['$scope', function($scope) {
$scope.username = 'World';
$scope.sayHello = function() {
$scope.greeting = 'Hello ' + $scope.username + '!';
};
}]);
Run Code Online (Sandbox Code Playgroud)
他们为我输出相同的内容,我只是不明白为什么我们把它放在那里.有时我必须把它作为工作的对象.为什么定义两次?
我想为控制器编写测试。这是测试代码段:
@RunWith(SpringRunner.class)
@WebMvcTest(WeatherStationController.class)
@ContextConfiguration(classes = MockConfig.class)
public class WeatherStationControllerTest {
@Autowired
private MockMvc mockMvc;
@Autowired
private IStationRepository stationRepository;
@Test
public void shouldReturnCorrectStation() throws Exception {
mockMvc.perform(get("/stations")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
}
}
Run Code Online (Sandbox Code Playgroud)
控制器代码段:
@RestController
@RequestMapping(value = "stations")
public class WeatherStationController {
@Autowired
private WeatherStationService weatherService;
@RequestMapping(method = RequestMethod.GET)
public List<WeatherStation> getAllWeatherStations() {
return weatherService.getAllStations();
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public WeatherStation getWeatherStation(@PathVariable String id) {
return weatherService.getStation(id);
}
Run Code Online (Sandbox Code Playgroud)
MockConfig类:
@Configuration
@ComponentScan(basePackages = "edu.lelyak.repository")
public class MockConfig {
//**************************** MOCK BEANS …Run Code Online (Sandbox Code Playgroud) controller ×10
angularjs ×2
php ×2
asp.net ×1
c# ×1
factory ×1
grails ×1
java ×1
javafx ×1
javafx-2 ×1
javascript ×1
jquery ×1
laravel ×1
nested-forms ×1
object ×1
redirect ×1
routing ×1
spring ×1
spring-boot ×1
symfony ×1
unit-testing ×1
view ×1
watch ×1