Строим Wiki
Установим плагині:
>symfony plugin-install http://plugins.symfony-project.com/sfPropelVersionableBehaviorPlugin
>symfony plugin-install http://plugins.symfony-project.com/sfAdvancedAdminGeneratorPlugin
В конце файла config/propel.ini изменим:
propel.builder.addBehaviors = true
Изменим модель
propel:
article:
id: ~
title: varchar(255)
body: longvarchar
version: integer
updated_at: ~
>symfony propel-build-all
В конце файла lib/model/Article.php добавим:
sfPropelBehavior::add('Article', array('versionable'));
>symfony clear-cache
http://localhost/frontend_dev.php
Построим админку:
> symfony propel-init-admin frontend wiki Article
Генерим форму apps/frontend/modules/wiki/config/generator.yml :
generator:
class: sfAdvancedAdminGenerator
param:
model_class: Article
theme: default
list:
title: List of Articles
sort: title
click_action: show
display: [=title, updated_at]
filters: [title, updated_at]
object_actions:
_show: { name: View Article }
_edit: { name: Edit Article }
show:
actions:
_list: { name: Back to the list }
_edit: { name: Edit Article }
edit:
fields:
updated_at: { type: plain }
version: { type: plain }
body: { params: size=80x15 }
actions:
_save: { name: Save modifications }
_show: { name: View Article }
_list: { name: Back to the list }
_delete: { name: Delete Article }
http://localhost/frontend_dev.php/wiki
wiki сохраняет все версии документа. Для их просмотра необходимо действие apps/frontend/modules/wiki/actions/actions.class.php:
public function executeHistory()
{
$this->article = $this->getArticleOrCreate();
}
И template для истлрии. apps/frontend/modules/wiki/templates/historySuccess.php:
<?php use_stylesheet('/sf/sf_admin/css/main') ?>
<div id="sf_admin_container">
<h1><?php echo sprintf('History of "%s" modifications', $article->getTitle()) ?></h1>
<div id="sf_admin_content">
<?php foreach ($article->getAllResourceVersions('desc') as $resourceVersion): ?>
<div class="form-row">
<?php echo sprintf("'%s', Version %d, updated on %s (%s)\n",
link_to($resourceVersion->getTitle(), 'wiki/show?id='.$article->getId().'&version='.$resourceVersion->getNumber()),
$resourceVersion->getNumber(),
$resourceVersion->getCreatedAt(),
$resourceVersion->getComment()
) ?>
</div>
<?php endforeach; ?>
<ul class="sf_admin_actions">
<li><?php echo button_to('Show Article', 'wiki/show?id='.$article->getId(), 'class=sf_admin_action_show') ?></li>
<li><?php echo button_to('Edit Article', 'wiki/edit?id='.$article->getId(), 'class=sf_admin_action_edit') ?></li>
</ul>
</div>
</div>
http://localhost/frontend_dev.php/wiki/history/id/1
Перепишем класс действий
protected function getArticleOrCreate($id = 'id')
{
$article = parent::getArticleOrCreate($id);
if($this->getRequest()->hasParameter('version'))
{
$article->toVersion($this->getRequest()->getParameter('version'));
}
return $article;
}
В форме добавим поле:
_history: { name: History }
Комментариев нет:
Отправить комментарий