我在 laravel 5.5 中使用 barryvdh/laravel-dompdf 和 bootstrap css(通过小的调整重命名为 pdf.css)以生成 pdf 格式的报告,这是我从报告视图调用 css 的标题:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link href="{{public_path('css/pdf.css') }}" rel="stylesheet" type="text/css" />
</head>
<body>
Run Code Online (Sandbox Code Playgroud)
我的控制器:
public function infor(News $news)
{
...
PDF::setOptions(['dpi' => 150, 'defaultFont' => 'sans-serif']);
$pdf = PDF::loadView('admin.news_events.pdf');
return $pdf->stream('pdfview.pdf');
}
Run Code Online (Sandbox Code Playgroud)
我收藏了 150 件物品
...
App\almacen {#1679
id: 124,
emp_id: 1,
dst_id: 13,
hora: 0,
numMesa: 0,
event_id: 1,
created_at: "2018-01-22 11:41:03",
updated_at: "2018-01-22 11:41:03",
},
App\almacen {#1680
id: 125,
emp_id: 1,
dst_id: 11,
hora: 0,
numMesa: 0,
event_id: 1,
created_at: "2018-01-22 11:41:03",
updated_at: "2018-01-22 11:41:03",
},
App\almacen {#1681
id: 126,
emp_id: 1,
dst_id: 12,
hora: 0,
numMesa: 0,
event_id: 1,
created_at: "2018-01-22 11:41:03",
updated_at: "2018-01-22 11:41:03",
},
App\almacen {#1682
id: 127,
emp_id: 1,
dst_id: 20,
hora: 0,
numMesa: 0,
event_id: …Run Code Online (Sandbox Code Playgroud) 这是我的 mysql 查询:
$tmp=almacen::select('nombre_empresa','oferta')->join('users','users.id','=','almacen.emp_id')->where('almacen.event_id','5')->get();
Run Code Online (Sandbox Code Playgroud)
这将返回几个像这样的对象:
...
App\almacen {#1948
nombre_empresa: "Aux1",
oferta: "Serv_1234",
},
App\almacen {#1947
nombre_empresa: "Aux2",
oferta: "Serv 12345678",
},
...
Run Code Online (Sandbox Code Playgroud)
例如,我需要在一个键中转换“nombre_empresa”
$tmp['Aux2']
this return:
"Serv 12345678"
Run Code Online (Sandbox Code Playgroud)
可以在 Laravel 中做到这一点吗?还是我应该以另一种方式来做?
我尝试复制在C#中创建的文件时遇到此问题:
"System.IO.IOException:'进程无法访问文件'd:\ las.txt',因为它正在另一个进程中使用.'"
我的代码:
using System;
namespace modulo1
{
class Program
{
static void Main(string[] args)
{
string folderName = @"c:\lasss";
System.IO.Directory.CreateDirectory(folderName);
string archivo = @"d:\las.txt";
System.IO.File.Create(archivo);
string dest = @"d:\soft";
//here is the problem
System.IO.File.Copy(archivo, dest, true);
}
}
}
我怎么解决这个问题???
如何使用 go-chi 框架的 gzip 中间件启用 gzip 压缩?
尝试使用此处显示的示例:
https://github.com/go-chi/chi/issues/204
但是当我检查 curl 时,我得到了这个:
$ curl -H "Accept-Encoding: gzip" -I http://127.0.0.1:3333
HTTP/1.1 405 Method Not Allowed
Date: Sat, 31 Aug 2019 19:06:39 GMT
Run Code Online (Sandbox Code Playgroud)
我尝试了代码“你好世界”:
package main
import (
"net/http"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
)
func main() {
r := chi.NewRouter()
r.Use(middleware.RequestID)
r.Use(middleware.Logger)
//r.Use(middleware.DefaultCompress) //using this produces the same result
r.Use(middleware.Compress(5, "gzip"))
r.Get("/", Hello)
http.ListenAndServe(":3333", r)
}
func Hello(w http.ResponseWriter, r *http.Request){
w.Header().Set("Content-Type", "text/html") //according to the documentation this must be here to enable gzip …Run Code Online (Sandbox Code Playgroud)