【问题标题】:Yii in-place crud text widgetYii 就地 crud 文本小部件
【发布时间】:2012-10-06 06:18:16
【问题描述】:

我正在使用 Yii 框架为自己构建一个穷人的项目跟踪系统。目标是有一个类似于basecamp's note 小部件的“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 sn-p:

<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

标签: jquery ajax yii crud


【解决方案1】:

首先看看这个,它可以帮助你了解你想要什么:

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/

您需要研究所有这些,并了解它们的工作原理,因此您应该能够学习并扩展以满足您的需求。祝你好运。

【讨论】:

  • 太棒了。我会研究所有这些,并希望尽快报告他们是如何一起工作的!谢谢。
  • 嗯,我想知道是否已经有一个小部件正在做我所追求的......即使是 Zend 也可以。不能花时间为就地 crud 小部件定制 Cgridview 作为项目时间限制(Cgridview 也可能不是显示笔记的最佳小部件,IMO)。现在,我会选择就地 CRD 并在其自己的页面中更新注释。我打算在 CListView 的 itemview 中用一个简单的 ajaxbutton 来实现 D 部分。
  • 能够使用上面提供的link@pentium10 中的 jeditable 来解决更新任务。删除任务比我预期的要容易,通过将 CHtml::ajaxLink 添加到项目视图(由 CListView 使用)和正确的数据(注释 id)和调用 $.fn.yiiListView.update('clistview_id') 以刷新 CListView 小部件的成功回调
猜你喜欢
  • 1970-01-01
  • 2013-04-27
  • 2015-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-10
  • 2011-11-05
相关资源
最近更新 更多