Bruce Gust
asked on
How can I do a var_dump in Symfony?
I need to see $_POST['criteria']. I want to use var_dump to do it, but I don't how to incorporate that into a Symfony Controller.
Here's the code:
At one point, I tried to eliminate the "return $this->redirectToRoute('ad min_gamifi cation_cha llenges'); " and do a "var_dump," but I got an error that said Symfony requires a "return" of some sort, but...
...how can I do a var_dump and see what the "_POST[criteria] array looks like?
Thanks!
Here's the code:
public function saveAction($id, Request $request){
$data = $_POST['challenge'];
// validate fields
foreach(['campName', 'campPointConv', 'campHierarchy', 'campParticUnits', 'campStartDate', 'campEndDate'] as $requiredField){
if(!Util::valid($requiredField, $data)){
$this->addNotice('You are missing required fields', 'error');
return $this->redirectToRoute('admin_gamification_challenges_edit', ['id'=>$id]);
}
}
if(!empty($data['campAutoSync'])){
foreach(['campAutoSyncHrId', 'campAutoSyncPoints', 'campAutoSyncUnits'] as $requiredField){
if(!Util::valid($requiredField, $data)){
$this->addNotice('You are missing required auto sync fields', 'error');
return $this->redirectToRoute('admin_gamification_challenges_edit', ['id'=>$id]);
}
}
if(!is_numeric($data['campAutoSyncPoints']) || !is_numeric($data['campAutoSyncUnits'])){
$this->addNotice('Auto sync points and units must be numbers', 'error');
return $this->redirectToRoute('admin_gamification_challenges_edit', ['id'=>$id]);
}
}
//here you're looking to make sure that if the "BETWEEN" clause was used for any of the rules, that the values inputted are, in fact, integers
$isNew = (empty($id) || $id == 'new')?true:false;
// save
$resp = $this->get('gamification.challenges')->saveChallenge($id, $data, $this->user->cpScope);
if(!$resp){
$this->addNotice('There was an error saving this challenge.', 'error');
return $this->redirectToRoute('admin_gamification_challenges');
}
$id = $resp['id'];
$criteria = (isset($_POST['criteria']) && !empty($_POST['criteria']))?$this->_assembleCriteria($_POST['criteria']):['and'=>[], 'or'=>[]];
$rule = ['ruleName'=>'Rule: '.$data['campName'], 'ruleDesc'=>$_POST['ruleDesc'], 'ruleStatus'=>'Active', 'ruleCriteria'=>$criteria];
$ruleID = (isset($_POST['ruleID']) && !empty($_POST['ruleID']))?$_POST['ruleID']:'new';
$resp_rule = $this->get('gamification.rules')->saveRule($ruleID, $rule, $id, $this->user->cpID, true);
$this->get('gamification.challenges')->saveParticLimits($_POST['partic_limits'], $id);
if(isset($_POST['lrnID'])){
$this->get('learning.learning')->saveChallengeAssignment($_POST['lrnID'], $id);
}
if($isNew){
$employers = $this->get('gamification.campaigns')->getPopulationEmployers($data['campHierarchy'], $this->user->cpID);
$userPushTokens = $this->get('push_notifications')->getUserTokensFromEmpScope(array_keys($employers), $this->user->cpScope);
if(!empty($userPushTokens)){
$notificationData = $this->get('push_notifications')->getNotificationContent('GamificationNewChallenge');
$this->get('push_notifications')->sendNotification($userPushTokens, ['title'=>$notificationData['title'], 'message'=>sprintf($notificationData['message'], $data['campName']), 'screen'=>'Gamification', 'params'=>['campID'=>$id]]);
}
}
$this->addNotice('Your challenge was successfully saved', 'success');
return $this->redirectToRoute('admin_gamification_challenges');
}
At one point, I tried to eliminate the "return $this->redirectToRoute('ad
...how can I do a var_dump and see what the "_POST[criteria] array looks like?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.