1 Answer
  • 1
name Punditsdkoslkdosdkoskdo

Yii in-place crud text widget

I'm using Yii framework to build myself a poor man's project tracking system. The goal is to have a in place "crud" widget/form that is similar to basecamp's note widget to display note(s) with a title and a content field. (I no longer use basecamp therefore cannot post the image of what their note widget looks like :-( )

Using Yii, I have a client model and I would like to display in a div all the notes corresponding to this client and have CRUD functionality for these notes right in the same webroot/client/view/client_id page.

The closest implementation I found online is done purely in jquery, jeditable, but lacks of create and delete functionality. Also, it has no Yii model (CActiveRecord) support, meaning one needs to hard-wire the data transmitted back and forth in controller code without taking advantage of Yii's MVC setup.

What I have now: A hidden form that's submitted via AJAX (forcCreation) and an Zii CListView widget (for Retrieve) of the note(s), which takes advantage of the built-in zii widget update functionality $.fn.yiiListView.update('clistview_id');, but I am rather stuck on the U and D part of the game using Yii/Zii widget, jquery, or a combination of those.

My client/view.php snippet:

<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 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(

A very simple Note Model:


 * 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'),);

Does anyone have any suggestions?

For start check out this, it helps you to understand how do you want:

after you understood, you need to create your own widget that does this

you can check out existing extensions that tries to do what you are after:

You need to study all these, and understand how they work, so you should be able to take one and extend to fit your needs. Good luck.

  • 0
Reply Report