首页 > 解决方案 > 如何在php刀片视图中添加php旧代码

问题描述

我开始了一个 laravel + vuejs 项目(fontend 和 backend 在同一个项目中)。它基本上是从纯 php-html 项目的迁移。我想知道是否可以只迁移其中的一部分,并整合其余部分。在你回答之后(谢谢:)),这里是 myview.blade.php:

@extends('template')

@section('contenu')
<div id="app">
    @php
       $path = public_path('myview/oldfile.php');
       include($path);
    @endphp
</div>
@endsection

现在我有一个问题:

** 第一期 **

我在旧的 php 文件中有这种代码:

<script type="text/javascript" src="./js/jquery-1.7.2.min.js">

但我的模板中也有脚本(包含导航栏和页脚)。然后我当然得到这个错误

[Vue warn]: Error compiling template:

Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <style>, as they will not be parsed.

** 问题 2 **

    $.post("./myview.php", "mode=activateForm&id1=<?=$id1?>&id2=<?=$_GET["id2"]?>", function() {

MethodNotAllowedHttpException
The POST method is not supported for this route. Supported methods: GET, HEAD.

新问题是这个,我不明白为什么......

有什么建议么?

标签: phplaravel

解决方案


当您在刀片模板中使用 @include 时,它​​会在resource/views目录中查找文件。所以像这样使用它@include('posts/index')

它将在views/posts/目录中查找 index.php。

不要在@include 中使用.php。

@extends('template')

@section('contenu')
<div id="app">

@include("yourDirectory/oldfile");

</div>
@endsection

推荐阅读