как передать данные в вид из copmonents

Общие вопросы по использованию второй версии фреймворка. Если не знаете как что-то сделать и это про Yii 2, вам сюда.
Ответить
vano.mig
Сообщения: 73
Зарегистрирован: 2016.11.21, 10:25

как передать данные в вид из copmonents

Сообщение vano.mig »

Добрый день.
Помогите решить проблему.
как передать данные из компонента в вид?

Код: Выделить всё

<?php
namespace app\components;

use app\models\Auth;
use app\models\User;
use Yii;
use yii\authclient\ClientInterface;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use yii\web\Controller;

/**
 * AuthHandler handles successful authentication via Yii auth component
 */
class AuthHandler
{
    /**
     * @var ClientInterface
     */
    private $client;

    public function __construct(ClientInterface $client)
    {
        $this->client = $client;
    }

    public function handle()
    {
        /*Sign in*/
        
            $attributes = $this->client->getUserAttributes();
            //debug($attributes); die();
            if (ArrayHelper::getValue($attributes, 'email') && ArrayHelper::getValue($attributes, 'email') != "")
            {
                $email = ArrayHelper::getValue($attributes, 'email');
                $id = ArrayHelper::getValue($attributes, 'id');
                $nickname = ArrayHelper::getValue($attributes, 'name');
                Yii::$app->getResponse()->redirect('sign', compact('email, nickname, id'));
                return $this->redirect('sign', compact('email, nickname, id'));
            }
            elseif (!ArrayHelper::getValue($attributes, 'email') || ArrayHelper::getValue($attributes, 'email') != "")
            {
                //debug($email); die();
                $id = ArrayHelper::getValue($attributes, 'id');
                if(ArrayHelper::getValue($attributes, 'name') && ArrayHelper::getValue($attributes, 'name') !="")
                {
                    //$id = ArrayHelper::getValue($attributes, 'id');
                    $nickname = ArrayHelper::getValue($attributes, 'name');
                    $email = "";
                }
                else 
                {
                    //$id = ArrayHelper::getValue($attributes, 'id');
                    $nickname = ArrayHelper::getValue($attributes, 'first_name');
                    $email = "";
                }
                //$nickname = ArrayHelper::getValue($attributes, 'name');
                Yii::$app->getResponse()->redirect('sign', ['email' => $email, 'nickname' => $nickname, 'id' => $id]);
                return $this->redirect('sign', compact('email, nickname, id'));
      }
  
ругается что неопределенный метод $this->redirect()
Аватара пользователя
Dominus
Сообщения: 892
Зарегистрирован: 2013.03.14, 21:27
Откуда: Россия, Иваново
Контактная информация:

Re: как передать данные в вид из copmonents

Сообщение Dominus »

vano.mig писал(а): 2017.08.10, 09:46 ругается что неопределенный метод $this->redirect()

Код: Выделить всё

return Yii::$app->getResponse()->redirect('sign', ['email' => $email, 'nickname' => $nickname, 'id' => $id]);
//return $this->redirect('sign', compact('email, nickname, id'));
Или определять метод

Код: Выделить всё

public function redirect($params=[])
{
 return  Yii::$app->response->redirect($params);
}
Как то так.
Не спорь с дураком, иначе окружающие не правильно поймут кто из вас дурак!
vano.mig
Сообщения: 73
Зарегистрирован: 2016.11.21, 10:25

Re: как передать данные в вид из copmonents

Сообщение vano.mig »

спасибо!
Ответить