1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* _ __ __ _____ _____ ___ ____ _____ |
5
|
|
|
* | | / // // ___//_ _// || __||_ _| |
6
|
|
|
* | |/ // /(__ ) / / / /| || | | | |
7
|
|
|
* |___//_//____/ /_/ /_/ |_||_| |_| |
8
|
|
|
* @link https://vistart.me/ |
9
|
|
|
* @copyright Copyright (c) 2016 - 2017 vistart |
10
|
|
|
* @license https://vistart.me/license/ |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace rhosocial\organization\web\organization\controllers\my; |
14
|
|
|
|
15
|
|
|
use rhosocial\organization\forms\SetUpForm; |
16
|
|
|
use rhosocial\organization\web\organization\Module; |
17
|
|
|
use Yii; |
18
|
|
|
use yii\base\Action; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @version 1.0 |
22
|
|
|
* @author vistart <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class SetUpOrganizationAction extends Action |
25
|
|
|
{ |
26
|
|
|
public $organizationSetUpSuccessMessage; |
27
|
|
|
public $organizationSetUpFailedMessage; |
28
|
|
|
|
29
|
|
|
protected function initMessages() |
30
|
|
|
{ |
31
|
|
|
if (!is_string($this->organizationSetUpSuccessMessage)) { |
32
|
|
|
$this->organizationSetUpSuccessMessage = Yii::t('organization' ,'Organization Set Up.'); |
33
|
|
|
} |
34
|
|
|
if (!is_string($this->organizationSetUpFailedMessage)) { |
35
|
|
|
$this->organizationSetUpFailedMessage = Yii::t('organization', 'Organization Set Up Failed.'); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function init() |
40
|
|
|
{ |
41
|
|
|
$this->initMessages(); |
42
|
|
|
parent::init(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function run() |
46
|
|
|
{ |
47
|
|
|
$model = new SetUpForm(['user' => Yii::$app->user->identity]); |
48
|
|
|
if ($model->load(Yii::$app->request->post())) { |
49
|
|
|
try { |
50
|
|
|
if (($result = $model->setUpOrganization()) === true) { |
51
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_SUCCESS); |
52
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, '(' . $model->getUser()->lastSetUpOrganization->getID() . ') ' . $this->organizationSetUpSuccessMessage); |
53
|
|
|
return $this->controller->redirect(['index']); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
if ($result instanceof \Exception) { |
56
|
|
|
throw $result; |
57
|
|
|
} |
58
|
|
|
} catch (\Exception $ex) { |
59
|
|
|
Yii::error($ex->getMessage(), __METHOD__); |
60
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_FAILED); |
61
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, $this->organizationSetUpFailedMessage); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
return $this->controller->render('set-up-organization', ['model' => $model]); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: