Button not working on first click (afterSave)

I currently inherited a codebase using Yii Framework and MVC which I am not familiar with. The first small bug I am looking at is that the update slide button needs clicked twice.

The xml is sent to the machine and played in a browser on an android machine. I would go into more details but regardless of what I post it is saying this post is spam…

The code is as below.

protected function afterSave() {


        // Write XML Document

        // setup writer

        $writer = new XMLWriter();

        // Add path here

        $writer->openUri($this->getPath() . $this->title . '.xml');

        $writer->startDocument('1.0', 'UTF-8');




        $writer->writeAttribute('name', $this->title);

        $writer->writeAttribute('loop', $this->loop);

        $writer->writeAttribute('version', $this->version);

        $writer->writeAttribute('format', $this->format);

        $writer->writeAttribute('clear_cache', $this->clear_cache);

        $writer->writeComment(' Auto Generated on: ' . date(DATE_ISO8601));

        $writer->writeComment(' .');

        // FOR each slide in presentation


        // have sperate function caalls for each slide type..




        // Whitespacing parsing...

        //Put the XML file into a string

        file_put_contents($this->getPath() . $this->title . '.xml', trim(file_get_contents($this->getPath() . $this->title . '.xml')));


and the button


    $this->widget('bootstrap.widgets.TbButton', array(

        'buttonType' => 'submit',

        'type' => 'inverse',

        'label' => $model->isNewRecord ? 'Create' : 'Update Slide',

        'htmlOptions' => array(

            'class' => 'span3'