我使用以下代码以模态方式呈现视图控制器:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
SubmitAYoNViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"SubmitAYoN"];
[ivc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:ivc animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
然后在我的 SubmitAYoNViewController 中我有这个:
NSLog(@"%@",self.parentViewController);
if([self.parentViewController isKindOfClass:[YesOrNoViewController class]]) {
NSLog(@"do something");
}
Run Code Online (Sandbox Code Playgroud)
self.parentVeiwController 为 NULL。这是为什么?
编辑:我想从我的父视图控制器访问一种方法,然后访问打开 SubmitAYoN 的方法。
解决方案:我使用委托代替。根据下面的答案,presentViewController 不会创建父子关系。
我有一个使用数据脚手架生成的视图。该视图有一个文本字段:
创建视图:
<div class="form-group">
@Html.LabelFor(model => model.GroupId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.GroupId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.GroupId, "", new { @class = "text-danger" })
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想将一个值从控制器传递到此文本字段。我做了以下,这似乎不起作用。
控制器:
public ActionResult Create(int id)
{
ViewBag.GroupId = id;
Debug.WriteLine("DEBUG: "+id);
return View();
}
Run Code Online (Sandbox Code Playgroud) 我有一个电子邮件地址字段,有一个客户端验证,不允许少数临时域,如 tempmailder.com 或 dispostable.com。
在服务器端,我使用了流畅的验证来指定验证规则。
web.config 文件中不允许使用逗号分隔字符串的临时域。
有没有一种方法可以指定根据不允许的电子邮件域列表验证用户输入的值。
RuleFor(x=>x.EMail). and something
Run Code Online (Sandbox Code Playgroud)
谢谢
我有 Rails 应用程序,其用例是在 collection_select 下拉框中显示价格。例如,产品名称及其价格,或客户和欠款金额。
我很清楚,简单地包含相关帮助程序来访问 number_to_currency 等函数是不好的 MVC 实践,但我可以使用产品或支付模型上的自定义方法获得一个看起来像 20.2 美元的值。因此,它是可读的,但不是最佳的,因为系统的大多数用户都期望 20 美元 20 美分表示为 20.20 美元。
有人对轻松自定义 collection_select 的 text_method 有任何建议吗?
我正在尝试将文件保存到磁盘,但收到 UnauthorizedAccessException。\n该错误表明我必须获得该文件夹的正确权限,并且我已尝试了我能找到的所有可能的用户,但没有成功工作。
\n\n尝试过以下用户
\n\n并在不工作的情况下给予充分的权利。
\n\n我发现真正奇怪的是,我在尝试保存文件之前创建了一个目录,并且效果很好,当尝试将文件保存到该新目录时,我得到了 UnautorhizedAccessException。
\n\n代码如下:
\n\n [HttpPost]\n public ActionResult Images(HttpPostedFileBase file, string boatId)\n {\n if (file.ContentLength > 0)\n {\n var fileName = Path.GetFileName(file.FileName);\n var path = Path.Combine(Server.MapPath("~/Content/Images/" + boatId));\n Directory.CreateDirectory(path);\n file.SaveAs(path);\n\n }\n return View($"Filen p\xc3\xa5 {boatId} har laddats upp");\n }\nRun Code Online (Sandbox Code Playgroud)\n\n对我所缺少的有什么想法吗?
\n我想知道我是否遵循 MVC 架构模式,在我的 Model 类中我可以调用 API 吗?
IE
class DataModel {
var data = "Some data that's a string"
func getAPIData(){
self.data = self.NetworkFunctionsClass.MakeAPICallFunction()
}
}
Run Code Online (Sandbox Code Playgroud)
我没有直接在模型类中创建函数
这是允许的吗?或者我通过引入一些操作而不是存储数据来违反模型规则?
在 ASP.Net mvc cshtml 页面中,我有以下代码调用位于我的文件夹中的 4 个部分视图:
<div id="accordion">
<h3 style="padding-left: 50px">Instructions</h3>
<div>@Html.Partial("/Views/Shared/_instruct.cshtml", null)</div>
<h3 style="padding-left: 50px">Projects by @Html.DisplayFor(model => model.FirstName) @Html.DisplayFor(model => model.LastName)</h3>
<div>@Html.Partial("~/Views/Shared/_research.cshtml", Model.Proposalsvm)</div>
<h3 style="padding-left: 50px"> Publications</h3>
<div> @Html.Partial("~/Views/Shared/_publications.cshtml", Model.Pubs)</div>
<h3 style="padding-left: 50px"> Patents</h3>
<div> @Html.Partial("~/Views/Shared/_patents.cshtml", Model.Patents)</div>
<h3 style="padding-left: 50px">Training</h3>
<div>@Html.Partial("~/Views/Shared/_Student.cshtml", Model.Students)</div>
</div>
Run Code Online (Sandbox Code Playgroud)
所有视图都位于我的共享文件夹中,并且拼写正确。当我从本地计算机运行代码时,所有部分视图都会呈现。当我将代码部署到生产计算机时,如果注释掉第一个视图,则会呈现最后三个部分视图。如果不这样做,我会收到以下错误:
The partial view '/Views/Shared/_instruct.cshtml' was not found or no view engine supports the searched locations. The following locations were searched:
/Views/Shared/_instruct.cshtml
Description: An unhandled exception occurred during the execution of the current web …Run Code Online (Sandbox Code Playgroud) 我需要在插入数据库之前验证一些数据,为此我创建了一个从实体返回无效字段的小服务。验证单个实体时它工作正常。
class EntityValidator
{
protected $validator;
public function __construct(ValidatorInterface $validator)
{
$this->validator = $validator;
}
public function validate($entity)
{
$errors = $this->validator->validate($entity);
$response = null;
if ($errors->count()) {
foreach ($errors as $error) {
$response[$error->getPropertyPath()] = $error->getMessage();
}
}
return $response;
}
}
Run Code Online (Sandbox Code Playgroud)
但我一直在努力验证更复杂的问题,例如:这是一个restful api端点,它接收带有user_id和帖子正文中百分比的json,它将验证实体以查看它是否与symfony验证器约束映射正确。
public function create(Request $request, EntityValidator $entityValidator)
{
$data = json_decode($request->getContent(), true);
$entityExample = new EntityExample();
$entityExample
->setUserId($data['user_id'])
->setPercentage($data['percentage'])
;
$errors = $entityValidator->validate($entityExample);
// .. do other things ..
return new JsonResponse($errors);
}
Run Code Online (Sandbox Code Playgroud)
但是假设我收到一个数据数组,并且我要一次插入多行,并且有一个业务逻辑说“用户的百分比总和需要为 100”
public function …Run Code Online (Sandbox Code Playgroud) php model-view-controller code-structure symfony symfony-validator
我是 Prestashop 的新手,我正在尝试添加一个新的“排序依据”字段(默认情况下,您有:“相关性”,“名称,A 到 Z”,“名称,Z 到 A”,“价格,低至高”, “价格从高到低”)
如你们所知,该功能位于名为“Ps_facetedsearch”的模块中,链接此处。
我试过:
所以我的问题是:
任何提示表示赞赏!
PrestaShop 版本:1.7.4.2
我需要复制/粘贴 Ps_facetedsearch 模块中的行,以便添加额外的“排序依据”字段:
private function getAvailableSortOrders()
{
return [
(new SortOrder('product', 'position', 'asc'))->setLabel(
$this->module->getTranslator()->trans('Relevance', array(), 'Modules.Facetedsearch.Shop')
),
(new SortOrder('product', 'name', 'asc'))->setLabel(
$this->module->getTranslator()->trans('Name, A to Z', array(), 'Shop.Theme.Catalog')
),
(new SortOrder('product', 'name', 'desc'))->setLabel(
$this->module->getTranslator()->trans('Name, Z to A', array(), 'Shop.Theme.Catalog')
),
(new SortOrder('product', 'price', 'asc'))->setLabel(
$this->module->getTranslator()->trans('Price, low to high', array(), 'Shop.Theme.Catalog')
),
(new SortOrder('product', 'price', 'desc'))->setLabel(
$this->module->getTranslator()->trans('Price, high to low', array(), …Run Code Online (Sandbox Code Playgroud) 我有这个代码:
\n\n <span class="glyphicon glyphicon-search"></span>\n @Html.TextBox("text", Model.Search.text, new {placeholder = Html.T("\xd0\x9f\xd0\xbe\xd0\xb8\xd1\x81\xd0\xba"), @class = "form-control"})\nRun Code Online (Sandbox Code Playgroud)\n\n结果是:
\n\n\n\n如果用户输入一些文本并按 Enter 键,则可以正常工作。搜索工作正常。但“搜索”按钮不起作用。它只是停留且不可点击。如何使“搜索”按钮可点击而不丢失外观?
\nc# ×4
html ×2
ios ×2
php ×2
symfony ×2
.net ×1
asp.net-mvc ×1
controller ×1
css ×1
javascript ×1
prestashop ×1
razor ×1
swift ×1
validation ×1
view ×1