Yii就地crud文本小部件

akr*_*ble 5 ajax jquery crud yii

我正在使用Yii框架为自己建立一个穷人的项目跟踪系统.目标是建立一个类似于basecamp的笔记小部件的"crud"小部件/窗体,以显示带有标题和内容字段笔记.(我不再使用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>
Run Code Online (Sandbox Code Playgroud)

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

<?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'),);
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

有没有人有什么建议?

Pen*_*m10 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/

您需要研究所有这些,并了解它们是如何工作的,因此您应该能够选择并扩展以满足您的需求。祝你好运。