BKF*_*BKF 5 php laravel laravel-5 laravel-5.1 laravel-blade
使用 Laravel 5.1,我可以动态地将自定义代码插入刀片视图吗?例如,我有这个view.blade.php:
<html>
<head>
<title>App Name - @yield('title')</title>
</head>
<body>
@section('sidebar')
This is the master sidebar.
@show
<div class="container">
@yield('content')
// Here, I want to insert a code dynamically, for example :
<div> <p> something </p> </div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
那么,有没有一种好方法可以在控制器中做这样的事情:
$customCode = "<div> <p> something </p> </div>";
$content = (string) $view;
//For example I want to insert this code into view file on line 11
updateContent($content, $customCode, $line_position_in_view);
Run Code Online (Sandbox Code Playgroud)
这是您的 jQuery 代码:
您的 HTML 文件或查看文件
<div class="container">
@yield('content')
// Here, I want insert a code dynamically, for example :
<div> <p> something </p> </div>
</div>
$.post("test.php",{},function (data){
$(".container").append(data);
});
Run Code Online (Sandbox Code Playgroud)
注意:如果您想使用控制器功能,请更改test.php函数名称和正确的路径。
test.php 文件或控制器函数
<?php
echo "<div> <p> something </p> </div>";
exit;
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2682 次 |
| 最近记录: |