Thinkphp5 开发笔记

xiaoxiao2021-02-28  144

网站架构:TP5 + mysql 数据来源大部分调用第三方接口获取 开发中碰到的问题总汇: 1、openssl问题: (1)公钥字符串开头要加上“-----BEGIN  PUBLIC  KEY-----\n”,结尾加上“\n-----END  PUBLIC  KEY-----\n”。否则会出现 false (2)公钥字符串每隔64个字符要加一个换行,否则会报秘钥格式错误 2、wamp2.5网站权限 修改httpd.conf文件 # onlineoffline tag - don't removeRequire local To # onlineoffline tag - don't removeRequire all granted 3、 WAMP虚拟目录的设置 1.打开Apache的配置文件httpd.conf,并去掉#Include conf/extra/httpd-vhosts.conf前面的#!! 2.打开Apache的apache/conf/extra下的次配置文件httpd-vhosts.conf 3.将此文件下的原有的扩展配置文件(如下):删除一个或两个 < VirtualHost *:80 > ServerAdmin webmaster@dummy-host2.localhost DocumentRoot /www/docs/dummy-host2.localhost ServerName dummy-host2.localhost ErrorLog logs/dummy-host2.localhost-error_log CustomLog logs/dummy-host2.localhost-access_log common </ VirtualHost > 4.在httpd-vhosts.conf文件的末尾添加上: < VirtualHost *:80 > DocumentRoot D:/wamp/website/a.com ServerName www.a.com < Directory "D:/wamp/website/a.com" > Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </ Directory > </ VirtualHost > 5.打开在C:/WINDOWS/system32/drivers/etc中的hosts文件中加上如下的内容 127.0.0.1 www.a.com 6.这样我们就配置好了名为wamp的虚拟主机,重启一下我们在浏览器中输入wamp就可以查看到D:/wamp/www目录下的内容了!! 7.但是这样localhost访问则出现了问题,这时需要我们,同样将localhost设为虚拟主机 < VirtualHost *:80 > DocumentRoot D:/wamp/www ServerName localhost < Directory "D:/wamp/www" > Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </ Directory > </ VirtualHost > 8.为了让其他电脑用IP访问电脑,需要在httpd.conf 中搜索127.0.0.1,修改为all 4、 Json格式 jquery each报 Uncaught TypeError: Cannot use 'in' operator to search  在写前端的时候用jquery来遍历后台传来的json数组时候遇到这个错误:Uncaught TypeError: Cannot use 'in' operator to search for。后来查到原因是因为:一部分浏览器后端传过来的是json对象,但是我们前端是需要Javascript的对象,所以需要做个转换JSON.parse(json) or jQuery $.parseJSON(json) 5、服务器部署 1) 阿里云装wamp提示缺少msvcr110.dll解决办法 只需要下载微软的Visual C++ Redistributable for Visual Studio 2012 Update 4安装包,安装之后再安装wamp即可 http://www.microsoft.com/en-us/download/details.aspx?id=30679 6、  PHP“Cannot use object of type stdClass as array”  php再调用json_decode从字符串对象生成json对象时,如果使用[]操作符取数据,会得到下面的错误 错误: Cannot use object of type stdClass as array 产生原因: +展开 -PHP     $res = json_decode($res);     $res['key']; //把 json_decode() 后的对象当作数组使用。 解决方法(2种): 1、使用 json_decode($d, true)。就是使json_decode 的第二个变量设置为 true。 2、json_decode($res) 返回的是一个对象, 不可以使用 $res['key'] 进行访问, 换成 $res->key 就可以了。 7、未定义的变量在模版中使用时会出错 配置文件config.php 顶部加上 error_reporting (E_ERROR | E_WARNING | E_PARSE); 8、jquery 的ajax方法 $.ajax({     url: "http://",    //请求的url地址     dataType: "json",   //返回格式为json     async: true, //请求是否异步,默认为异步,这也是ajax重要特性     data: { "id": "value" },    //参数值     type: "GET",   //请求方式     beforeSend: function() {         //请求前的处理     },     success: function(req) {         //请求成功时处理     },     complete: function() {         //请求完成的处理     },     error: function() {         //请求出错处理 alert(XMLHttpRequest.status); alert(XMLHttpRequest.readyState); alert(textStatus);     } }); 9、 jquery 1)ul li 添加方法 $('.content ul li').click(function(){ var interid = $(this).index()+1; if($(this).val()){ $(this).val("0"); $("img",this).attr("src","/static/images/ic_interest_"+interid+".png"); } else{ $(this).val("1"); $("img",this).attr("src","/static/images/ic_interest_sel_"+interid+".png"); } }); var inters = new Array(); $('#intergo').click(function(){ //i就是li的索引, 给不同的i绑定不同的事件即可 $('.content ul li').each(function(i){ }); }); 2) query如何删除数组中的一个元素 var a = [3,4,5,6,7,8,9];      $.each(a,function(index,item){               // index是索引值(即下标)   item是每次遍历得到的值;             if(item==7){                      a.splice(index,1);              }      }); 3)jquery 替换 class 的方法 1、.addClass(“class1″) .removeClass(“class2″) 2、.attr(“class”,”class1″) 3、.toggleClass(“class1″)如果原来没有class1就添加class1,如果原来有class1就移除class1 10、如何增加微信朋友圈分享链接的小图片 在网页的头部加上以下代码,图片路径自行修改。 <head> <div id='wx_pic' style='margin:0 auto;display:none;'> <img src='/image/data/pic300.jpg' /> </div> </head> 11 ThinkPHP 中实现 Rewrite 模式 ThinkPHP中默认的URL地址是形如这样的:http://localhost/Myapp/index.php/Index/index/ Myapp是我的项目文件名,默认的访问地址是上面这样的。为了使URL更加简介友好,现在要去掉中间的index.php,方法如下: 1。确认httpd.conf配置文件中加载了mod_rewrite.so 模块,加载的方法是去掉mod_rewrite.so前面的注释#号 2。讲httpd.conf中的Allowoverride  None 将None改为All 3。打开对应的项目配置文件,我的项目配置文件是Myapp/Conf/config.php ,在这个配置文件数组中增加一行,‘URL_MODEL’=>2 (TP5不需要配置此项) 4。在项目的根目录下面建立一个.htaccess文件,里面写入下面的内容: <IfModule rewrite_module> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] </IfModule>   alias rewrite 后出现404,应设置RewriteBase参数 为保证正常访问  需要在.htaccees文件里加入 RewriteBase /mytest 12.二级域名设置 httpd-vhosts.conf 增加虚拟目录节点 <VirtualHost *:80> DocumentRoot D:/wamp/www\xxx/public ServerName m.xiaozhaogou.com <Directory "D:/wamp/www\xxx/public"> Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all </Directory> </VirtualHost> config.php 应用配置文件 // m子域名绑定到mobile模块 Route::domain('www','mobile'); Route::domain('m','mobile'); Route::domain('wx','wx'); // 域名根,如thinkphp.cn 'url_domain_root' => 'xxx.com', 13、 utf-8无bom  的问题 一定注意文件格式,若保持为utf-8+BOM格式,可能导致页面和css样式问题
转载请注明原文地址: https://www.6miu.com/read-22574.html

最新回复(0)