Cakephp Model Saving Data Twice

579 views Asked by At

I am using the version Cakephp 2.9.3 and when I am saving the data by using save method of the model, the data is being saved twice in my database table but I have checked that the save call is triggered only once.

Here is the code for my Controller:

App::uses('AppController', 'Controller');
App::uses('Log', 'Model');

class DashboardController extends AppController {

    public function index() {
        $data = array(
            'type' => 'subscribers_log',
            'message' => 'sample text',
            'ip' => '127.0.0.1',
            'hostname' => 'finakle.com',
            'uri' => '/'
        );

        $log = new Log;
        $log->save($data);
    }

}

Here is the sample screenshot of my database table:

Database Image Screenshot

1

There are 1 answers

0
Kishen Nagaraju On BEST ANSWER

I had built a custom layout for the application and further analyzed that in my layout file I was playing a video file using normal HTML tags. This somehow was causing the issue. Below mentioned is the code:

<div class="hero-video">
    <video autoplay muted="muted" loop="loop" poster="#" id="hero_video">
        <source src="resources/images/New/In-And-Out.mp4" type="video/mp4" />
        <source src="resources/images/New/In-And-Out.webm" type="video/webm" />
    </video>
</div>

But then I changed the code to include the video file through cakephp media tag as shown below:

<div class="hero-video">
    <?php echo $this->Html->media(
        array(
            'In-And-Out.mp4',
            array(
                'src' => 'In-And-Out.webm',
                'type' => "video/webm"
            )
        ),
        array(
            'autoplay' => 'true',
            'muted' => 'muted',
            'loop' => 'loop',
            'poster' => '#',
            'id' => 'hero_video'
        )
    ); ?>
</div>

This resolved my issue.