我查了资料,说可以把 用户的登陆,注册,找回密码等等逻辑 独立成一个 用户中心 系统 ,,这个 用户中心 不涉及业务,只用来认证用户,
每个子系统要登陆时,跳转到这个 用户中心 进行登陆,,成功后,再返回来路系统
在原始数据和表结构不能动的情况下,不知是否可以实现
public function coll($filter = '')
{
$model = $this->_infoModel;
$query = $model->find();
$query = Yii::$service->helper->ar->getCollByFilter($query, $filter);
return [
'coll' => $query->all(),
'count'=> $query->limit(null)->offset(null)->count(),
'explain' => $model->getCollection()->explain([])
];
}
$model->getCollection()->explain([]) 如何使用explain命令来查看查询语句的执行情况, 我这样使用报错了,,Calling unknown method: yii\mongodb\Collection::explain(),,,找不到方法,,大佬指点下,
看了一下,yii2-mongodb文档 https://www.yiiframework.com/extension/yiisoft/yii2-mongodb/doc/api/2.1/yii-mongodb-debug-explainaction#explainQuery()-detail ,,我不太会看yii的相关文档,,,文档中说的 explainQuery() 方法,,在上面的coll()方法中,如何使用
// 输出SQL语句
$commandQuery = clone $query;
echo $commandQuery->createCommand()->getRawSql();
exit;
这样,就报上面的错误
{"name":"Exception","message":"Calling unknown method: yii\\mongodb\\ActiveQuery::createCommand()","code":0,"type":"yii\\base\\UnknownMethodException","file":"/mnt/hgfs/centoswww/server/web.zlserve.com/vendor/yiisoft/yii2/base/Component.php","line":300,"stack-trace":["#0 /mnt/hgfs/centoswww/server/web.zlserve.com/common/local/local_services/chat/info/InfoMongodb.php(66): yii\\base\\Component->__call()","#1 /mnt/hgfs/centoswww/server/web.zlserve.com/common/local/local_services/chat/Info.php(84): common\\local\\local_services\\chat\\info\\InfoMongodb->coll()","#2 /mnt/hgfs/centoswww/server/web.zlserve.com/appserver/local/local_modules/Chat/controllers/InfoController.php(289): common\\local\\local_services\\chat\\Info->coll()","#3 [internal function]: appserver\\local\\local_modules\\Chat\\controllers\\InfoController->actionTest()","#4 /mnt/hgfs/centoswww/server/web.zlserve.com/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()","#5 /mnt/hgfs/centoswww/server/web.zlserve.com/vendor/yiisoft/yii2/base/Controller.php(180): yii\\base\\InlineAction->runWithParams()","#6 /mnt/hgfs/centoswww/server/web.zlserve.com/vendor/yiisoft/yii2/base/Module.php(528): yii\\base\\Controller->runAction()","#7 /mnt/hgfs/centoswww/server/web.zlserve.com/vendor/yiisoft/yii2/web/Application.php(103): yii\\base\\Module->runAction()","#8 /mnt/hgfs/centoswww/server/web.zlserve.com/vendor/yiisoft/yii2/base/Application.php(386): yii\\web\\Application->handleRequest()","#9 /mnt/hgfs/centoswww/server/web.zlserve.com/appserver/web/index.php(90): yii\\base\\Application->run()","#10 {main}"]}
问题解决了,问题原因是vue axios请求发起了OPTIONS请求,而OPTIONS在yii2中并未被允许跨域,我在appserver入口文件index.php中加入下面的代码就解决了问题
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
$cors_allow_headers = ['fecshop-uuid','fecshop-lang','fecshop-currency','access-token'];
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, ".implode(', ',$cors_allow_headers));
header('Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS');
exit;
}