yiiext/status-behavior
最新稳定版本:0.7
Composer 安装命令:
composer require yiiext/status-behavior
包简介
Yii Framework Active Record Status behavior for models
README 文档
README
Can be used with models to add functions to manage model status.
Installing and configuring
Add field to model and DB table. Field status is used as example.
Field type depends on behavior configuration.
Configure model:
<?php class Post extends CActiveRecord { public function behaviors() { return array( 'statuses' => array( 'class' => 'ext.yiiext.behaviors.model.status.EStatusBehavior', // Field used for status 'statusField' => 'status', // Allowed statuses. Default is array('draft', 'published', 'archived'). // One can pass an array where key is DB field name, value is what user will see. // 'statuses' => array('draft', 'published', 'archived'), // 'statuses' => array('d' => 'draft', 'p' => 'published', 'a' => 'archived'), ), ); } }
Examples
Configuring models
<?php class Post extends CActiveRecord { public function behaviors() { return array( 'statuses' => array( 'class' => 'ext.CStatusBehavior.CStatusBehavior', 'statusField' => 'status', ), ); } } class Book extends CActiveRecord { public function behaviors() { return array( 'statuses' => array( 'class' => 'ext.CStatusBehavior.CStatusBehavior', 'statusField' => 'status', 'statuses' => array( 'new' => 'new', 'reserved' => 'reserved', 'sale' => 'sale', ), ), ); } }
Using statuses
<?php $post=Post::model()->findByPk(1); // Getting current status echo $post->getStatus(); // Changing status $post->setStatus('draft'); // Saving model if ($post->save() === FALSE) { echo 'Error!'; } $post = Post::model()->findByPk(1); // Changing status field only $post->setStatus('draft')->saveStatus();
统计信息
- 总下载量: 2.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 0
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2014-03-24