我的网址是:/backend/web/product/1
:
namespace backend\controllers;
use Yii;
use backend\models\Product;
class ProductController extends \yii\rest\Controller
{
public $enableCsrfValidation = false;
public function actionIndex()
{
\Yii::$app->response->format = yii\web\Response::FORMAT_JSON;
$product = Product::find()->All();
return $product;
}
public function actionView($product_id)
{
// how can I get 1 in my URL? so i can use it inside this function
}
答案 0 :(得分:0)
通常,您展示的模式的漂亮网址是基于ID的。 (你应该检查你的配置urlManager组件)
所以试试
public function actionView($id)
{
// $id should contain 1
return $this->render('view', [
'model' => $this->findModel($id),
]);
}