我有一些控制器方法可以处理WMI类(唤醒选定的计算机,打开或关闭进程,启动RDP会话),然后重新加载当前视图。要重新加载,我尝试了以下操作:
return View();
return RedirectToAction("Index", "RenderNodesController");
return RedirectToAction("Index");
return Redirect(Request.UrlReferrer.ToString());
Run Code Online (Sandbox Code Playgroud)
所有方法都可以成功执行WMI调用,但是return语句不会重新加载页面。如果我手动刷新页面,它将重新加载并按预期显示更改的信息。同样相当奇怪的是,如果我在调试器中逐步执行return语句,我会看到视图的Index方法已执行,因此在这种情况下调试似乎无济于事。我将不胜感激。
下面是我的控制器Admin/MoviesController的'store'方法示例.它看起来已经很大了,"更新"方法会更大.
算法是:
我的问题:
有一些最佳做法吗?我说的不是MVC,而是Laravel的功能.目前为了保持一些逻辑,我只使用Request for validation.
public function store(CreateMovieRequest $request) {
$movie = Movies::create($request->except('poster'));
/* Uploading poster */
if ($request->hasFile('poster')) {
$poster = \Image::make($request->file('poster'));
$poster->fit(250, 360, function ($constraint) {
$constraint->upsize();
});
$path = storage_path() . '/images/movies/'.$movie->id.'/';
if(! \File::exists($path)) {
\File::makeDirectory($path);
}
$filename = time() . '.' . $request->file('poster')->getClientOriginalExtension();
$poster->save($path . $filename);
$movie->poster = $filename;
}
/* If 'Meta Title' is empty, then fill it with the name of the movie */ …Run Code Online (Sandbox Code Playgroud)我需要在MVC控制器方法中读取web.config appsettings并传递它们以查看和访问angularjs控制器和服务中的设置.我正在考虑循环使用appsettings并准备一个包含键/值对的字典,并将模型对象传递给我的视图.但是如何在角度应用程序中的任何位置访问它们?
我想在应用程序的服务器端将所有java8 ZonedDateTimes转换为UTC时区.我使用@DateTimeFormat成功地将Java 8 jsr310日期数据类型绑定到spring RestController中.
@RequestMapping(value = "rest/test-date", method = RequestMethod.GET)
public TestCollection findPrivilegesByRoleList(
@RequestParam(value = "local-date", defaultValue = "2015-05-10") @DateTimeFormat(iso = ISO.DATE) LocalDate requestParamDate,
@RequestParam(value = "local-date-time", defaultValue = "2015-05-16T15:55:56") @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime requestParamLocalDateTime,
@RequestParam(value = "zoned-date-time", defaultValue = "2015-05-18T11:55:56-04:00") @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime requestParamZonedDateTime
)
Run Code Online (Sandbox Code Playgroud)
对于ZonedDateTime类,我想将所有输入ZonedDateTimes转换为UTC时间,因此服务器端始终在UTC时区中工作.遵循最佳实践#3 - 将其存储在UTC中 http://apiux.com/2013/03/20/5-laws-api-dates-and-times/#comments
对于JSON反序列化,我有一个ZonedDateTime的自定义反序列化器,可将任何时区转换为UTC.
....
//Parse string into a zoned date time with the specified timezone offset - EST, CET, EDT, PST, ect.
ZonedDateTime zonedDateTimewithTimeZone = ZonedDateTime.parse(string, formatter);
//Shift the date …Run Code Online (Sandbox Code Playgroud) 如果我具有以下表单字段(下面的代码),如何在模型中根据需要设置该字段,以便像其他字段一样,如果表单不包含信息,则无法提交该表单。
<?= $form->field($model, 'seo[seo_title]')->textInput(['maxlength' => 60])->label('SEO Title') ?>
Run Code Online (Sandbox Code Playgroud) 所以在Yii 1中,在视图文件中,您可以使用$this->action()或访问Controller的属性/操作$this->property.
在Yii 2中,我能看到这种可能性的唯一方法是使用Yii::$app->controller->property或Yii::$app->controller->action().我是一个不想写更多代码的人,所以我想知道是否有更短的方法.
我没有得到extract()函数的挂起,并且传输变量.我在用户控制器中有一个方法,其中定义了一些变量,并在数组中发送到父控制器中的视图函数,在该控制器中提取数组.然后视图是必需的.但变量未定义.可以打印数组内容.
以下是具有简化配置文件功能的用户控制器:
class User extends Controller{
public function profile(){
$profiledetails = $this->profiledetails();
$profilestatus = $this->profileStatus();
$this->view('profile', [$profiledetails, $profilestatus]);
}}
Run Code Online (Sandbox Code Playgroud)
变量被发送到父Controller中的view函数:
class Controller {
public function view($view, $variables =[]){
extract($variables);
require_once './app/views/' . $view . '.php';
}}
Run Code Online (Sandbox Code Playgroud)
在视图中,'profile.php',显示未定义的变量错误.我认为"extract()"函数会使$ profiledetails和$ profilestatus在视图中可用作变量.我究竟做错了什么?也许我正在使用错误类型的数组,或者我应该使用"变量变量"或其他东西..(在这种情况下,如何?).
基本上我的:创建动作测试保持失败,即使它在应用程序中工作.我在下面的控制器中注释了回形针验证并且它有效.
has_attached_file :image, styles: { medium: "700x700>", small: "350x250#" }
validates_attachment_presence :image
validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/
Run Code Online (Sandbox Code Playgroud)
这是我正在运行的测试,它在注释验证时有效.我怎样才能通过符合我模型中回形针验证的参数.
test "should create if signed_in" do
sign_in(@user)
assert_difference 'Product.count' do
post :create, product:{ title:'test_product', description: 'khara', user_id: @user.id}
end
assert_redirected_to product_path(assigns(:product))
end
Run Code Online (Sandbox Code Playgroud)
失败的消息:
FAIL["test_should_post_create_if_signed_in", ProductsControllerTest, 0.58458]
test_should_post_create_if_signed_in#ProductsControllerTest (0.58s)
"Product.count" didn't change by 1.
Expected: 3
Actual: 2
test/controllers/products_controller_test.rb:52:in `block in <class:ProductsControllerTest>'
Run Code Online (Sandbox Code Playgroud)
基本上我该怎么做这个测试通过?
注意:我知道回形针提供了测试指令,而Shoulda和Spec希望纯粹在Minitest中做到这一点.
我尝试List<Theatres>使用AJAX从视图发送到控制器
每个theates都有一个TheatresName(字符串),TheatresNumber(int),HomeCinemaID(int),RowAmount(int).
这里的型号代码:
public class MovieTheaters
{
[Key]
public int MovieTheatersID { get; set; }
public int HomeCinemaID { get; set; }
public string TheatersName { get; set; }
public int NumberHall { get; set; }
public int RowAmount { get; set; }
//FK .
public virtual HomeCinema HomeCinema { get; set; }
public virtual ICollection<Rows> Rows { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
用户输入他需要的剧院数量然后为循环提供创建它们的选项.
查看代码:
@model CimenaCityProject.Models.MovieTheaters
@{
ViewBag.Title = "Create";
}
<h2>Create New Theatres</h2>
@Html.AntiForgeryToken()
@{ …Run Code Online (Sandbox Code Playgroud) 这是我的第一个php框架.我的控制器中有一个php文件,它是posts.php但是当我尝试运行localhost/codeigniter/index.php/posts时,它显示错误404
.htaccess在应用程序文件夹中
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
Run Code Online (Sandbox Code Playgroud)
autoload.php
$autoload['libraries'] = array('database');
$autoload['helper'] = array('url');
Run Code Online (Sandbox Code Playgroud)
config.php文件
$config['base_url'] = 'http://localhost/codeigniter/';
$config['index_page'] = 'index.php';
Run Code Online (Sandbox Code Playgroud)
routes.php文件
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Run Code Online (Sandbox Code Playgroud)
模型文件夹中的post.php
class Post extends CI_Model{
function get_posts($num = 20, $start = 0){
//$sql = "SELECT * FROM users WHERE active=1 ORDER BY date_added DESC LIMIT 0,20;";
$this->db->select()->from('posts')->where('active', 1)->order_by('date_added', 'desc')->limit(0, 20);
$query=$this->db->get();
return $query->result_array();
}
}
Run Code Online (Sandbox Code Playgroud)
控制器文件夹中的posts.php
class Posts extends CI_Controller{
function index(){ …Run Code Online (Sandbox Code Playgroud)