本文整理汇总了PHP中Preference::setCategoryPreferenceId方法的典型用法代码示例。如果您正苦于以下问题:PHP Preference::setCategoryPreferenceId方法的具体用法?PHP Preference::setCategoryPreferenceId怎么用?PHP Preference::setCategoryPreferenceId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Preference
的用法示例。
在下文中一共展示了Preference::setCategoryPreferenceId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processForm
protected function processForm(sfWebRequest $request, sfForm $form)
{
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid()) {
$notice = $form->getObject()->isNew() ? 'Элемент создан успешно.' : 'Элемент изменен успешно.';
$form->getObject()->setCompanyId($request->getParameter('element_company'));
$form->getObject()->setPriceType($request->getParameter('element_price_type'));
if ($form->getObject()->isNew()) {
$form->getObject()->setDateCreated(time());
}
$form->getObject()->setDateUpdated(time());
$form->getObject()->setCategoryId($request->getParameter('element_category_id'));
$Element = $form->save();
foreach ((array) $request->getParameter('element_file') as $key => $value) {
if (isset($value['delete'])) {
$file_delete = ElementFilePeer::retrieveByPk($key);
$file_delete->delete();
}
}
foreach ((array) $request->getFiles('element_file') as $key => $value) {
list($type, $ext) = explode('/', $value['type']);
if (isset($value['id']) and $value['id'] != 0) {
$file = ElementFilePeer::retrieveByPk($value['id']);
} else {
$file = new ElementFile();
}
$file->setElementId($Element->getId());
$file->setName(md5(time()) . '.' . $ext);
$file->setFileType($type == 'image' ? 1 : 2);
$file->save(null, $value);
}
foreach ((array) $request->getParameter('element_preference') as $key => $value) {
if (isset($value['id']) and $value['id'] != 0) {
$preference = PreferencePeer::retrieveByPk($value['id']);
} else {
$preference = new Preference();
}
$preference->setElementId($Element->getId());
$preference->setCategoryPreferenceId($value['category_preference_id']);
$preference->setValue(isset($value['value']) ? $value['value'] : 0);
$preference->save();
}
$this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $Element)));
if ($request->hasParameter('_save_and_add')) {
$this->getUser()->setFlash('notice', $notice . ' Можно добавить еще один.');
$this->redirect('@element_new');
} else {
$this->getUser()->setFlash('notice', $notice);
$this->redirect(array('sf_route' => 'element_edit', 'sf_subject' => $Element));
}
} else {
$this->getUser()->setFlash('error', 'Эелемент не сохранен, так как некоторые поля заполненны не верно!', false);
}
}
示例2: processForm
protected function processForm(sfWebRequest $request, sfForm $form)
{
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid()) {
$notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.';
$Element = $form->save();
foreach ((array) $request->getParameter('element_preference') as $key => $value) {
if (isset($value['id']) and $value['id'] != 0) {
$preference = PreferencePeer::retrieveByPk($value['id']);
} else {
$preference = new Preference();
}
$preference->setElementId($Element->getId());
$preference->setCategoryPreferenceId($value['category_preference_id']);
$preference->setValue(isset($value['value']) ? $value['value'] : 0);
$preference->save();
}
$this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $Element)));
if ($request->hasParameter('_save_and_add')) {
$this->getUser()->setFlash('notice', $notice . ' You can add another one below.');
$this->redirect('@element_new');
} else {
$this->getUser()->setFlash('notice', $notice);
$this->redirect(array('sf_route' => 'element_edit', 'sf_subject' => $Element));
}
} else {
$this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false);
}
}