我喜欢干净的文档和phpdoc将自动查找类型.在记录返回View :: make的控制器函数时,我不知道在我的文档中@return使用什么类型.
<?php
class FooController extends BaseController {
/**
* Show a view.
*
* @return ??? description of the view
*/
public function show(){
return View::make('bar');
}
}
Run Code Online (Sandbox Code Playgroud)
这里的类型是什么,还是有更好的方法来记录这个功能?
为了将路径定义为资源Route::resource,文档指出:
Verb Path Action Route Name
-------------------------------------------------------------------
GET /resource index resource.index
GET /resource/create create resource.create
POST /resource store resource.store
GET /resource/{resource} show resource.show
GET /resource/{resource}/edit edit resource.edit
PUT/PATCH /resource/{resource} update resource.update
DELETE /resource/{resource} destroy resource.destroy
Run Code Online (Sandbox Code Playgroud)
按照典型的REST CRUD,PUT/PATCH用于更新操作,DELETE用于destroy操作.我认为这意味着定义典型的资源交互,即使在手动定义自己的路由和控制器操作时也是如此.
以下是我对与Laravel进行这些交互的理解的核心:
Route::put和DELETE 来定义接受PUT的路径Route::delete.Input门面用Illuminate\Http\Request::input典型化的相互作用,将返回json_decode的JSON的内容,所有的GET GET请求或POST的所有参数,否则参数.我们必须使用json或者根本不使用PUT或DELETE(很好,因为http PUT和DELETE请求不是普遍支持的)._method数据中的a ,以便路由可以强制执行动词.PUT和DELETE是否仅用于创建外部可访问的json REST API,还是用于其他目的?除了使用不同的端点路由到相同的URI,是否存在一些好处,强制存在_methodin $_POST或json?
PUT和DELETE应该是幂等的,但这甚至在Laravel中实现了吗?这是我必须在我的控制器中发生的事情,还是路由以某种方式强制执行?
本质上,如果Laravel中的PUT和DELETE在功能上与POST相同,除了REST语义和并行路由之外,我何时以及为什么要在POST上使用它们?
在我尝试通过引用刀片@include来找到传递变量的方法时,我构建了一个简单的测试用例,它还演示了执行的模板顺序非常不稳定.有没有办法使用刀片模板和变量执行顺序的变量(特别是关于部分)?
testLayout.blade.php
<!DOCTYPE html>
<html>
<head>
</head>
<body>
{{"this is the layout: ".++$tabindex."<br>"}}
@include('testInclude')
{{"this is the layout after include: ".++$tabindex."<br>"}}
@include('testInclude',array('tabindex'=>$tabindex))
{{"this is the layout after passing include: ".++$tabindex."<br>"}}
@yield('testYield')
{{"this is the layout after yield: ".++$tabindex."<br>"}}
@section('testSection')
{{"this is the layout section: ".++$tabindex."<br>"}}
@show
{{"this is the layout after section: ".++$tabindex."<br>"}}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
testExtension.blade.php
@extends('testLayout')
{{"this is the extension: ".++$tabindex."<br>"}}
@include('testInclude')
{{"this is the extension after include: ".++$tabindex."<br>"}}
@include('testInclude',array('tabindex'=>$tabindex))
{{"this is the extension after …Run Code Online (Sandbox Code Playgroud) 在Laravel 4.2设置中,我在模板中有一个变量,我希望在多个包含中共享:
master.blade
<?php $tabindex = 0; ?>{{--This is the variable--}}
@include('header'){{-- <-in header.blade, I often use ++$tabindex --}}
{{--$tabindex is still 0--}}
@include('content'){{-- <-in content.blade, I often use ++$tabindex --}}
{{--$tabindex is still 0--}}
@include('footer'){{-- <-in footer.blade, I often use ++$tabindex --}}
{{--$tabindex is still 0--}}
Run Code Online (Sandbox Code Playgroud)
$tabindex如果用作tabindex html属性显然是一个简单的例子,我可以使用安全值和足够大的缓冲区值来解决这个问题,但这并不是优雅或解决手头的实际问题.在常规的php包含中,我的理解是包含文件中的变量赋值会影响包含文件中的变量 - 这是所需的效果.
我尝试过View::share(),但它出现了同样的症状.将值传递给@include数组显然是通过值传递并产生相同的效果.
看起来似乎首先对包含范围值进行整体评估,然后是包含范围.如果是这种情况,如果在包含范围中有任何用法或者进一步包含范围(甚至通过某些持久存储器存储),那么它将使我正在尝试做的更不可行,因为执行的顺序会有所不同比代码中的顺序.
是否有一些未记录的刀片巫术,以防止刀片@include切断其改变其包含变量的值,或者我必须回到直接的PHP include或其他一些丑陋的替代品(Session变量应该坚持他们的值调用包括范围,但这只是一个令人讨厌和脆弱的方法)?