payu2107 / zii

Automatically exported from code.google.com/p/zii
0 stars 0 forks source link

CForm tosses fatal error when using as documented #29

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Already report here: http://code.google.com/p/yii/issues/detail?id=948

What steps will reproduce the problem?
Follow the tutorial for a Nested Form 
(http://www.yiiframework.com/doc/guide/form.builder#creating-a-nested-form)

What is the expected output? What do you see instead?
I expect to see a rendered form, but instead find this error in error logs:
[Fri Feb 19 17:05:45 2010] [error] [client 70.63.90.226] PHP Fatal error:  
Call to a member function isAttributeSafe() on a non-object in 
/var/www/dev/lib/yiiframework/web/form/CFormInputElement.php on line 217, 
referer: http://dev.DOMAIN.com/user/admin

What version of the product are you using? On what operating system?
v1.1.0, RHEL

Please provide any additional information below.

Tried specifying the path to a config array as in the example, now I'm 
trying just passing the config array straight in:

------------------------------------------------------------
        $formConfig = array(
            'elements'=>array(
                'user'=>array(
                    'type'=>'form',
                    'title'=>'Login Information',
                    'elements'=>array(
                        'username'=>array(
                            'type'=>'text',
                        ),
                        'password'=>array(
                            'type'=>'password',
                        ),
                    ),
                ),
                'person'=>array(
                    'type'=>'form',
                    'title'=>'Employee Information',
                    'elements'=>array(
                        'field1'=>array(
                            'type'=>'text',
                        ),
                        'field2'=>array(
                            'type'=>'text',
                        ),
                    ),
                ),
            ),

            'buttons'=>array(
                'register'=>array(
                    'type'=>'submit',
                    'label'=>'Register',
                ),
            ),
        );
        $form = new CForm($formConfig);
------------------------------------------------------------

Note that I am not passing my model as the 2nd param (again, as in the 
example). But if I pass in my model, the form works (but *only* for the 
model that is passed, i.e. - either the User portion renders, or the 
Profile portion renders, not both).

Example:
$form = new CForm($formConfig, $userModel);  // Produces a form working 
with User fields

Can anyone else replicate these issues?

Original issue reported on code.google.com by intel352 on 19 Feb 2010 at 10:24

GoogleCodeExporter commented 8 years ago
This belongs to core.

Original comment by qiang.xue on 19 Feb 2010 at 10:33

GoogleCodeExporter commented 8 years ago
It turns out, the documentation is wrong. You must specify an additional 
parameter of 'model' per each model's element 
set.

i.e.-
----------------------------------------------------------------
        $formConfig = array(
            'elements'=>array(
                'user'=>array(
                    'type'=>'form',
                    'title'=>'Login Information',
                    'elements'=>array(
                        'username'=>array(
                            'type'=>'text',
                        ),
                        'password'=>array(
                            'type'=>'password',
                        ),
                    ),
                    'model'=>new User,
                ),
                'person'=>array(
                    'type'=>'form',
                    'title'=>'Employee Information',
                    'elements'=>array(
                        'field1'=>array(
                            'type'=>'text',
                        ),
                        'field2'=>array(
                            'type'=>'text',
                        ),
                    ),
                    'model'=>new Person,
                ),
            ),

            'buttons'=>array(
                'register'=>array(
                    'type'=>'submit',
                    'label'=>'Register',
                ),
            ),
        );

Original comment by intel352 on 19 Feb 2010 at 10:35