鍍金池/ 問(wèn)答/ PHP問(wèn)答

你看下這樣行不行。
把input的value用數(shù)組表示,然后后臺(tái)接收到的所有input在一個(gè)數(shù)組中

$hotels = array();
$arr = $_POST['arr'];

foreach ($arr as $k => $v) {
    if($k%3 == 0){
        if($v){
            if(!$arr[$k+1] || !$arr[$k+2]){
                echo json_encode(array(
                    "code" => -1,
                    "msg"  => "如果填酒店名,就必須填金額,時(shí)間",
                ));
                die;
            }
            $hotels[] = array(
                "name" => $v,
                "cost" => $arr[$k+1],
                "time" => $arr[$k+2],
            );
        }else{
            $hotels[] = array(0, 0, 0);
        }
    }
}
echo json_encode(array(
    "code" => 0,
    "msg"  => "success",
));
薄荷綠 回答

storage整個(gè)目錄的權(quán)限都改吧。

通過(guò)分析換了一種方法解決

利用BootstrapTable這個(gè)onClickRow事件函數(shù) 然后在單獨(dú)調(diào)用google map的api

產(chǎn)生點(diǎn)擊循環(huán)列表在map中展現(xiàn)圖片信息

修復(fù)bug $element[0].addEventListener('click',fm);

  function BootstrapTable() {
        $.ajax({
            "type": "get",
            "url": imgJson,
            "async": false,
            "success": function (data) {
                window.res = data.data;
                //console.log(data.data);
                $('#table').bootstrapTable({
                    data: data.data,
                    pagination: true,
                    searchAlign: "right",
                    buttonsAlign: "left",
                    showRefresh: true,
                    searchOnEnterKey: false,
                    singleSelect: true,
                    maintainSelected: false,
                    search: true,
                    pageSize: 10,
                    sortable: false,
                    paginationLoop: true,
                    toolbar: '#toolbar',        // 工具欄ID
                    toolbarAlign: 'right',        // 工具欄對(duì)齊方式
                     onClickRow: function (item, $element) {
                        var arr = {};
                        arr.Latitude = parseFloat(item.Latitude);
                        arr.Longitude = parseFloat(item.Longitude);
                        var latLng = new google.maps.LatLng(arr.Latitude, arr.Longitude);
                        var fm = mapLine.markerClickFunction(item, latLng);
                        $element[0].addEventListener('click',fm);
                    },
              
                    columns: [
                        {
                            field: 'id',
                            align: 'center',
                            title: 'id'
                        },
                        {
                            field: 'photo_title',
                            align: 'center',
                            title: 'photo_title'
                        },
                        {
                            field: 'photo_time',
                            align: 'center',
                            title: 'photo_time'
                        }
                    ]

                });
            }
        });
    };
我以為 回答

set names utf8

設(shè)置一下編碼試試

喵小咪 回答

select * from t2 LEFT JOIN t1 ON t2. m_top_user_list like '%t1. user_id%'

我以為 回答

raw:文件內(nèi)容。
blame:按行顯示最新提交的信息。
history:文件的歷史記錄。

扯不斷 回答

直接round不可能出現(xiàn)這個(gè)吧。。只有計(jì)算才會(huì)出現(xiàn)這種,然后你里面2個(gè)點(diǎn)的是什么

js代碼:

<script type="text/javascript">

            $(function () {
                $("#file_upload").change(function () {
                    uploadImage();
                })
            })
            function uploadImage() { //  判斷是否有選擇上傳文件
                var imgPath = $("#file_upload").val();
                if (imgPath == "") {
                    alert("請(qǐng)選擇上傳圖片!");
                    return;
                }
                //判斷上傳文件的后綴名
                var strExtension = imgPath.substr(imgPath.lastIndexOf('.') + 1);
                if (strExtension != 'jpg' && strExtension != 'gif'
                    && strExtension != 'png' && strExtension != 'bmp') {
                    alert("請(qǐng)選擇圖片文件");
                    return;
                }
                // var formData = new FormData($('#art_form')[0]);
                var formData = new FormData();
                formData.append('fileupload',$('#file_upload')[0].files[0]);

                $.ajax({
                    type: "POST",
                    cache: false,
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    url: "/admin/upload",
                    data: formData,
                    contentType: false,
                    processData: false,
                    success: function(data) {
                        console.log(data);
                        $('#art_thumb').attr('src', data);
                        $("input[name='map']").val(data);
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert("上傳失敗,請(qǐng)檢查網(wǎng)絡(luò)后重試");
                    }
                });
            }
        </script>

后端代碼:

//文件上傳

public function upload(Request $request)
{
    $file = $request->file('fileupload');
 
   
    //如果是有效的上傳文件
    if($file->isValid()) {
     //            獲取原文件的文件類(lèi)型
        $ext = $file->getClientOriginalExtension();    //文件拓展名
         //        生成新文件名
        $newfile = md5(date('YmdHis').rand(1000,9999).uniqid()).'.'.$ext;

         //       將文件上傳到本地服務(wù)器
        //將文件從臨時(shí)目錄移動(dòng)到制定目錄
        $path = $file->move(public_path().'/uploads',$newfile);

        //        將上傳文件的路徑返回給客戶(hù)端
        return '/uploads/'.$newfile;
    }
}

你把置頂?shù)奈恼路旁诰彺嬷谢蛘吡硪粡埍碇校ㄎ恼卤硪灿兄庙斘恼碌臄?shù)據(jù)),那么你先在這邊取置頂文章,然后再按之前最后一條文章的添加時(shí)間來(lái)分頁(yè),當(dāng)然增加過(guò)濾條件非置頂文章。這樣性能會(huì)快很多,尤其是有對(duì)“添加時(shí)間”欄位做了索引。

不是特別明白 你想要的json格式, 按照我理解的意思 隨手寫(xiě)了一段,并沒(méi)有測(cè)試



$res = $db->table('cate')->where('parentid =0')->select();
$array=array();
foreach ($res as $key =>$val){
    $cate = $db->table('cate')->where('parentid ='.$val['id'])->select();
    $array[$key]['id']=$cate['id'];
    $array[$key]['disabled']=false;
    $array[$key]['groupName']=$val['categoryname'];
    $array[$key]['groupId']=$val['id'];
    $array[$key]['selected']=false;
    $array[$key]['name']=$cate['categoryname'];
}
echo json_encode($array);exit;
神曲 回答

上文中所寫(xiě)的代碼極其危險(xiǎn)

建議對(duì)于這種嵌有HTML的內(nèi)容 通過(guò)使用模板文件進(jìn)行存儲(chǔ),使用占位符的形式來(lái)對(duì)內(nèi)容進(jìn)行替換。

建議方案

  • email.template
<html>
    <head>
        {$phpmailer_css_style}
    </head>

    <body>
    <div class="edm-layout">
      <img src="{$host_url}images/logo.png">
      <div class="line"></div>
    </div>

    <div class="edm-content">
      <div class="edm-hithere">
        嗨,{$user_name} <br>XXX {$prod_total}XXXXX<br>XXXXXX{$this_total} XXX
      </div>
      
        <div class="edm-products">
            {$row_distinct}
        </div>
      </div>
    </div>
  </body>
</html>
  • EmailTemplate.php

<?php
$php_version = version_compare(phpversion(), '7');
/**
 * 必須php 7
 */
if ($php_version === -1) {
    die('Need a high version of php 7.1.*');
}
/**
 * EmailTemplate
 */
class EmailTemplate
{
    /**
     * @param string $template_path 模板路徑
     * @param array $args 變量組
     * @return string 渲染后的
     * @throws Exception
     */
    public static function render(string $template_path, array $args): string
    {
        if (!file_exists($template_path)) {
            throw new Exception("Not found template fiel.", 1);

        }
        $template = file_get_contents($template_path);
        $result = preg_replace_callback('!\{\$(\w+)\}!', function ($matches) use ($args) {
            $arg = $matches[1];
            return $args[$arg] ?? '';
        }, $template);
        return $result;
    }
}
  • demo.php
$body = EmailTemplate::render(
    'email.template',
    [
        'host_url' => 'http://xxx',
        'phpmailer_css_style' => 'empty',
        'user_name' => '張三',
        'prod_total' => '100.00',
        'this_total' => '10000.00',
        'row_distinct' => 'empty',
    ]
);

這樣就實(shí)現(xiàn)了一個(gè)簡(jiǎn)單的模板替換。

笑浮塵 回答

ThinkingSession應(yīng)該是以dll的形式當(dāng)做程序集引入的,目前看來(lái)這個(gè)dll被改動(dòng)位置或者刪除了。 檢查一下項(xiàng)目的程序集引用,是否缺失了這個(gè)dll。

clipboard.png

墨小羽 回答

后端簡(jiǎn)化下接口,就做成一個(gè)接口

青瓷 回答

bind對(duì)象進(jìn)去就行了
setInterval(test.all.bind(test),1000);

你好胸 回答

很簡(jiǎn)單的問(wèn)題花了兩天時(shí)間,終于解決了,我F...佛慈悲,咳咳嗯,正經(jīng)說(shuō)說(shuō)怎么回事

背景介紹

項(xiàng)目是要部署在阿里云上對(duì)外的,簡(jiǎn)單說(shuō)就是要大家在地址欄敲個(gè)xxx.com就能訪(fǎng)問(wèn)到我的網(wǎng)站。而樓主之前一直項(xiàng)目組做本地調(diào)試

假設(shè)本地有兩個(gè)Vue工程,如果一個(gè)工程被npm run dev,就會(huì)跑在localhost:8080,那么80端口被占用了,不能再占一個(gè)8080,只能改用8081,做法如題問(wèn)中描述
但是,當(dāng)發(fā)布到阿里云之后,設(shè)置好的8081不起作用了怎么回事呢?

