The DDNotes extension provides a behaviour for a CActiveRecord to show notes attached to the record and to add new notes.
All notes are stored in one database table.
Requirements ¶
- Yii Framework 1.1 or above (tested with V1.1.8)
- Having authentificated users (see Yii blog demo)
Installation ¶
Extract the downloaded extension archive under the extensions
directory.
Create the neccessary table for the notes items. Run the schema_sqlite.sql
against your database.
Optionally, move the message files in extensions/ddnotes/messages
to your protected/messages
tree.
Usage ¶
Model ¶
Include the DDNotes
behavior in your model class:
// {{{ behaviors
public function behaviors()
{
return array(
...
'notesBehaviour' => array(
'class' => 'application.extensions.ddnotes.DDNotesBehavior',
),
...
);
} // }}}
Views ¶
In your _form
view, add this code:
$this->renderPartial(
'application.extensions.ddnotes.views.notes',
array(
'model'=>$model,
'form'=>$form
)
);
This will show a list off all notes attached to the current record, and also a small form snippet to add a new note.
In your item view
template, add this code:
[html]
<div id="comments" style="margin-bottom:10px;">
<?php if($model->notesCount>=1): ?>
<h3>
<?php echo CHtml::encode(Yii::t('ddnotes',
'1#One note for item {recordName}|n>1#{notesCount} notes for item {recordName}',
array(
$model->notesCount,
'{notesCount}'=>$model->notesCount,
'{recordName}'=>$model->recordName))); ?>
</h3>
<?php $this->renderPartial('application.extensions.ddnotes.views._notes',
array(
'model'=>$model,
)); ?>
<?php else : ?>
<?php echo CHtml::encode(Yii::t('ddnotes','No notes yet.')); ?>
<?php endif; ?>
</div><!-- }}} End Notes -->
This will display a list of the notes attached to the currently displayed record.
Resources ¶
History ¶
- 2011-09-29
V0.1 Initial version
Problems with timestamps
I solved these by implementing CTimestampBehavior on DDNotesBehavior:
//DDNote.php public function behaviors(){ return array( 'CTimestampBehavior' => array( 'class' => 'zii.behaviors.CTimestampBehavior', 'createAttribute' => 'tsCreated', 'updateAttribute' => 'tsUpdated', ) ); } //_notes.php use this instead Yii::app()->dateFormatter->formatDateTime(strtotime($note->tsCreated),'medium','short')
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.