I am trying to work in RESTfull web services in Yii2
using default controller. But the problem I faced is, I cannot send POST request with parameters.
Below is my code:
Url Manager rule in web.php
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
['pattern' => 'api/v1/auth/payment/<id:\d+>', 'route' => 'api/v1/auth/payment'],
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
AuthController.php
file this is inside controller/api/v1/
namespace app\controllers\api\v1;
use app\controllers\api\v1\components\ApiFunctions;
use Yii;
use yii\web\Controller;
class AuthController extends Controller
{
public function actionPayment()
{
$id = Yii::$app->getRequest()->getQueryParam('id');
json_encode($id);
}
}
But when I send GET
request to http://{url}//api/v1/auth/payment/5
I get response as 5
. But I want to get that result when sending POST
or any other methods.
So how can I achieve that?