Source

zf-form-builder / www / system / library / ZendY / Form / Doctrine.php

<?php
class ZendY_Form_Doctrine extends ZendY_Form
{
    /**
     *
     * @var Neno_Service_Doctrine
     */
    protected $service = null;

    /**
     *
     * @var Doctrine_Record
     */
    protected $model = null;

    public function setModel(Doctrine_Record $model)
    {
        $this->model = $model;
        $this->populate($this->model->toArray());
    }

    public function create(Doctrine_Record $model = null)
    {
        if ($model) {
            $this->setModel($model);
        }
        return $this->service->create($this->getValues(), $model);
    }

    public function update(Doctrine_Record $model = null)
    {
        if ($model) {
            $this->setModel($model);
        }
        return $this->service->update($this->getValues(), $model);
    }

    public function save($model = null)
    {
        if ($model) {
            $this->setModel($model);
        }

        if ($this->model->exists()) {
            return $this->update();
        } else {
            return $this->create();
        }
    }
}