Monday, November 2, 2015

Re: Cakephp Inline Editing

Aha Thanks for the help.

I'm working on function add()

I'm trying to get user input and calculate hours from the start and stop date provided by the users. I'm not able to have the calculated $hours to save in the database together with rest of the user inputs.

           $starttime = $this->request->data['Leave']['event_date'];
            $endtime = $this->request->data['Leave']['event_stop_time'];
            $lunch = $this->request->data['Leave']['lunch_break'] * 60; //lunch break in seconds
                                       
               
            $start = strtotime($starttime); //Convert to unix time
            $end = strtotime($endtime); //Convert to unix time             
            $hours = ($end - $start - $lunch)/60/60;   
          ----------------------------------------------------------

When i use this
        if ($this->Leave->saveAll($this->request->data)) {   
                $this->Session->setFlash(__('The leave has been saved'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The leave could not be saved. Please, try again.'));
            }

    The hours field is not updated. I have no idea how to save the $hours together with other user inputs. Any help is much appreciated

Thanks
Para

     

On Sat, Oct 24, 2015 at 6:56 AM, John Andersen <j.andersen.lv@gmail.com> wrote:
In your code you are already using $stop as an array:

        $this->set('stop',$stop['Leave']['event_stop_time']);

so when you try to calculate the $hours, then you have an array - a value :)

Try and fix that!
Enjoy, John


On Friday, 23 October 2015 12:43:47 UTC+3, Para K wrote:
I'm working on a project for Payroll Dept. I have included inline editing feature in my code.

When the user edits start date, the program should calculate and update the hours field by subtracting the stop date from start date. I'm stuck on the calculation part giving an error "Unsupported Operand Types". Below is my code snippet

case 'event_date':
           
             if ($this->request->data['Leave']['event_date'] == $value) {
                   
                    $stop = $this->Leave->find('first', array('conditions' => array('event_date' => $value)));
                    $this->set('stop',$stop['Leave']['event_stop_time']);
                   
                    $start = $this->request->data['Leave']['event_date'];
                                   
                    $hours = ($stop - $start);
                    $this->request->data['Leave']['hours'] = $hours;
                    $this->set('updated_value', $hours);
               
             }

Any form of help is much appreciated as I'm a newbie to cakephp

Thanks

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: