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\web\organization\Module; |
16
|
|
|
use Yii; |
17
|
|
|
use yii\base\Action; |
18
|
|
|
use yii\web\UnauthorizedHttpException; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class ExitAction |
22
|
|
|
* @package rhosocial\organization\web\organization\controllers\my |
23
|
|
|
* @version 1.0 |
24
|
|
|
* @author vistart <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class ExitAction extends Action |
27
|
|
|
{ |
28
|
|
|
public $exitSuccessMessage; |
29
|
|
|
public $exitFailedMessage; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Initialize messages. |
33
|
|
|
*/ |
34
|
|
|
protected function initMessages() |
35
|
|
|
{ |
36
|
|
|
if (!is_string($this->exitSuccessMessage) || empty($this->exitSuccessMessage)) { |
37
|
|
|
$this->exitSuccessMessage = Yii::t('organization', 'Exited.'); |
38
|
|
|
} |
39
|
|
|
if (!is_string($this->exitFailedMessage) || empty($this->exitFailedMessage)) { |
40
|
|
|
$this->exitFailedMessage = Yii::t('organization', 'Failed to exit.'); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @inheritdoc |
46
|
|
|
*/ |
47
|
|
|
public function init() |
48
|
|
|
{ |
49
|
|
|
$this->initMessages(); |
50
|
|
|
parent::init(); |
51
|
|
|
} |
52
|
|
|
/** |
53
|
|
|
* Run action |
54
|
|
|
* @param $id |
55
|
|
|
* @return \yii\web\Response |
56
|
|
|
* @throws UnauthorizedHttpException |
57
|
|
|
*/ |
58
|
|
|
public function run($id) |
59
|
|
|
{ |
60
|
|
|
$organization = Module::getOrganization($id); |
61
|
|
|
try { |
62
|
|
|
if ($organization->removeMember(Yii::$app->user->identity)) { |
63
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_SUCCESS); |
64
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, $this->exitSuccessMessage); |
65
|
|
|
return $this->controller->redirect(['index']); |
|
|
|
|
66
|
|
|
} else { |
67
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_FAILED); |
68
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, $this->exitFailedMessage); |
69
|
|
|
} |
70
|
|
|
} catch (\Exception $ex) { |
71
|
|
|
throw new UnauthorizedHttpException($ex->getMessage()); |
72
|
|
|
} |
73
|
|
|
return $this->controller->redirect(['index']); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
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: