yii2

yii2 Webhook post empty

醉酒当歌 提交于 2019-12-07 08:42:44
问题 I am kinda new to the yii FrameWork, and i need help. i need to implement a stripe webhook controller that is used for the subscription event sent by Stripe. For this controller, there is no view nor model I can access to the controller, but the $_POST content is empty and i cannot figure why. Is it possible to use the post verb without a view ? here's an example : class StripeWebhookController extends Controller { public function beforeAction($action) { if ($action->id == 'index') { $this-

Forbidden (#403) - You are not allowed to perform this action [Yii2]

本小妞迷上赌 提交于 2019-12-07 07:59:04
问题 I've tried to add menu map in backend-side. I use yii2-advanced . This is my “controller” code: public function actionMap() { return $this->render('map'); } But, when I try to access it with this url http://localhost/yii2advanced/backend/web/index.php?r=site/map , I've got error message Forbidden (#403) - You are not allowed to perform this action . I don't understand why I got this error message, can anybody help me to fix this problem? 回答1: It's caused by AccessControl. Most likely the

IIS and Yii2 pretty URL

那年仲夏 提交于 2019-12-07 06:13:45
问题 What is the .htaccess equivalent for IIS to enable pretty URLs in Yii2 on IIS. Indeed, I don't know what could I do with web.conf to allow those URLs. 回答1: try this on your web.config and save it on the root <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <directoryBrowse enabled="false" /> <rewrite> <rules> <rule name="Hide Yii Index" stopProcessing="true"> <match url="." ignoreCase="false" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile"

Yii2 custom sql query in gridview

走远了吗. 提交于 2019-12-07 05:09:41
问题 I'm quite new to Yii2. I'm using advanced structure I need to show a custom sql result in a view without using a model because I would like to display a sql view. index.php <?= GridView::widget([ 'dataProvider' => $dataProvider, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], 'COD_RISORSA', [ 'label' =>"Nome", 'attribute' => 'NOME', 'value'=>function($data){ return $data["NOME"]; } ], 'COGNOME', ['class' => 'yii\grid\ActionColumn'], ], ]); ?> VRisorseController.php public function

Yii2: How to allow CORS on non-restfull API

冷暖自知 提交于 2019-12-07 04:47:45
问题 I am working with a pre-built API (not restfull) on Yii2 Framework. It responds with JSON data and accepts requests depending on User type and credential token. Now I have to make an app that is on a different location (domain) which is causing CORS conflict. My app is jQuery and I'm using $.ajax for data sending and receiving. How can I avoid this CORS conflict and use the API over ajax? Regards UPDATE: As IStranger told me in his answer I added the following code: public function behaviors(

Creating yii2 dynamic pages with url: www.example.com/pageName

心不动则不痛 提交于 2019-12-07 04:40:56
问题 In my system, users need to have their profile pages. It is requested from me that these pages will be displayed in url like this: www.example.com/John-Doe www.example.com/Mary-Smith How to achieve these URLs in yii2 ? These John-Doe and Mary-Smith can be user usernames or profile names. For example I have field in user table called "name" and it will hold names "John Doe", "Mary Smith". Pay attention that I need SEO friendly URLs with "-" instead of blank spaces. URLs like this: www.example

yii2 deny user login on backend

淺唱寂寞╮ 提交于 2019-12-07 04:29:31
问题 I have yii2 advance template with RBAC migration applied. I was trying to learn RBAC and followed the Docs 2.0. I have logged in using database, but the front-end and back-end both get logged in with any account. I have made 2 RBAC roles (admin, user), but can't understand or find how to restrict back-end to login non-admin user-role. The following is the code for roles. and database entries: namespace console\controllers; use Yii; use yii\console\Controller; class RbacController extends

Yii2 Gii Table Prefix

吃可爱长大的小学妹 提交于 2019-12-07 04:18:56
问题 I allways setup table prefix - for this post lets say my prefix is abc_ . So in common\config\main-local.php . I have: 'components' => [ 'db' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=database', 'username' => 'user', 'password' => 'pwd', 'charset' => 'utf8', 'tablePrefix' => 'abc_', ], ... I have worked on Yii1 and used gii to generate models. In this version it generated files like: table.php . Now I work with Yii2 and learn the differences: gii generate

how to create console command in a module?

我怕爱的太早我们不能终老 提交于 2019-12-07 04:00:36
问题 console command , like ./yii hello/world . I'm using yii-app-basic . what I want is not create console command in the dir commands/ but in a module . 回答1: 1) Your module should implements BootstrapInterface : class Module extends \yii\base\Module implements \yii\base\BootstrapInterface { public function bootstrap($app) { if ($app instanceof \yii\console\Application) { $this->controllerNamespace = 'app\modules\my_module\commands'; } } } 2) Create your console controller in your module commands

Yii2 REST+ Angular Cross Domain CORS

大兔子大兔子 提交于 2019-12-07 03:43:39
问题 I have developed Angular & Yii2 REST service. Have problem in cross domain. Here below add my angular & Yii2 REST Code. AngularJs : (like 'http://organization1.example.com','http://organization2.example.com',....) $http.defaults.useXDomain = true; $http.defaults.withCredentials = true; $http.defaults.headers.common['Authorization'] = 'Bearer ' + MYTOKEN My Request from Angular Controller: apiURL = 'http://api.example.com'; $http.get(apiURL + '/roles') .success(function (roles) { }) .error