怎样用yii2.0配合mongodb做后台的yii2角色权限管理系统控制系统

Yii2- Failed to create Mongodb models using Gii - Stack Overflow
Join the Stack Overflow Community
Stack Overflow is a community of 7.0 million programmers, just like you, helping each other.
J it only takes a minute:
I can't create MongoDb models using Gii module code generator. Gets the below error :
Unknown Method – yii\base\UnknownMethodException
Calling unknown method: common\components\MongoConnection::getTableSchema()
Gii should not be used to create MongoDB Models.
MongoDB documents may change from one to another and there is no "collection definiton", as oposed to "table schemas" where you can get all column names and types.
This is the reason why a model cannot be created automatically and should be created manually.
There is a Gii component to help you generate MongoDB ActiveRecords.
Here's a little YouTube video that shows you exactly how it modify Yii2 configuration, create an active record and generate a CRUD controller.
8,00532544
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
The week's top questions and answers
Important community announcements
Questions that need answers
By subscribing, you agree to the
rev .25671
Stack Overflow works best with JavaScript enabled完美利用Yii2微信后台开发的系列总结
完美利用Yii2微信后台开发的系列总结
网上有很多关于YII2.0微信开发教程,但是太过复杂凌乱,所以今天在这里给大家整理总结利用Yii2微信后台开发的系列了,给需要的小伙伴们参考。
一:接入微信
Yii2后台配置
1.在app/config/params.php中配置token参数
//微信接入
'wechat' =&[
'token' =& 'your token',
2.在app/config/main.php中配置路由
因为接口模块使用的RESTful API,所以需要定义路由规则。
'urlManager' =& [
'enablePrettyUrl' =& true,
'enableStrictParsing' =& true,
'showScriptName' =& false,
'rules' =& [
'class' =& 'yii\rest\UrlRule',
'controller' =& 'wechat',
'extraPatterns' =& [
'GET valid' =& 'valid',
3.在app/controllers中新建WechatController
namespace api\
use yii\rest\ActiveC
class WechatController extends ActiveController
public $modelClass = '';
public function actionValid()
$echoStr = $_GET["echostr"];
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
//valid signature , option
if($this-&checkSignature($signature,$timestamp,$nonce)){
echo $echoS
private function checkSignature($signature,$timestamp,$nonce)
// you must define TOKEN by yourself
$token = Yii::$app-&params['wechat']['token'];
if (!$token) {
echo 'TOKEN is not defined!';
$tmpArr = array($token, $timestamp, $nonce);
// use SORT_STRING rule
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
微信公众号后台配置
在微信公众号后台配置URL和Token,然后提交验证即可。
URL:/wechats/valid
Token:your token
二:获取用户信息
用户表设计
https://api./cgi-bin/ticket/getticket?type=jsapi&access_token=".$accessT
&&&&&&&&&&& $res = json_decode(self::curlGet($url));
&&&&&&&&&&& $ticket = $res-&
&&&&&&&&&&& if ($ticket) {
&&&&&&&&&&&&&&& $redis-&set('wechat:jsapi_ticket', $ticket);
&&&&&&&&&&&&&&& $redis-&expire('wechat:jsapi_ticket', 7000);
&&&&&&&&&&& }
&&&&&&& return $
&&& public static function getAccessToken() {
&&&&&&& //使用Redis缓存 access_token
&&&&&&& $redis = Yii::$app-&
&&&&&&& $redis_token = $redis-&get('wechat:access_token');
&&&&&&& if ($redis_token) {
&&&&&&&&&&& $access_token = $redis_
&&&&&&& } else {
&&&&&&&&&&& $appid = Yii::$app-&params['wechat']['appid'];
&&&&&&&&&&& $appsecret = Yii::$app-&params['wechat']['appsecret'];
&&&&&&&&&&& $url = "https://api./cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$
&&&&&&&&&&& $res = json_decode(self::curlGet($url));
&&&&&&&&&&& $access_token = $res-&access_
&&&&&&&&&&& if ($access_token) {
&&&&&&&&&&&&&&& $redis-&set('wechat:access_token', $access_token);
&&&&&&&&&&&&&&& $redis-&expire('wechat:access_token', 7000);
&&&&&&&&&&& }
&&&&&&& return $access_
&&& public static function curlGet($url = '', $options = array()){
&&&&&&& $ch = curl_init($url);
&&&&&&& curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
&&&&&&& curl_setopt($ch, CURLOPT_TIMEOUT, 30);
&&&&&&& if (!empty($options)) {
&&&&&&&&&&& curl_setopt_array($ch, $options);
&&&&&&& //https请求 不验证证书和host
&&&&&&& curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
&&&&&&& curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
&&&&&&& $data = curl_exec($ch);
&&&&&&& curl_close($ch);
&&&&&&& return $
&&& public static function curlPost($url = '', $postData = '', $options = array()){
&&&&&&& if (is_array($postData)) {
&&&&&&&&&&& $postData = http_build_query($postData);
&&&&&&& $ch = curl_init();
&&&&&&& curl_setopt($ch, CURLOPT_URL, $url);
&&&&&&& curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
&&&&&&& curl_setopt($ch, CURLOPT_POST, 1);
&&&&&&& curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
&&&&&&& curl_setopt($ch, CURLOPT_TIMEOUT, 30); //设置cURL允许执行的最长秒数
&&&&&&& if (!empty($options)) {
&&&&&&&&&&& curl_setopt_array($ch, $options);
&&&&&&& //https请求 不验证证书和host
&&&&&&& curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
&&&&&&& curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
&&&&&&& $data = curl_exec($ch);
&&&&&&& curl_close($ch);
&&&&&&& return $
&&& public static function createNonceStr($length = 16){
&&&&&&& $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
&&&&&&& $str = '';
&&&&&&& for ($i = 0; $i&$ $i++){
&&&&&&&&&&& $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
&&&&&&& return $
2.获取config参数接口
public function actionConfig(){
if (isset($_REQUEST['url'])) {
$url = $_REQUEST['url'];
//微信支付参数
$appid = Yii::$app-&params['wechat']['appid'];
$mchid = Yii::$app-&params['wechat']['mchid'];
$key = Yii::$app-&params['wechat']['key'];
$wx_pay = new WechatPay($mchid, $appid, $key);
$package = $wx_pay-&getSignPackage($url);
$result['error'] = 0;
$result['msg'] = '获取成功';
$result['config'] = $
$result['error'] = 1;
$result['msg'] = '参数错误';
以上就是利用Yii2微信后台开发全部过程及示例代码,希望本文对大家基于php的微信公众平台开发有所帮助。
Copyright & 2016 phpStudyMongodb后台daemon方式启动 - 青葱岁月 - ITeye技术网站
博客分类:
Mongodb可以通过命令行方式和配置文件的方式来启动,具体命令如下:
[root@localhost mongodb]# ./bin/mongod --dbpath=/data/db
配置文件:
[root@localhost mongodb]# ./bin/mongod -f mongodb.conf
但是这两种方式都是在前台启动Mongodb进程,如果Session窗口关闭,Mongodb进程也随之停止。不过Mongodb同时还提供了一种后台Daemon方式启动,只需要加上一个"--fork"参数即可,值得注意的是,用到了"--fork"参数就必须启用"--logpath"参数。如下所示:
[root@localhost mongodb]# ./bin/mongod --dbpath=data/db --fork
--fork has to be used with --logpath
[root@localhost mongodb]# ./bin/mongod --dbpath=data/db --fork --logpath=log/mongodb.log
all output going to: /opt/mongodb/log/mongodb.log
forked process: 3300
[root@localhost mongodb]#
daemon方式启动的fork参数也可以配置配置文件中,如下所示:
port=27017
dbpath=data/db
logpath=log/mongodb.log
logappend=true
然后通过配置文件启动后mongodb也是在后台启动了:
[root@localhost mongodb]# ./bin/mongod -f mongodb.conf
all output going to: /opt/mongodb/log/mongodb.log
forked process: 3377
浏览 24298
chenzhou123520
浏览: 2308050 次
来自: 北京
您好,我的配置跟你的一样,可就是不打印日志,很奇怪,你配置的时 ...
感谢!!!!!!!!!!
感谢楼主!终于可以睡觉了
尹鹏波 写道学习了,多谢楼主分享GoodsDaoTest测试类 ...}

我要回帖

更多关于 yii mongodb 查询 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信