現(xiàn)在針對(duì)同一個(gè)阿里云分配的IP地址,樓主申請(qǐng)了兩個(gè)域名hehe.com和lala.com,希望訪(fǎng)問(wèn)hehe.com時(shí)對(duì)應(yīng)顯示工程hehe,訪(fǎng)問(wèn)lala.com時(shí),對(duì)應(yīng)顯示工程lala

通過(guò)nginx配置使同一IP對(duì)應(yīng)多個(gè)域名和多個(gè)項(xiàng)目

其實(shí)我們的所有設(shè)置都是針對(duì)開(kāi)發(fā)環(huán)境(關(guān)鍵字:dev/development),而部署在阿里云上被稱(chēng)為生產(chǎn)環(huán)境(關(guān)鍵字:production)

那生產(chǎn)環(huán)境怎么還不受代碼控制呢?這個(gè)需要展開(kāi)來(lái)講:

我們開(kāi)發(fā)的工程,需要一步步測(cè)試調(diào)試
在開(kāi)發(fā)環(huán)境下修改一小段code都可以看到相應(yīng)的效果
而當(dāng)你解決所有bug,認(rèn)為代碼perfect的時(shí)候,就會(huì)npm run build
這是做什么呢?就是把你的項(xiàng)目打包成一個(gè)靜態(tài)文件,什么叫靜態(tài)文件?Emmm...就理解成打包成一坨,里里外外都不能改的,可以直接運(yùn)行出你perfect的效果

這個(gè)文件在哪里呢?當(dāng)你build之后會(huì)看到根目錄下有個(gè)dist文件,吶,就是這個(gè),先記住他哦

clipboard.png

然后就可以運(yùn)行了么?Nope
這是個(gè)文件,讓它run在阿里云服務(wù)器上我們需要一個(gè)代理服務(wù)器nginx,你可以理解為你有個(gè).doc文件,總需要個(gè)Microfoft Word來(lái)打開(kāi)的對(duì)吧,這里的nginx可以幫你打開(kāi)靜態(tài)文件讓它run起來(lái)

所以

步驟

  1. 你要在阿里云上安裝一個(gè)nginx
    這里有教程nginx的安裝配置和使用: https://segmentfault.com/a/11...
  2. nginx有一個(gè)配置文件nginx.conf,吶關(guān)鍵來(lái)啦,這個(gè)配置文件可以幫助我們實(shí)現(xiàn)對(duì)應(yīng)域名,對(duì)應(yīng)文件的強(qiáng)大功能啦,下面粘貼一小段配置代碼,可以看到hehe工程和hehe.com對(duì)對(duì)應(yīng)起來(lái)了,可以看到lala工程和lala.com對(duì)對(duì)應(yīng)起來(lái)了,
  3. 端口號(hào)可以通過(guò)修改listen后的數(shù)字來(lái)設(shè)置
#第一個(gè)服務(wù)器
server {
       #這里的default_server標(biāo)識(shí)服務(wù)器為默認(rèn)服務(wù)器,無(wú)對(duì)應(yīng)域名情況下會(huì)對(duì)應(yīng)至該服務(wù)器
       listen 80 default_server;
       #和上一句語(yǔ)義相同,上句對(duì)應(yīng)Ipv4這里對(duì)應(yīng)Ipv6
       listen [::]:80 default_server;
        
       #對(duì)應(yīng)的靜態(tài)文件根目錄,把你的hehe工程的dist里面的內(nèi)容放在這里
       root /var/www/hehe;
 
       index index.html index.htm index.nginx-debian.html;
                        
       #對(duì)應(yīng)的第一個(gè)域名
       server_name hehe.com;
 
       location / {
           # First attempt to serve request as file, then
           # as directory, then fall back to displaying a 404.
           try_files $uri $uri/ @router;
           index index.html;
       }
       location @router{
           rewrite ^.*$ /index.html last;
       }
}
 
 
#第二個(gè)服務(wù)器
server {
    #這里應(yīng)該不設(shè)置default_server否則會(huì)報(bào)錯(cuò),注:端口號(hào)可與另一服務(wù)器重復(fù)
    listen 80;
    listen [::]:80;
        
    #對(duì)應(yīng)的靜態(tài)文件路徑
    root /var/www/lala;

    index index.html index.htm index.nginx-debian.html;
    
    #對(duì)應(yīng)的第二個(gè)域名           
    server_name lala.com;
        
    location / {
      # First attempt to serve request as file, then
      # as directory, then fall back to displaying a 404.
      try_files $uri $uri/ @router;
      index index.html;
    }
    location @router{
      rewrite ^.*$ /index.html last;
    }
}

吢丕 回答

是不是兩邊有空格或者什么的,把兩邊的空格去掉試試?。?/p>

離人歸 回答

不是有個(gè)socket嗎。。。雖然我不會(huì)用。。。