本文整理汇总了PHP中Respect\Validation\Validator::object方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::object方法的具体用法?PHP Validator::object怎么用?PHP Validator::object使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Respect\Validation\Validator
的用法示例。
在下文中一共展示了Validator::object方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: post
public function post($manufacturerId)
{
$editManufacturer = $this->collection[$manufacturerId]->fetch() ?: new stdClass();
foreach ($_POST as $k => $v) {
$editManufacturer->{$k} = $v;
}
try {
v::object()->attribute('name', v::string()->notEmpty()->length(1, 300))->assert($editManufacturer);
$this->collection->persist($editManufacturer);
$this->collection->flush();
if (empty($newManufacturer->manufacturer_featured)) {
$newManufacturer->manufacturer_featured = null;
}
if ($_FILES['files']['error'] != 4) {
foreach ($_FILES as $file) {
$this->uploaderService->setFile($editManufacturer->name, 'files');
$image = (object) ['name' => $this->uploaderService->getFile()->getNameWithExtension(), 'title' => $editManufacturer->name, 'type' => $this->uploaderService->getFile()->getMimetype(), 'manufacturer_id' => $editManufacturer->id];
$this->imageCollection->persist($image);
$this->imageCollection->flush();
$this->uploaderService->upload();
}
}
header('HTTP/1.1 303 See Other');
header('Location: ' . $_SERVER['REQUEST_URI']);
} catch (NestedValidationExceptionInterface $e) {
return ['editManufacturer' => $editManufacturer, 'messages' => $e->findMessages(['name' => 'Name must have between 1 and 300 chars', 'enabled' => 'Could not enable manufacturer'])];
}
}
示例2: postEdit
protected function postEdit($categoryId)
{
$editCategory = $this->collection[$categoryId]->fetch() ?: new stdClass();
foreach ($_POST as $k => $v) {
$editCategory->{$k} = $v;
}
try {
v::object()->attribute('name', v::string()->notEmpty()->length(1, 300))->attribute('enabled', v::numeric()->between(0, 1, true), false)->assert($editCategory);
$this->collection->persist($editCategory);
$this->collection->flush();
header('HTTP/1.1 303 See Other');
header('Location: ' . $_SERVER['REQUEST_URI']);
} catch (NestedValidationExceptionInterface $e) {
return ['editCategory' => $editCategory, 'messages' => $e->findMessages(['name' => 'Name must have between 1 and 300 chars', 'enabled' => 'Could not enable category'])];
}
}
示例3: post
public function post($featureId)
{
$editFeature = $this->collection[$featureId]->fetch() ?: new stdClass();
foreach ($_POST as $k => $v) {
$editFeature->{$k} = $v;
}
try {
v::object()->attribute('name', v::string()->notEmpty()->length(1, 300))->assert($editFeature);
$this->collection->persist($editFeature);
$this->collection->flush();
header('HTTP/1.1 303 See Other');
header('Location: ' . $_SERVER['REQUEST_URI']);
return $this->get($featureId);
} catch (NestedValidationExceptionInterface $e) {
return ['singleFeature' => $editFeature, 'messages' => $e->findMessages(['name' => 'Name must have between 1 and 300 chars', 'enabled' => 'Could not enable product'])];
}
}