当前位置: 首页>>代码示例>>PHP>>正文


PHP Preference::setElementId方法代码示例

本文整理汇总了PHP中Preference::setElementId方法的典型用法代码示例。如果您正苦于以下问题:PHP Preference::setElementId方法的具体用法?PHP Preference::setElementId怎么用?PHP Preference::setElementId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Preference的用法示例。


在下文中一共展示了Preference::setElementId方法的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);
     }
 }
开发者ID:Chipusy,项目名称:lkbroker,代码行数:54,代码来源:actions.class.php

示例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);
     }
 }
开发者ID:Chipusy,项目名称:lkbroker,代码行数:29,代码来源:actions.class.php


注:本文中的Preference::setElementId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。