PHP code example of bearlord / esd-yii

1. Go to this page and download the library: Download bearlord/esd-yii library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bearlord / esd-yii example snippets


/**
 * @GetMapping("/query")
 * @return string
 */
public function query()
{
	$this->response->withHeader("Content-Type", "application/json;charset=UTF-8");

	$result =  (new Query())
		->from('p_photo_model')
		->where([
			'id' => 1713
		])
		->all();
	return [
		'result' => $result
	];
}

namespace app\Model;


use ESD\Yii\Db\ActiveRecord;

class YiiCustomer extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'p_customer';
    }

    public function attributeLabels()
    {
        return [
            'user_name' => '用户名',
            'contact' => '联系方式'
        ];
    }

    public function rules()
    {
        return [
            [['user_name', 'contact'], '

use app\Model\YiiCustomer;

/**
 * @GetMapping("/validate")
 * @return string
 */
public function validate()
{
	$this->response->withHeader("Content-Type", "application/json;charset=UTF-8");

	$customer = new YiiCustomer();
	$customer->setScenario('test');
	$customer->setAttributes([
		'user_name' => 'abfffffffff'
	], false);
	$customer->validate();

	return $customer->errors;
}