srs81 / CakePHP-AjaxMultiUpload

CakePHP 2 plugin to allow for easy multi-file upload with AJAX
Other
65 stars 33 forks source link

Subfolder - ID Problem #27

Closed deadsoulja closed 11 years ago

deadsoulja commented 11 years ago

Hi, I've got the same problem as here: https://github.com/srs81/CakePHP-AjaxMultiUpload/issues/1

the only difference is, that i use no companies, i want to use users, so that the users can upload files. the plugin should create subfolders with the users id but it doesn't.

also i got the error message: Notice (8): Undefined index: User.id [APP/View/User/edit.ctp, line 138] where I have the code: echo $this->Upload->edit('User', $this->Form->fields['User.id']);

id is the primary key of the table user and i use scaffold function. but i created the edit view.

i have tried the same with customers (every user can create customers so 1:n) and there it works great. the subfolders are created and i can see only the files which are in the subfolder with my id.

don't know why it doesn't work with users. need help please.

srs81 commented 11 years ago

Are you sure User has an id field?

deadsoulja commented 11 years ago

yes definetly. the user table has an id field. it is auto increment so it is filled automatically.

deadsoulja commented 11 years ago

any ideas?

deadsoulja commented 11 years ago

echo $this->Form->create('User'); echo $this->Form->input('User.id', array('type' => 'hidden')); echo $this->Form->hidden('user_id', array('value' => $user_id)); echo $this->Form->input('email', array('label' => 'E-mail')); echo $this->Form->input('firstname', array('label' => 'First Name')); echo $this->Form->input('lastname', array('label' => 'Surname'));

echo $this->Form->end('Save'); echo '

'; echo $this->Upload->edit('User', $this->Form->fields['User.user_id']); echo '

'; echo $user_id; echo '

'; echo $user_group; debug($this->Form->fields);

mybe you can have a look at the code. echo $user_id gives out the right user id, also echo $user_group gives me the right user-group but debug($this->Form->fields) gives me an empty array, i just don't know why.

thanks for your help.

srs81 commented 11 years ago

Note this:

echo $this->Form->input('User.id', array('type' => 'hidden'));

and this:

echo $this->Upload->edit('User', $this->Form->fields['User.user_id']);

You are using id and _userid in two different places - shouldn't it be just id in the second place?

deadsoulja commented 11 years ago

it really doesn't matter because in customer it works perfectly. here the code from the customer view: echo $this->Form->create('Customer'); echo $this->Form->input('Customer.id', array('type' => 'hidden')); echo $this->Form->hidden('user_id', array('value' => $user_id)); echo $this->Form->input('company'); echo $this->Form->input('street_number', array('label' => 'Street')); echo $this->Form->input('postcode'); echo $this->Form->input('city');

echo $this->Upload->edit('Customer', $this->Form->fields['Customer.user_id']); echo '

'; debug($this->Form->fields);

the debug gives me a filled array with all the customer data including Customer.id and user_id

here the code from customer controller: public function beforeFilter() { $this->set('user_id',$this->Auth->user('User.id')); }

and the edit function: public function edit() { //get the id of the Customer to be edited $id = $this->request->params['pass'][0];

//set the customer id
$this->Customer->id = $id;

//check if a customer with this id really exists
if( $this->Customer->exists() ){

    if( $this->request->is( 'post' ) || $this->request->is( 'put' ) ){
        //save customer
        if( $this->Customer->save( $this->request->data ) ){

            //set to user's screen
            $this->Session->setFlash('Customer was edited.');

            //redirect to customer's list
            $this->redirect(array('action' => 'index'));

        }else{
            $this->Session->setFlash('Unable to edit customer. Please, try again.');
        }

    }else{

        //we will read the customer data
        //so it will fill up our html form automatically
        $this->request->data = $this->Customer->read();
    }

}else{
    //if not found, we will tell the user that customer does not exist
    $this->Session->setFlash('The customer you are trying to edit does not exist.');
    $this->redirect(array('action' => 'index'));

    //or, since it we are using php5, we can throw an exception
    //it looks like this
    //throw new NotFoundException('The user you are trying to edit does not exist.');
}

i've got the same function in the users controller as the edit function: public function edit() { //get the id of the User to be edited $id = $this->request->params['pass'][0]; //pr($id); //set the User id $this->User->id = $id;

//check if a User with this id really exists
if( $this->User->exists() ){

    if( $this->request->is( 'post' ) || $this->request->is( 'put' ) ){
        //save User
        if( $this->User->save( $this->request->data ) ){

            //set to user's screen
            $this->Session->setFlash('User was edited.');

            //redirect to User's list
            $this->redirect(array('action' => 'index'));

        }else{
            $this->Session->setFlash('Unable to edit User. Please, try again.');
        }

    }else{

        //we will read the User data
        //so it will fill up our html form automatically
        $this->request->data = $this->User->read();
    }

}else{
    //if not found, we will tell the user that User does not exist
    $this->Session->setFlash('The User you are trying to edit does not exist.');
    $this->redirect(array('action' => 'index'));

    //or, since it we are using php5, we can throw an exception
    //it looks like this
    //throw new NotFoundException('The user you are trying to edit does not exist.');
}

}

mybe the code is useful for you. the functions are working correctly, just don't know where the error comes from and it's really getting me crazy :)

deadsoulja commented 11 years ago

it works now.

i've changed this: echo $this->Upload->edit('User', $this->Form->fields['User.user_id']);

to this: echo $this->Upload->edit('User', $user_id);