Hi,
I’ve been struggling with this for a couple of hours now, so I hope someone can steer me in the right direction.
I’ve configured Yii to use the path URL format and hide the index page. I’ve written a number of forms using the POST method and they work okay. I’d like to use the GET method for the search form I’m currently working on, so that I can link to the results of the search.
Here’s a stripped down version of the view:
<?php
print_r($_GET); // Printing contents of GET array while trying to figure out this problem
echo CHtml::beginForm('', 'get');
// name
$field = 'name';
echo CHtml::activeLabel($model, $field);
echo CHtml::activeTextField($model, $field, array('class'=>'form_input', 'maxlength'=>'80'));
echo CHtml::error($model, $field);
echo CHtml::endForm();
A stripped down version of the form model:
<?php
class FindMemberForm extends CFormModel{
public $name;
public function rules()
{
return array(
array('name', 'required'),
);
}
}
And a stripped down version of the controller action:
<?php
class MemberController extends AdminController {
public function actionFind()
{
Yii::import('application.models.forms.member.*');
$form = new FindMemberForm;
if (isset($_GET['FindMemberForm']))
{
$form->attributes = $_GET['FindMemberForm'];
}
$this->render('/member/find_member', array('model'=>$form));
}
}
At this point, the code should simply cause the form fields to retain their value after submission, by taking the submitted values from the GET array. The form reloads correctly, but the form data is inaccessible. For some reason, the GET data gets passed in a standard query string such as:
http://192.168.0.3/admin/member/find?FindMemberForm[name]=testvalue
This does not get loaded into the GET array, so the result of the print_r statement in the view is:
Array ( [/admin/member/find] => )
How can I retrieve the form data, given that Yii is expecting the GET parameters to be passed into the URL in the form /controller/action/param_name/param_value ? Is there some way of getting Yii to automatically load data passed in the standard format into the GET array when you are using the path URL format?
Thanks,
Keith