Hi All,

I have a controller and view generated with Bake and has modified the
add function(). All seems well, but when I have empty data submitted
it returns :

Notice: Trying to get property of non-object in
C:\wamp\www\cake2\cake\libs\controller\controller.php on line 514

Fatal error: Cannot access empty property in
C:\wamp\www\cake2\cake\libs\controller\controller.php on line 514
0 query took ms

What's wrong ?

I attached my code here

============================================
User controller (add function)
============================================
function add() {
                $this->set('username_error', 'Please enter user name ');
                if (empty($this->data)) {
                        $this->render();
                } else {
                        
if($this->User->validates($this->data)&&!empty($this->data)):
                                $this->cleanUpFields();
                                
if($this->User->findByUsername($this->data['User']['username']))
                                {
                                        $this->User->invalidate('username');
                                        $this->set('username_error','User 
already exist');
                                }
                                else
                                {
                                        if ($this->User->save($this->data)) {
                                                $this->Session->setFlash('User 
has been saved');
                                                $this->redirect('/users/index');
                                        } else {
                                                
$this->Session->setFlash('Please correct errors below.');
                                        }
                                }
                        else:
                                $this->validateErrors($this->data);
                        endif;
                }
        }
============================================
User Model
============================================
<?php
class User extends AppModel
{
                var $name = 'User';

                var $validate = array(
                        'username' => VALID_NOT_EMPTY,
                        'useralias' => VALID_NOT_EMPTY
                );

                var $hasMany = array ('Product' => array(
                        'className' => 'Product',
                        'condition'=>null,
                        'order'=>null,
                        'foreignKey'=>'user_id')
                );
}
?>
============================================
add.thml view
============================================
<h2>New User</h2>
<form action="<?php echo $html->url('/users/add'); ?>" method="post">
<div class="required">
        <?php echo $form->labelTag('User/useralias', 'Useralias');?>
        <?php echo $html->input('User/useralias', array('size' => '60'));?>
        <?php echo $html->tagErrorMsg('User/useralias', 'Please enter the
Useralias.');?>
</div>
<div class="required">
        <?php echo $form->labelTag('User/username', 'Username');?>
        <?php echo $html->input('User/username', array('size' => '60'));?>
        <?php echo $html->tagErrorMsg('User/username', $username_error);?>
</div>
<div class="submit">
        <?php echo $html->submit('Add');?>
</div>
</form>
<ul class="actions">
<li><?php echo $html->link('List Users', '/users/index')?></li>
</ul>
============================================


Regards,

Feris

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to