0

Как получить из объекта $comment->date значение date.

Модель Comment https://github.com/Holland-Store/crm/blob/development/frontend/models/Comment.php

 public function getByIdNotificationComments($id, $comment, $id_sotrud_put,$zakaz)
    {

    switch ($id) {
        case '1'://оформление уведомление о новом комментарии к созданной задача
            $this->id_user = $id_sotrud_put->id_sotrud_put;
            $this->name = substr($comment->date.'Комментарий к созданной задаче '.$id_sotrud_put->comment , 0, 120) . '...' ;
            $this->todoist_id = $comment->id_todoist;
            $this->category = 2;
            break;


public function actionTodoist($id)
    {
        $commentForm = new Comment();
        $telegram = new Telegram();
        $todoist = Todoist::findOne($id);
        $user = Yii::$app->user->id;
        $notification = new Notification();
        if ($commentForm->load(Yii::$app->request->post())){
            $commentForm->id_todoist = $id;
            $commentForm->id_user = Yii::$app->user->id;
            if (!$commentForm->save()){
                print_r($commentForm->getErrors());
            } else {
                var_dump($commentForm);
                if ($todoist->id_sotrud_put != $user){                 //уведомление кто назначил задачу
                    $notification->getByIdNotificationComments( '1', $commentForm, $todoist,$zakaz= null);
                    $notification->getSaveNotification();

Значение полученные из var_dump($commentForm);

object(app\models\Comment)[134]
  private '_attributes' (yii\db\BaseActiveRecord) => 
    array (size=4)
      'comment' => string 'fgfgf' (length=5)
      'id_todoist' => string '77' (length=2)
      'id_user' => int 4
      'id' => int 399
  private '_oldAttributes' (yii\db\BaseActiveRecord) => 
    array (size=4)
      'comment' => string 'fgfgf' (length=5)
      'id_todoist' => string '77' (length=2)
      'id_user' => int 4
      'id' => int 399
  private '_related' (yii\db\BaseActiveRecord) => 
    array (size=0)
      empty
  private '_errors' (yii\base\Model) => 
    array (size=0)
      empty
  private '_validators' (yii\base\Model) => 
    object(ArrayObject)[149]
      private 'storage' => 
        array (size=8)
          0 => 
            object(yii\validators\NumberValidator)[152]
              public 'integerOnly' => boolean true
              public 'max' => null
              public 'min' => null
              public 'tooBig' => null
              public 'tooSmall' => null
              public 'integerPattern' => string '/^\s*[+-]?\d+\s*$/' (length=18)
              public 'numberPattern' => string '/^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s*$/' (length=48)
              public 'attributes' => 
                array (size=8)
                  0 => string 'id_user' (length=7)
                  1 => string 'sotrud' (length=6)
                  2 => string 'id_zakaz' (length=8)
                  3 => string 'id_todoist' (length=10)
                  4 => string 'id_helpdesk' (length=11)
                  5 => string 'notice_id' (length=9)
                  6 => string 'category' (length=8)
                  7 => string 'date' (length=4)
              public 'message' => string 'Значение «{attribute}» должно быть целым числом.' (length=79)
5
  • Доброе утро. В каком формате у Вас $comment->date?
    – user216615
    19 апр 2018 в 8:45
  • @slo_nik у меня $comment берется при передаче объекта $commentForm . $commentForm = new Comment(); Comment - Это модельный класс для таблицы «comment».
    – Silverfire
    19 апр 2018 в 8:51
  • я понимаю, но как дата выглядит?
    – user216615
    19 апр 2018 в 9:09
  • @slo_nik 2018-04-19 11:20:18
    – Silverfire
    19 апр 2018 в 9:20
  • читайте ответ, используйте formatter. yiiframework.com/doc/api/2.0/yii-i18n-formatter
    – user216615
    19 апр 2018 в 9:32

1 ответ 1

0

Доброе утро.

$comment->date строка? В виде "02-04-2018"

Yii::$app->formater->asDate(strtotime($comment->date), 'php: d'); // только день
Yii::$app->formater->asDate(strtotime($comment->date), 'php: m'); // только месяц
Yii::$app->formater->asDate(strtotime($comment->date), 'php: Y'); // только год
1
  • У меня в модели так же не было прописано ['date', 'default', 'value' => date('Y-m-d H:i:s')], . Поэтому я и не мог получить значения.
    – Silverfire
    28 апр 2018 в 7:37

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.