You don't need the prepareData
method in your code. Your model should look something like this:
<?php
class Model_Post extends Model_Table {
public $table='posts';
public $entity_code='posts';
public $id_field='slug';
function init(){
parent::init();
$this->addField('slug')->caption('Ссылка')->mandatory(true);
$this->addField('author')->setValueList($user)->caption('Автор')->mandatory(true);
$this->addField('category')->setValueList($category)->caption('Категория')->mandatory(true);
//$this->addField('previewIMG')->setModel("filestore/Model_Image")->type("file")->caption('Изображение');
$this->addField('title')->caption('Заголовок')->mandatory(true);
$this->addField('date')->type('date')->defaultValue(date('Ymd'))->caption('Дата')->mandatory(true);
$this->addField('body')->type('text')->caption('Текст поста')->mandatory(true);
$this->addField('published')->type('boolean')->caption('Опубликовать');
}
}
There are several ways to display all these fields on the page. If you want to input values from user
Way # 1
: Form
$f = $this->add('Form');
$f->setModel('Post');
$f->addSubmit();
Way # 2
: Grid
$this->add('Grid')->setModel('Post');