Laravel 4:我如何理解它是如何工作的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14348100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 4: how can I understand how it all works?
提问by duality_
I am using Laravel 3 in one project and it's been a joy. I have also looked at the source code several times to see how some things work behind the scenes.
我在一个项目中使用 Laravel 3,这是一种乐趣。我还多次查看了源代码,以了解某些事情在幕后是如何工作的。
But now in Laravel 4, I don't know where to begin or how to understand it all. Where can I learn all the behind the scenes of Laravel 4?
但是现在在 Laravel 4 中,我不知道从哪里开始或如何理解这一切。我在哪里可以了解 Laravel 4 的所有幕后知识?
Case in point: I wanted to find out if the DB::insert()
returns the id of inserted row. So I started searching.
1. I found the Illuminate\Support\Facades\Facade class that "encapsulates" DB.
2. The resolveFacadeInstance function is called and then I tried to print these arrays, but my computer hangs :-/. And I'm sure this would lead to many more classes that I wouldn't understand.
举个例子:我想知道是否DB::insert()
返回插入行的 id。于是我开始寻找。1.我找到了“封装”DB的Illuminate\Support\Facades\Facade类。2. resolveFacadeInstance 函数被调用,然后我试图打印这些数组,但我的电脑挂了:-/。而且我确信这会导致更多我无法理解的课程。
Is there a way I could try to learn the inner workings of Laravel 4? Maybe stack traces?
有没有办法让我尝试学习 Laravel 4 的内部工作原理?也许堆栈跟踪?
回答by socketman
The facade class is just a filter class to allow you to call methods as if they were static. For the facade mappings go here: http://laravel.com/docs/facades#facade-class-reference
外观类只是一个过滤器类,允许您像调用静态方法一样调用方法。对于门面映射去这里:http: //laravel.com/docs/facades#facade-class-reference
The starting point to fully understand laravel's inner-workings should begin at:
完全理解 laravel 的内部工作原理的起点应该是:
/public/index.php
You can follow the logic of the program, noticing that requires start.php, which loads an instance of the "Application" which is found here:
您可以遵循程序的逻辑,注意需要 start.php,它会加载“应用程序”的一个实例,该实例位于此处:
/vendor/laravel/framework/src/Illuminate/Foundation/Application.php
回答by David Oliver
This Tuts+ videoshows a couple of ways of finding out what class is actually doing the work.
这个 Tuts+ 视频展示了几种找出哪个班级实际上在做这项工作的方法。
E.g.:
例如:
$root = get_class(DB::getFacadeRoot());
var_dump($root);
回答by Maxime Fabre
You can check out the early docs for Laravel 4 here : http://four.laravel.com/– that should give you a good starting point
你可以在这里查看 Laravel 4 的早期文档:http://four.laravel.com/——这应该给你一个很好的起点
回答by thestepafter
The actual Laravel 4 code is well documented in the files. If you want to understand the inner workings then open up the source code files and read the notes. For example I looked up the DB::insert() code in /vendor/laravel/framework/src/Illuminate/Foundation/Application.php.
实际的 Laravel 4 代码在文件中有详细记录。如果您想了解内部工作原理,请打开源代码文件并阅读注释。例如,我在 /vendor/laravel/framework/src/Illuminate/Foundation/Application.php 中查找了 DB::insert() 代码。
/**
* Run an insert statement against the database.
*
* @param string $query
* @param array $bindings
* @return bool
*/
public function insert($query, $bindings = array())
{
return $this->statement($query, $bindings);
}
Ok, so this is calling the statement function so I search for function statement in the same code / class:
好的,所以这是调用语句函数,所以我在相同的代码/类中搜索函数语句:
/**
* Execute an SQL statement and return the boolean result.
*
* @param string $query
* @param array $bindings
* @return bool
*/
public function statement($query, $bindings = array())
{
return $this->run($query, $bindings, function($me, $query, $bindings)
{
if ($me->pretending()) return true;
$bindings = $me->prepareBindings($bindings);
return $me->getPdo()->prepare($query)->execute($bindings);
});
}
We can now see that this returns the boolean result based on the comments above the code.
我们现在可以看到,这会根据代码上方的注释返回布尔结果。
回答by quantme
If you come from Laravel 3 this articleis for you. After that you should read the other tutorialsof that series.
如果你来自 Laravel 3,这篇文章适合你。之后,您应该阅读该系列的其他教程。
Author's note:
作者注:
This article should outline some of the more important changes to Laravel between versions 3 and the upcoming version 4. Bear in mind this isn't all of the changes. As the release of Laravel 4 gets closer I'll keep this article up to date. If you're having any problems with Laravel 4 please jump on to #laravelon Freenode. At this time we'd like to ask people not to post help topics on the forums.
本文应概述 Laravel 版本 3 和即将发布的版本 4 之间的一些更重要的更改。请记住,这不是所有更改。随着 Laravel 4 的发布越来越近,我会及时更新这篇文章。如果您在使用 Laravel 4 时遇到任何问题,请跳转到Freenode上的#laravel。目前,我们希望人们不要在论坛上发布帮助主题。