12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace backend\forms;
- use Yii;
- use yii\base\Model;
- use components\Exception;
- /**
- * Class BaseForm
- * @package backend\forms
- */
- class BaseForm extends Model
- {
- public function handleError()
- {
- $errors = $this->getFirstErrors();
- $result = reset($errors);
- if (is_numeric($result)) {
- throw new Exception($result, \Yii::t('error', $result));
- } else {
- throw new Exception(1003, $result);
- }
- }
- /**
- * getConnect
- * @author: libingke
- * @return \PhpAmqpLib\Connection\AMQPStreamConnection
- * @throws Exception
- */
- public function getConnect()
- {
- try {
- return new \PhpAmqpLib\Connection\AMQPStreamConnection(
- Yii::$app->Amqp->host,
- Yii::$app->Amqp->port,
- Yii::$app->Amqp->user,
- Yii::$app->Amqp->pass,
- Yii::$app->Amqp->vhost
- );
- } catch (\Exception $e) {
- throw new Exception(1001, $e->getMessage());
- }
- }
- }
|