StaticBlock.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. namespace fecshop\models\mongodb\cms;
  10. use yii\mongodb\ActiveRecord;
  11. /**
  12. * @author Terry Zhao <2358269014@qq.com>
  13. * @since 1.0
  14. */
  15. class StaticBlock extends ActiveRecord
  16. {
  17. /**
  18. * mongodb collection 的名字,相当于mysql的table name
  19. */
  20. public static function collectionName()
  21. {
  22. return 'static_block';
  23. }
  24. /**
  25. * mongodb是没有表结构的,因此不能像mysql那样取出来表结构的字段作为model的属性
  26. * 因此,需要自己定义model的属性,下面的方法就是这个作用
  27. */
  28. public function attributes()
  29. {
  30. return [
  31. '_id',
  32. 'title',
  33. 'identify',
  34. 'status',
  35. 'content',
  36. 'created_at',
  37. 'updated_at',
  38. 'created_user_id',
  39. ];
  40. }
  41. /**
  42. * 给model对应的表创建索引的方法
  43. * 在indexs数组中填写索引,如果有多个索引,可以填写多行
  44. * 在migrate的时候会运行创建索引,譬如:
  45. * @fecshop/migrations/mongodb/m170228_072455_fecshop_tables
  46. */
  47. public static function create_index()
  48. {
  49. $indexs = [
  50. ['identify' => -1],
  51. ];
  52. $options = ['background' => true];
  53. foreach ($indexs as $columns) {
  54. self::getCollection()->createIndex($columns, $options);
  55. }
  56. }
  57. }