Questions about Yii writing api

1. For example: I use yii api to write the interface for submitting orders

  • for example, the information in the form is verified at the front end. How can I implement the verification?
  • used to use form model validation rules and load to load data. Do you still need to write this?

        // 
        $deliveryForm = new SalesOrderDelivery();
        // 
        $deliveryForm->load($post_param);

   
  • api is only for the company"s own use, and session is used in some places, is that right?
  • for example, for my order API, I can verify whether there is user information in the session directly on the server. Is it necessary to add access token?
< hr >
Dec.08,2021

1. Form validation reference document ide/2.0/start-forms" rel=" nofollow noreferrer "> https://www.yiichina.com/doc/.
2. As long as the data you want to verify conforms to the form array format, you can also verify
3. If you only provide API services, you don't need to use session.
4. APIs are authenticated through access_token, and session is not needed without browsers


1: check and receive data

   `if ($model->load(Yii::$app->request->post()) && $model->validate()) {
        //  $model 
    }`

access_token authentication is used for 2:api. Jwt is commonly used at present.


API, please try not to use session, or there will be problems with server expansion and so on. The
interface can be validated with the form model that comes with Yii2. With dependency injection, cool and unwanted

    public function actionBargin(BarginOrderForm $form)
    {
        $data = $form->attributes;
        $data['src_id'] = $form->bargin_id;
        $data['src_type'] = Order::SRC_BARGIN;

        return OrderManager::buyPromotionGoods($data, $form->user_id, $form->corporation_id, '');
    }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b31cd7-2bdef.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b31cd7-2bdef.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?