Alexc
(Alexclaidlaw)
November 4, 2015, 11:35am
1
Hi guys,
I’m currently trying to fix a new form that I assume is being generated in the controller that broke when I updated the version of yiibooster and broke the functionality of their forms. I have inherited this from a developer who is no longer with the company and so I’m trying to make as little changes to the system as possible, as there is little documentation
I decided to just try and revert to CForm but I’m still getting this error
Fatal error: Call to a member function beginWidget() on array in /Applications/XAMPP/xamppfiles/htdocs/framework/web/form/CForm.php on line 437
Note, removing the null from my code returns a stack trace error of "beginwidget function does not exist in sessionForm", which is correct because it no longer is using the extension.
private function getSessionSelectionForm($dataModel) {
// SessionSelection Form Model
$sessionForm = new SessionSelectionForm();
$items = $dataModel->getDynamicFormSessionsConfig($sessionForm);
$form = new CForm (
array(
'title' => 'Session Registration',
'enableClientValidation' => true,
'enableAjaxValidation' => false, // Just keep this to false
'layout' => TbHtml::FORM_LAYOUT_HORIZONTAL,
'elements' => $items,
'buttons' => array(
'reset' => array(
'buttonType' => 'reset',
'label' => 'Reset',
),
'submit' => array(
'buttonType' => 'submit',
'label' => 'Next',
'context' => 'primary'
),
// 'cancel' => array(
// 'type' => 'submit',
// 'label' => 'Cancel',
// 'layoutType' => 'warning'
// ),
),
), null, array(
'htmlOptions' => array('class' => 'well'),
'type' => 'horizontal',
), $sessionForm
);
return $form;
}
And the view
<?php echo $form->render(); ?>
Your form’s owner object is an array.
Line 437 in CForm.php:
$this->_activeForm=$this->getOwner()->beginWidget($class, $options);
Where from do you render your view file and where is it located?
Alexc
(Alexclaidlaw)
November 5, 2015, 9:20am
3
Your form’s owner object is an array.
Line 437 in CForm.php:
$this->_activeForm=$this->getOwner()->beginWidget($class, $options);
Where from do you render your view file and where is it located?
The view file is in the event view folder under register.php whereas this is the eventcontroller.php
The only code I think that is running the form is this
<?php echo $form->render(); ?>
How is your $form variable defined?
Alexc
(Alexclaidlaw)
November 11, 2015, 10:22am
6
Not sure but fairly sure it is being declared here
$form = $this->getSessionSelectionForm($eventModel);
public function actionRegister($id) {
Yii::import('booster.widgets.TbForm');
$sessionSelectionModel = new SessionSelectionForm();
// EventModel
$eventModel = $this->loadModel($id);
// Is session Available
if ($eventModel->getRemainingCapacity() > 0 && $eventModel->getCountSessions() > 0) {
$form = $this->getSessionSelectionForm($eventModel);
// Store values in memory
$userID = Yii::app()->user->id;
$isRegistered = $eventModel->isUserRegistered();
if ($isRegistered) {
Yii::app()->user->setFlash('info', "You are already registered to attend this event, your schedule is shown below.");
}
if ($form->submitted() && $form->validate()) {
// For Each group
if (!$isRegistered) {
for ($index = 0; $index < SessionSelectionForm::DYNAMIC_VAR_COUNT_GROUP; $index++) {
// Session Selection
if (isset($_POST['SessionSelectionForm']["group_{$index}"])) {
$sessionAttendeesModel = new SessionAttendees();
$sessionAttendeesModel->user_id = $userID;
$sessionAttendeesModel->session_id = $_POST['SessionSelectionForm']["group_{$index}"];
$sessionAttendeesModel->event_id = $eventModel->id;
$sessionAttendeesModel->save();
}
}
}
// Event Questions
for ($index = 0; $index < SessionSelectionForm::DYNAMIC_VAR_COUNT_QUESTION; $index++) {
if (isset($_POST['SessionSelectionForm']["question_{$index}"])) {
$sessionSelectionModel->{"question_" . $index} = $_POST['SessionSelectionForm']["question_{$index}"];
if (isset($eventModel->type->eventTypeVariables[$index - 1]->name)) {
// set questions
// Attempt to find original
$eventUserVariable = $eventModel->getDynamicVarible($eventModel->type->eventTypeVariables[$index - 1]->name);
if ($eventUserVariable == null) {
$eventUserVariable = new EventVariables;
}
$eventUserVariable->event_id = $eventModel->id;
// Get Event Type Model
$selectedQuestion = $eventModel->getDynamicEventTypeVarible($eventModel->type->eventTypeVariables[$index - 1]->name, $_POST['SessionSelectionForm']["question_{$index}"]);
$eventUserVariable->event_type_variables_id = $selectedQuestion->id;
$eventUserVariable->user_id = $userID;
$eventUserVariable->value = $_POST['SessionSelectionForm']["question_{$index}"];
Yii::app()->user->setFlash('info', "Session saved... ");
$eventUserVariable->save();
}
}
}
if (!$isRegistered) {
// Create our Event Booking
$eventAttendees = new EventAttendees();
$eventAttendees->user_id = $userID;
$eventAttendees->event_id = $eventModel->id;
$eventAttendees->checkin_status_id = 0;
$eventAttendees->status_id = 0;
$eventAttendees->save();
}
Yii::app()->user->setFlash('info', "Your booking details have been saved ");
$this->refresh(); // We refresh here, to load the updated attributes
}
$this->render('register', array(
'model' => $this->loadModel($id),
'form' => $form,
));
} else {
$this->render('view_sales_over');
}
}
If you write this code, after the "$form = $this->getSessionSelectionForm($eventModel);" line, what do you see in your application.log?
Yii::log(CVarDumper::dumpAsString($form), 'error');