小编nie*_*lsv的帖子

使用ajax请求在浏览器中下载

我正在使用AngularJS,我正在尝试在php中生成PDF.这就是我在controller.js中的内容:

$scope.downloadPDF = function(){
    $http.post('/download-pdf', { fid: $routeParams.fid })
        .success(function(data, status, headers, config){
            console.log("success");
        })
        .error(function(data, status, headers, config){
            console.log("error");
        });
};
Run Code Online (Sandbox Code Playgroud)

在我的php文件中,我有以下内容来创建带有FPDF库的PDF :

function download_pdf()
{
    $id = $_POST['fid'];

    $pdf = new FPDF();

    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->Cell(40,10,'Hello World!');

    header('Content-Type: application/pdf');
    header('Content-Disposition: attachment; filename=' . $id . '.pdf');

    $pdf->Output('Order123.pdf', 'D');
}
Run Code Online (Sandbox Code Playgroud)

但请求是响应此而不是打开保存对话框来保存我的pdf.

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> streamx3Rðâ2Ð35W(çrQÐw3T04Ó30PISpêZ*[¤(hx¤æää+çå¤(j*dÔ7Wstndstreamendobj 1 0 obj <endobj 5 0 obj <endobj 2 0 obj <</ProcSet [/ PDF/Text/ImageB/ImageC/ImageI]/Font …

javascript php ajax fpdf angularjs

33
推荐指数
2
解决办法
5361
查看次数

获取控制器中的环境值

在我的.env文件中,我有以下内容:

IMAP_HOSTNAME_TEST=imap.gmail.com
IMAP_USERNAME_TEST=myemail@gmail.com
IMAP_PASSWORD_TEST=mypw
Run Code Online (Sandbox Code Playgroud)

现在我想在我的控制器中使用它们.我试过这个,但没有结果:

$hostname = config('IMAP_HOSTNAME_TEST');
Run Code Online (Sandbox Code Playgroud)

$ hostname变量等于null.如何在控制器中使用这些配置变量?

php config laravel laravel-5.1

33
推荐指数
6
解决办法
8万
查看次数

Select2以输入字段而不是下拉列表开始

我使用js库select2.这是我现在拥有的截图:
开始:
在此输入图像描述
点击下拉列表:
在此输入图像描述

现在可以有一个输入字段,而不是直接下拉列表吗?我知道这是可能的,因为你可以在select2网站上找到它.一个例子是: 在此输入图像描述 在此输入图像描述

但文档非常简短.这就是我现在拥有的:

<input type="text" name="questions[question1]" id="question1" class="question1" style="width:500px"/>
Run Code Online (Sandbox Code Playgroud)
function createQuestionTags(data, question_number){
  $(".question" + question_number).select2({
    createSearchChoice: function (term, data) {
      if ($(data).filter(function () {
        return this.text.localeCompare(term) === 0;
      }).length === 0) {
        return {
          id: term,
          text: term
        };
      }
    },
    data: data,
    placeholder: "Enter Question",
    allowClear:true
  });
}
Run Code Online (Sandbox Code Playgroud)

(数据是从ajax调用接收的)

javascript jquery input jquery-select2 drop-down-menu

32
推荐指数
4
解决办法
8万
查看次数

在严格模式之外尚不支持块范围声明

我在我的Homestead流浪盒上运行Laravel 5.4.我用npm install命令安装了所有npm依赖项.这没有产生任何错误.

在我的webpack.min.js文件中,我有:

const { mix } = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js([
        'resources/assets/plugins/jquery-1.11.3.min.js',
        'resources/assets/plugins/bootstrap/js/bootstrap.min.js',
        'resources/assets/js/main.js'
    ], 'public/js'
);

mix.combine([
       'resources/assets/plugins/bootstrap/css/bootstrap.min.css',
       'resources/assets/plugins/font-awesome/css/font-awesome.css',
       'resources/assets/css/styles.css'
   ], 'public/css/all.css');
Run Code Online (Sandbox Code Playgroud)

当我想要运行时,npm …

elixir-mix node.js laravel webpack laravel-5

31
推荐指数
4
解决办法
7万
查看次数

将JSON对象推送到localStorage中的数组

我在Javascript中有一个函数:

var a = [];
function SaveDataToLocalStorage(data)
{       
    var receiveddata = JSON.stringify(data);
    a.push(receiveddata);
    alert(a);

    localStorage.setItem('session', a);

}
Run Code Online (Sandbox Code Playgroud)

data参数是JSON对象.

但每次我点击按钮它都会覆盖我本地存储中的数据.

有人知道怎么做这个吗?

javascript json object local-storage

27
推荐指数
4
解决办法
10万
查看次数

Sonata Admin(2.3)中的嵌套集合字段

我在创建课程时遇到了问题.这是我正在尝试创建表单的数据库方案的一部分:

在此输入图像描述

我正在尝试做的是创建一个课程,我可以创建会话和日期(时刻)附加到该会话.它应该看起来像这样:

在此输入图像描述

在我的CourseAdmin课程中,我有:

protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->add('name',                   'text',         array('label' => 'Naam'))
        ->add('description',            'textarea',     array('label' => 'Beschrijving'))
        ->add('materials',              'textarea',     array('label' => 'Benodigde materialen'))
        ->add('numberOfParticipants',   'number',       array('label' => 'Aantal deelnembers'))
        ->add('numberOfDays',           'number',       array('label' => 'Aantal dagen'))
        ->add('price',                  'number',       array('label' => 'Prijs'))
        ->add('priceKmo',               'number',       array('label' => 'KMO-portefeuille Prijs'))

        ->add('location', 'sonata_type_model', array('expanded' => true, 'by_reference' => false, 'multiple' => true, 'btn_add' => false))

        ->add('session', 'sonata_type_collection', array(
            'by_reference' => false,
            'type_options' => array(
                // Prevents the "Delete" option from being …
Run Code Online (Sandbox Code Playgroud)

php nested symfony symfony-sonata sonata-admin

24
推荐指数
1
解决办法
2509
查看次数

AngularJS中的jQuery文件上传

我正在尝试使用jQuery File Upload和angularJS 上传文件.

我有一个多步形式,这是我的多步形式的两个步骤:

<div ng-switch="step">
    <div ng-switch-when="1">
        <h1>Identity</h1>
        <form name="steponeForm" data-file-upload="options" enctype="multipart/form-data" novalidate autocomplete="off">
            <input type="submit" ng-click="next(steponeForm.$valid)" value="next" /><br>

            <span class="button fileinput-button" ng-class="{disabled: disabled}">
                <input type="file" id="fileupload" name="files[]" multiple="" >
            </span>
            <button type="button" class="btn btn-primary start" data-ng-click="submit()">
                <span>Start upload</span>
            </button>

            <input ng-model="application.lastName" string-pattern required type="text" placeholder="{{ 'Last name'|translate }} *" name="appname" id="appname" />
            <div ng-show="steponeForm.$submitted || steponeForm.appname.$touched">
                <div class="error" ng-show="steponeForm.appname.$error.required">Last name is required.</div>
                <div class="error" ng-show="steponeForm.appname.$error.stringPattern">Doesn't look like a text.</div>
            </div>

            <input type="submit" ng-click="next(steponeForm.$valid)" value="next" …
Run Code Online (Sandbox Code Playgroud)

javascript jquery file-upload angularjs jquery-file-upload

20
推荐指数
2
解决办法
8009
查看次数

WordPress项目旁边的Laravel项目(在public_html文件夹中)

我的public_html文件夹中有一个Laravel项目.域名是例如domain.com我的.htaccess文件(在public_html文件夹中)是这样的:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

有以下路线:

  • API/licenseplate
  • API /日历
  • 认证/注册
  • 管理/设置
  • 管理员/约会
  • 约定
  • ...

所以URL的一个例子是http://domain.com/appointment.

现在我想在domain.com上有一个wordpress网站.因此,当您访问domain.com时,您会看到wordpress网站.但是我也希望得到像我的laravel项目的/约会的网址.

什么是最简单,最干净的方法?

php wordpress .htaccess http laravel

18
推荐指数
1
解决办法
1397
查看次数

在表格中添加一个 - 背包laravel

我正在使用Backpack for Laravel来提供我的laravel网站的后端区域.

我的数据库结构中有以下表格:

在此输入图像描述

这是为匹配添加集合,并为锦标赛添加匹配.

这些是我的模特:

比赛模型:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;

class Tournament extends Model
{
    use CrudTrait;

     /*
    |--------------------------------------------------------------------------
    | GLOBAL VARIABLES
    |--------------------------------------------------------------------------
    */

    protected $fillable = ['from', 'to', 'type', 'location', 'place'];

    /*
    |--------------------------------------------------------------------------
    | RELATIONS
    |--------------------------------------------------------------------------
    */

    public function matches()
    {
        return $this->hasMany('App\Models\Match');
    }
}
Run Code Online (Sandbox Code Playgroud)

匹配模型:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;

class Match extends Model
{
    use CrudTrait;

     /*
    |--------------------------------------------------------------------------
    | GLOBAL VARIABLES
    |--------------------------------------------------------------------------
    */

    protected $table …
Run Code Online (Sandbox Code Playgroud)

php one-to-many laravel laravel-5 backpack-for-laravel

17
推荐指数
1
解决办法
1309
查看次数

不支持Driver []. - Laravel 5.3

我正在使用backpackforlaravel设置我网站的后端区域.我在ProjectCrudController中添加了一个图像字段:

$this->crud->addField([
    'label' => "Project Image",
    'name' => "image",
    'type' => 'image',
    'upload' => true,
], 'both');
Run Code Online (Sandbox Code Playgroud)

在我的模型项目中,我有一个像这样的mutator:

public function setImageAttribute($value)
{
    $attribute_name = "image";
    $disk = "public_folder";
    $destination_path = "uploads/images";

    // if the image was erased
    if ($value==null) {
        // delete the image from disk
        \Storage::disk($disk)->delete($this->image);

        // set null in the database column
        $this->attributes[$attribute_name] = null;
    }

    // if a base64 was sent, store it in the db
    if (starts_with($value, 'data:image')) …
Run Code Online (Sandbox Code Playgroud)

php image laravel laravel-5.3 backpack-for-laravel

15
推荐指数
1
解决办法
3万
查看次数