Я создаю новый модуль на OrangeHRM и пытаюсь создать форму. Но когда я публикую форму, значения не будут опубликованы в файле действий. Я пробовал много раз, но результат все тот же.
вот действие:
<?php
class requestTrainingAction extends sfAction {
private $trainingService;
/**
* Get TrainingService
* @returns TrainingService
*/
public function getTrainingService() {
if (is_null($this->trainingService)) {
$this->trainingService = new TrainingService();
}
return $this->trainingService;
}
/**
* Set TrainingService
* @param TrainingService $trainingService
*/
public function setTrainingService(TrainingService $trainingService) {
$this->trainingService = $trainingService;
}
/**
* @param sfForm $form
* @return
*/
public function setForm(sfForm $form) {
if (is_null($this->form)) {
$this->form = $form;
}
}
/**
*
* @param <type> $request
*/
public function execute($request) {
/* For highlighting corresponding menu item */
$request->setParameter('initialActionName', 'requestTraining');
$this->form = new RequestTrainingForm();
if ($this->getUser()->hasFlash('templateMessage')) {
$this->templateMessage = $this->getUser()->getFlash('templateMessage');
}
if ($request->isMethod('post')) {
$this->form->bind($request->getParameter($this->form->getName()));
if ($this->form->isValid()) {
$templateMessage = $this->form->save();
$this->getUser()->setFlash($templateMessage['messageType'], $templateMessage['message']);
$this->redirect('training/requestTraining');
}
}
$this->listForm = new DefaultListForm();
}
}
?>
Вот форма:
<?php
class RequestTrainingForm extends BaseForm {
private $trainingService;
private $trainingId;
public function getTrainingService() {
if (is_null($this->trainingService)) {
$this->trainingService = new TrainingService();
}
return $this->trainingService;
}
public function setTrainingService(TrainingService $trainingService) {
$this->trainingService = $trainingService;
}
public function configure() {// Job Level
$jobLevelChoices = Training::getLevelTextList();
$divisionChoices = Training::getDivisionTextList();
$departmentChoices = Training::getDepartmentTextList();
$this->setWidgets(array(
'chkJobLevel' => new ohrmWidgetCheckboxGroup(array('choices' => $jobLevelChoices, 'show_all_option' => true)),
'chkDivision' => new ohrmWidgetCheckboxGroup(array('choices' => $divisionChoices, 'show_all_option' => true)),
'chkDepartment' => new ohrmWidgetCheckboxGroup(array('choices' => $departmentChoices, 'show_all_option' => true)),
'training_name' => new sfWidgetFormInputText(),
'training_desc' => new sfWidgetFormTextArea(),
));
$this->setValidators(array(
'chkJobLevel' => new sfValidatorChoice(array('choices' => array_keys($jobLevelChoices), 'required' => true, 'multiple' => true)),
'chkDivision' => new sfValidatorChoice(array('choices' => array_keys($divisionChoices), 'required' => true, 'multiple' => true)),
'chkDepartment' => new sfValidatorChoice(array('choices' => array_keys($departmentChoices), 'required' => true, 'multiple' => true)),
'training_name' => new sfValidatorString(array('required' => true, 'max_length' => 120)),
'training_desc' => new sfValidatorString(array('required' => false, 'max_length' => 400)),
));
$this->widgetSchema->setNameFormat('training[%s]');
}
/**
*
* @return array
*/
public function getStylesheets() {
$styleSheets = parent::getStylesheets();
return $styleSheets;
}
public function getJavaScripts() {
$javaScripts = parent::getJavaScripts();
$javaScripts[] = plugin_web_path('orangehrmTrainingPlugin', 'js/requestTrainingSuccess.js');
return $javaScripts;
}
public function save() {
$message = array('messageType' => 'success', 'message' => __(TopLevelMessages::SAVE_SUCCESS));
$training = new Training();
$training->setTrainingName($this->getValue('training_name'));
$training->setTrainingDesc($this->getValue('training_desc'));
$this->getTrainingService()->saveRequestTraining($training);
return $message;
}
}
?>
И вот DAO:
<?php
class TrainingDao extends BaseDao {
public function saveRequestTraining(Training $training) {
try {
$training->save();
return $training;
} catch (Exception $e) {
throw new DaoException($e->getMessage(), $e->getCode(), $e);
}
}
}
?>
Ошибка показывает это:
01/06/17 11:21:16,781 [644] ERROR filter.ExceptionCatcherFilter - Uncaught Exception: exception 'Doctrine_Validator_Exception' with message 'Validation failed in class Training
2 fields had validation errors:
* 1 validator failed on trainingName (unsigned)
* 1 validator failed on trainingDesc (unsigned)
' in C:\xampp\htdocs\orangehrm-3.2.1\symfony\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Transaction.php:265
Stack trace:
#0 C:\xampp\htdocs\orangehrm-3.2.1\symfony\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Connection.php(1395): Doctrine_Transaction->commit(NULL)
#1 C:\xampp\htdocs\orangehrm-3.2.1\symfony\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Connection\UnitOfWork.php(148): Doctrine_Connection->commit()
#2 C:\xampp\htdocs\orangehrm-3.2.1\symfony\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Record.php(1718): Doctrine_Connection_UnitOfWork->saveGraph(Object(Training))
#3 C:\xampp\htdocs\orangehrm-3.2.1\symfony\plugins\orangehrmTrainingPlugin\lib\dao\TrainingDao.php(7): Doctrine_Record->save()
#4 C:\xampp\htdocs\orangehrm-3.2.1\symfony\plugins\orangehrmTrainingPlugin\lib\service\TrainingService.php(43): TrainingDao->saveRequestTraining(Object(Training))
#5 C:\xampp\htdocs\orangehrm-3.2.1\symfony\plugins\orangehrmTrainingPlugin\lib\form\RequestTrainingForm.php(79): TrainingService->saveRequestTraining(Object(Training))
#6 C:\xampp\htdocs\orangehrm-3.2.1\symfony\plugins\orangehrmTrainingPlugin\modules\training\actions\requestTrainingAction.class.php(87): RequestTrainingForm->save()
#7 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(952): requestTrainingAction->execute(Object(sfWebRequest))
#8 C:\xampp\htdocs\orangehrm-3.2.1\symfony\plugins\orangehrmCorePlugin\lib\filter\orangehrmExecutionFilter.php(36): sfExecutionFilter->executeAction(Object(requestTrainingAction))
#9 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(947): orangehrmExecutionFilter->executeAction(Object(requestTrainingAction))
#10 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(933): sfExecutionFilter->handleAction(Object(sfFilterChain), Object(requestTrainingAction))
#11 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): sfExecutionFilter->execute(Object(sfFilterChain))
#12 C:\xampp\htdocs\orangehrm-3.2.1\symfony\lib\vendor\symfony\lib\filter\sfCommonFilter.class.php(29): sfFilterChain->execute()
#13 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): sfCommonFilter->execute(Object(sfFilterChain))
#14 C:\xampp\htdocs\orangehrm-3.2.1\symfony\plugins\orangehrmCorePlugin\lib\filter\orangehrmPostExecutionFilter.php(22): sfFilterChain->execute()
#15 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): orangehrmPostExecutionFilter->execute(Object(sfFilterChain))
#16 C:\xampp\htdocs\orangehrm-3.2.1\symfony\apps\orangehrm\lib\filter\ModuleFilter.php(56): sfFilterChain->execute()
#17 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): ModuleFilter->execute(Object(sfFilterChain))
#18 C:\xampp\htdocs\orangehrm-3.2.1\symfony\plugins\orangehrmCorePlugin\lib\authorization\filter\ohrmAuthorizationFilter.php(97): sfFilterChain->execute()
#19 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): ohrmAuthorizationFilter->execute(Object(sfFilterChain))
#20 C:\xampp\htdocs\orangehrm-3.2.1\symfony\apps\orangehrm\lib\filter\SessionInfoFetcherFilter.php(67): sfFilterChain->execute()
#21 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): SessionInfoFetcherFilter->execute(Object(sfFilterChain))
#22 C:\xampp\htdocs\orangehrm-3.2.1\symfony\apps\orangehrm\lib\filter\OrangeI18NFilter.php(58): sfFilterChain->execute()
#23 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): OrangeI18NFilter->execute(Object(sfFilterChain))
#24 C:\xampp\htdocs\orangehrm-3.2.1\symfony\apps\orangehrm\lib\filter\ExceptionCatcherFilter.php(26): sfFilterChain->execute()
#25 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): ExceptionCatcherFilter->execute(Object(sfFilterChain))
#26 C:\xampp\htdocs\orangehrm-3.2.1\symfony\lib\vendor\symfony\lib\filter\sfBasicSecurityFilter.class.php(72): sfFilterChain->execute()
#27 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): sfBasicSecurityFilter->execute(Object(sfFilterChain))
#28 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(995): sfFilterChain->execute()
#29 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): sfRenderingFilter->execute(Object(sfFilterChain))
#30 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(665): sfFilterChain->execute()
#31 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(2352): sfController->forward('training', 'requestTraining')
#32 C:\xampp\htdocs\orangehrm-3.2.1\symfony\lib\vendor\symfony\lib\util\sfContext.class.php(170): sfFrontWebController->dispatch()
#33 C:\xampp\htdocs\orangehrm-3.2.1\symfony\web\index.php(22): sfContext->dispatch()
#34 {main}
Next exception 'DaoException' with message 'Validation failed in class Training
2 fields had validation errors:
* 1 validator failed on trainingName (unsigned)
* 1 validator failed on trainingDesc (unsigned)
' in C:\xampp\htdocs\orangehrm-3.2.1\symfony\plugins\orangehrmTrainingPlugin\lib\dao\TrainingDao.php:11
Stack trace:
#0 C:\xampp\htdocs\orangehrm-3.2.1\symfony\plugins\orangehrmTrainingPlugin\lib\service\TrainingService.php(43): TrainingDao->saveRequestTraining(Object(Training))
#1 C:\xampp\htdocs\orangehrm-3.2.1\symfony\plugins\orangehrmTrainingPlugin\lib\form\RequestTrainingForm.php(79): TrainingService->saveRequestTraining(Object(Training))
#2 C:\xampp\htdocs\orangehrm-3.2.1\symfony\plugins\orangehrmTrainingPlugin\modules\training\actions\requestTrainingAction.class.php(87): RequestTrainingForm->save()
#3 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(952): requestTrainingAction->execute(Object(sfWebRequest))
#4 C:\xampp\htdocs\orangehrm-3.2.1\symfony\plugins\orangehrmCorePlugin\lib\filter\orangehrmExecutionFilter.php(36): sfExecutionFilter->executeAction(Object(requestTrainingAction))
#5 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(947): orangehrmExecutionFilter->executeAction(Object(requestTrainingAction))
#6 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(933): sfExecutionFilter->handleAction(Object(sfFilterChain), Object(requestTrainingAction))
#7 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): sfExecutionFilter->execute(Object(sfFilterChain))
#8 C:\xampp\htdocs\orangehrm-3.2.1\symfony\lib\vendor\symfony\lib\filter\sfCommonFilter.class.php(29): sfFilterChain->execute()
#9 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): sfCommonFilter->execute(Object(sfFilterChain))
#10 C:\xampp\htdocs\orangehrm-3.2.1\symfony\plugins\orangehrmCorePlugin\lib\filter\orangehrmPostExecutionFilter.php(22): sfFilterChain->execute()
#11 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): orangehrmPostExecutionFilter->execute(Object(sfFilterChain))
#12 C:\xampp\htdocs\orangehrm-3.2.1\symfony\apps\orangehrm\lib\filter\ModuleFilter.php(56): sfFilterChain->execute()
#13 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): ModuleFilter->execute(Object(sfFilterChain))
#14 C:\xampp\htdocs\orangehrm-3.2.1\symfony\plugins\orangehrmCorePlugin\lib\authorization\filter\ohrmAuthorizationFilter.php(97): sfFilterChain->execute()
#15 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): ohrmAuthorizationFilter->execute(Object(sfFilterChain))
#16 C:\xampp\htdocs\orangehrm-3.2.1\symfony\apps\orangehrm\lib\filter\SessionInfoFetcherFilter.php(67): sfFilterChain->execute()
#17 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): SessionInfoFetcherFilter->execute(Object(sfFilterChain))
#18 C:\xampp\htdocs\orangehrm-3.2.1\symfony\apps\orangehrm\lib\filter\OrangeI18NFilter.php(58): sfFilterChain->execute()
#19 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): OrangeI18NFilter->execute(Object(sfFilterChain))
#20 C:\xampp\htdocs\orangehrm-3.2.1\symfony\apps\orangehrm\lib\filter\ExceptionCatcherFilter.php(26): sfFilterChain->execute()
#21 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): ExceptionCatcherFilter->execute(Object(sfFilterChain))
#22 C:\xampp\htdocs\orangehrm-3.2.1\symfony\lib\vendor\symfony\lib\filter\sfBasicSecurityFilter.class.php(72): sfFilterChain->execute()
#23 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): sfBasicSecurityFilter->execute(Object(sfFilterChain))
#24 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(995): sfFilterChain->execute()
#25 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(1031): sfRenderingFilter->execute(Object(sfFilterChain))
#26 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(665): sfFilterChain->execute()
#27 C:\xampp\htdocs\orangehrm-3.2.1\symfony\cache\orangehrm\prod\config\config_core_compile.yml.php(2352): sfController->forward('training', 'requestTraining')
#28 C:\xampp\htdocs\orangehrm-3.2.1\symfony\lib\vendor\symfony\lib\util\sfContext.class.php(170): sfFrontWebController->dispatch()
#29 C:\xampp\htdocs\orangehrm-3.2.1\symfony\web\index.php(22): sfContext->dispatch()
#30 {main}
Задача ещё не решена.
Других решений пока нет …