Logs.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "os_logs".
  6. *
  7. * @property int $id
  8. * @property string $date
  9. * @property string $section
  10. * @property string $error_text
  11. */
  12. class Logs extends \yii\db\ActiveRecord
  13. {
  14. /**
  15. * {@inheritdoc}
  16. */
  17. public static function tableName()
  18. {
  19. return 'os_logs';
  20. }
  21. public static function getDb()
  22. {
  23. return \Yii::$app->slave_db;
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['date'], 'safe'],
  32. //[['section', 'error_text'], 'required'],
  33. [['error_text'], 'string'],
  34. //[['section'], 'integer'],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'date' => 'Date',
  45. 'section' => 'Section',
  46. 'error_text' => 'Error Text',
  47. ];
  48. }
  49. public static function addlog($section,$text) {
  50. $logsModel = new Logs();
  51. $logsModel->section = $section;
  52. $logsModel->error_text = $text;
  53. $logsModel->save();
  54. //var_dump($logsModel->errors);
  55. }
  56. public function addlogText($er_text = '',$su_text = '', $section = '') {
  57. if ( null == $this->section) {
  58. $this->section = $section;
  59. }
  60. $logsModel = new Logs();
  61. $logsModel->index_t = $this->index_t;
  62. $logsModel->section = $this->section;
  63. $logsModel->error_text = $er_text;
  64. $logsModel->success_text = $su_text;
  65. $logsModel->save();
  66. }
  67. }