Yii原地CRUD文本小部件

5
我正在使用Yii框架构建一个简易的项目跟踪系统。目标是拥有一个现成的“crud”小部件/表单,类似于basecamp的注释小部件,用于显示带有标题和内容字段的注释。(我不再使用basecamp,因此无法发布他们的注释小部件的图像 :-( )
使用Yii,我有一个客户端模型,我想在一个div中显示与该客户对应的所有注释,并在相同的webroot/client/view/client_id页面上为这些注释提供CRUD功能。
我在网上找到的最接近的实现纯粹是基于jquery的jeditable,但缺少创建和删除功能。另外,它没有Yii模型(CActiveRecord)支持,这意味着需要在控制器代码中硬编码来回传输数据,而无法利用Yii的MVC设置。
现有情况:一个通过 AJAX 提交的隐藏表单(forcCreation)和一个笔记的 Zii CListView 小部件(用于检索),利用内置的 Zii 小部件更新功能 $.fn.yiiListView.update('clistview_id');,但使用 Yii/Zii 小部件、jquery 或两者组合的 U 和 D 部分卡住了。
客户端/view.php 片段:
<div class="note_create">
    <?php echo CHtml::button('Add new note',array('class'=>'create-note-button')) ?>
    <div class="create-note-form" style="display: none;">
    <!-- _createNote is just a CActiveForm with a CHtml::ajaxSubmitButton-->
    <?php $this->renderPartial('_createNote', array('client' => $model, 'note' => $note)); ?>
    </div>
</div>
<div class="note_browser">
    <?php $this->widget('zii.widgets.CListView', array(
        'id' => 'clist_note_browser',
        'dataProvider' => $model->noteSearch(),
        'itemView' => '_note', // refers to the partial view named '_note'
        'emptyText' => 'No notes found.',
        'sortableAttributes' => array(
            'note.title',
            'note.last_modify'
        ),
        ));
    ?>
</div>

一个非常简单的笔记模型:
<?php

/**
 * This is the model class for table "note".
 *
 * The followings are the available columns in table 'note':
 * @property string $nid
 * @property string $title
 * @property string $content
 * @property string $first_create
 * @property string $last_modify
 *
 * The followings are the available model relations:
 * @property ClientNote $client  ClientNote an intermediate table with two columns: nid, cid
 */
class Note extends CActiveRecord
{
    ...
    public function relations()
    {   
        return array('client' => array(self::HAS_ONE, 'ClientNote', 'nid'),);
    }
    ...
}

有人有什么建议吗?


Yii的Gii模块有这种小部件(用于在模型生成中编辑表前缀和其他内容)。看一下它的代码。但我认为只支持UPDATE。 - dInGd0nG
1个回答

0

首先,查看这个内容,它可以帮助您了解您想要什么:

http://help.discretelogix.com/php/yii/enable-in-place-editing-in-yii-grid.htm

当你理解了之后,你需要创建自己的小部件来完成这个任务

你可以查看现有的扩展,尝试实现你想要的功能: http://www.yiiframework.com/extension/editablegridview/

http://yiitutorials.net/easy/creating-a-widget-with-the-yii-framework

http://www.yiiframework.com/extension/escrollablegridview/

你需要学习所有这些,并理解它们的工作原理,这样你就可以拿一个并扩展以适应你的需求。祝你好运。


太好了。我会学习所有这些内容,并希望很快向您报告它们如何一起运作!谢谢。 - akredible
嗯,我在想是否已经有一个小部件可以做我想要的事情...即使是Zend的也可以。由于项目时间限制(而且Cgridview可能不是显示注释的最佳小部件,我个人认为),不能花时间定制Cgridview以用作原地CRUD小部件。目前,我会选择原地CRD并在其自己的页面中更新注释。我计划在CListView的itemview中使用简单的ajaxbutton来实现D部分。 - akredible
能够使用上面提供的链接中的jeditable解决更新任务。删除任务比我预期的要容易,只需在项目视图(由CListView使用)中添加一个CHtml :: ajaxLink,并使用正确的数据(注意id)和成功回调来调用$.fn.yiiListView.update('clistview_id')以刷新CListView小部件。 - akredible

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接