HGthecode/apidoc-php

可以支持下webman框架下使用表前缀,ref参数引用模型数据表所有字段,支持查询没带表前缀的错误。 * @Apidoc\Returned("list", type="array", desc="列表数据", ref="app\model\User")

Closed this issue · 4 comments

xigu commented

Next Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'call' at line 1 (SQL: SHOW FULL COLUMNS FROM call) in D:\www\xzzh\xzzh_manages\vendor\illuminate\database\Connection.php:712
Stack trace:
#0 D:\www\xzzh\xzzh_manages\vendor\illuminate\database\Connection.php(672): Illuminate\Database\Connection->runQueryCallback('SHOW FULL COLUM...', Array, Object(Closure))
#1 D:\www\xzzh\xzzh_manages\vendor\illuminate\database\Connection.php(376): Illuminate\Database\Connection->run('SHOW FULL COLUM...', Array, Object(Closure))
#2 D:\www\xzzh\xzzh_manages\vendor\illuminate\database\Capsule\Manager.php(200): Illuminate\Database\Connection->select('SHOW FULL COLUM...')
#3 D:\www\xzzh\xzzh_manages\vendor\hg\apidoc\src\middleware\WebmanMiddleware.php(46): Illuminate\Database\Capsule\Manager::__callStatic('select', Array)
#4 D:\www\xzzh\xzzh_manages\vendor\hg\apidoc\src\providers\BaseService.php(111): hg\apidoc\middleware\WebmanMiddleware::databaseQuery('SHOW FULL COLUM...')
#5 D:\www\xzzh\xzzh_manages\vendor\hg\apidoc\src\parses\ParseModel.php(196): hg\apidoc\middleware\WebmanMiddleware->hg\apidoc\providers{closure}('SHOW FULL COLUM...')
#6 D:\www\xzzh\xzzh_manages\vendor\hg\apidoc\src\parses\ParseModel.php(69): hg\apidoc\parses\ParseModel::getTableDocument(Object(app\common\model\Call), Array)
#7 D:\www\xzzh\xzzh_manages\vendor\hg\apidoc\src\parses\ParseModel.php(37): hg\apidoc\parses\ParseModel::parseModelTable(Object(app\common\model\Call), 'app\common\mode...', '')
#8 D:\www\xzzh\xzzh_manages\vendor\hg\apidoc\src\parses\ParseApiDetail.php(452): hg\apidoc\parses\ParseModel->renderModel('app\common\mode...')
#9 D:\www\xzzh\xzzh_manages\vendor\hg\apidoc\src\parses\ParseApiDetail.php(747): hg\apidoc\parses\ParseApiDetail->renderRef('app\common\mode...', true)
#10 D:\www\xzzh\xzzh_manages\vendor\hg\apidoc\src\parses\ParseApiDetail.php(597): hg\apidoc\parses\ParseApiDetail->handleParamAndReturned(Array, Object(hg\apidoc\annotation\Returned), 'returned', true, 'controller')
#11 D:\www\xzzh\xzzh_manages\vendor\hg\apidoc\src\parses\ParseApiDetail.php(254): hg\apidoc\parses\ParseApiDetail->parseAnnotation(Object(ReflectionMethod), true, 'controller')
#12 D:\www\xzzh\xzzh_manages\vendor\hg\apidoc\src\parses\ParseApiDetail.php(84): hg\apidoc\parses\ParseApiDetail->parseApiMethod(Object(ReflectionClass), Object(ReflectionMethod))
#13 D:\www\xzzh\xzzh_manages\vendor\hg\apidoc\src\Controller.php(158): hg\apidoc\parses\ParseApiDetail->renderApiDetail('api', 'app\api\v3\cont...', 'lists')
#14 D:\www\xzzh\xzzh_manages\vendor\workerman\webman-framework\src\App.php(304): hg\apidoc\Controller->getApiDetail(Object(support\Request))
#15 D:\www\xzzh\xzzh_manages\vendor\hg\apidoc\src\middleware\WebmanMiddleware.php(25): Webman\App::Webman{closure}(Object(support\Request))
#16 D:\www\xzzh\xzzh_manages\vendor\workerman\webman-framework\src\App.php(299): hg\apidoc\middleware\WebmanMiddleware->process(Object(support\Request), Object(Closure))
#17 D:\www\xzzh\xzzh_manages\vendor\webman\log\src\Middleware.php(58): Webman\App::Webman{closure}(Object(support\Request))
#18 D:\www\xzzh\xzzh_manages\vendor\workerman\webman-framework\src\App.php(299): Webman\Log\Middleware->process(Object(support\Request), Object(Closure))
#19 D:\www\xzzh\xzzh_manages\vendor\webman\cors\src\CORS.php(12): Webman\App::Webman{closure}(Object(support\Request))
#20 D:\www\xzzh\xzzh_manages\vendor\workerman\webman-framework\src\App.php(299): Webman\Cors\CORS->process(Object(support\Request), Object(Closure))
#21 D:\www\xzzh\xzzh_manages\app\common\middleware\AccessControl.php(32): Webman\App::Webman{closure}(Object(support\Request))
#22 D:\www\xzzh\xzzh_manages\vendor\workerman\webman-framework\src\App.php(299): app\common\middleware\AccessControl->process(Object(support\Request), Object(Closure))
#23 D:\www\xzzh\xzzh_manages\app\common\middleware\ApiDocServiceProvider.php(39): Webman\App::Webman{closure}(Object(support\Request))
#24 D:\www\xzzh\xzzh_manages\vendor\workerman\webman-framework\src\App.php(299): app\common\middleware\ApiDocServiceProvider->process(Object(support\Request), Object(Closure))
#25 D:\www\xzzh\xzzh_manages\vendor\workerman\webman-framework\src\App.php(515): Webman\App::Webman{closure}(Object(support\Request))
#26 D:\www\xzzh\xzzh_manages\vendor\workerman\webman-framework\src\App.php(128): Webman\App::findRoute(Object(Workerman\Connection\TcpConnection), '/apidoc/apiDeta...', 'POST/apidoc/api...', Object(support\Request))
#27 D:\www\xzzh\xzzh_manages\vendor\workerman\workerman\Connection\TcpConnection.php(638): Webman\App->onMessage(Object(Workerman\Connection\TcpConnection), Object(support\Request))
#28 D:\www\xzzh\xzzh_manages\vendor\workerman\workerman\Events\Select.php(311): Workerman\Connection\TcpConnection->baseRead(Resource id #320)
#29 D:\www\xzzh\xzzh_manages\vendor\workerman\workerman\Worker.php(2457): Workerman\Events\Select->loop()
#30 D:\www\xzzh\xzzh_manages\vendor\workerman\workerman\Worker.php(1443): Workerman\Worker->run()
#31 D:\www\xzzh\xzzh_manages\vendor\workerman\workerman\Worker.php(1386): Workerman\Worker::forkWorkersForWindows()
#32 D:\www\xzzh\xzzh_manages\vendor\workerman\workerman\Worker.php(559): Workerman\Worker::forkWorkers()
#33 D:\www\xzzh\xzzh_manages\vendor\workerman\webman-framework\src\support\App.php(124): Workerman\Worker::runAll()
#34 D:\www\xzzh\xzzh_manages\start.php(4): support\App::run()
#35 {main}

如何复现你的错误?我用webman框架并配置表前缀,也是能正常获取的。

xigu commented

控制器:
/**

  • 测试
    */
    class Test extends Base
    {

    /**

    • @apidoc\Title("用户列表")
    • @apidoc\Author("wp")
    • @apidoc\Tag("基础,示例")
    • @apidoc\Url ("/backend/test/index")
    • @apidoc\Method ("GET")
    • @apidoc\Returned("list", type="array", desc="列表数据", ref="app\common\model\User")
      */
      public function index(Request $request): \support\Response
      {
      $user = new \app\common\model\User();
      $data['table'] = $user->getTable();
      return $this->success(0, $data);
      }
      }
      模型:

namespace app\common\model;

use app\common\model\common\BaseModel;

class User extends BaseModel
{

/**
 * The table associated with the model.
 *
 * @var string
 */
protected $table = 'staff';

/**
 * The primary key associated with the table.
 *
 * @var string
 */
protected $primaryKey = 'id';

}
image
image
查看接口test/index就有错误

xigu commented
    $tableColumns = $config['database_query_function']("SHOW FULL COLUMNS FROM " . $model->getTable());

这里调模型获取到的表名没带前缀

请更新到v4.2.2版本,该问题已修正,感谢反馈