我认为这可以自动获取user,replies当我将对象序列化为JSON时,但toArray实际上是否正确地覆盖了这个?
<?php
class Post extends Eloquent
{
protected $table = 'posts';
protected $fillable = array('parent_post_id', 'user_id', 'subject', 'body');
public function user()
{
return $this->belongsTo('User');
}
public function replies()
{
return $this->hasMany('Post', 'parent_post_id', 'id');
}
public function toArray()
{
$this->load('user', 'replies');
return parent::toArray();
}
}
Run Code Online (Sandbox Code Playgroud) Facebook推出了一种新的编程语言,它看起来就像是PHP的扩展.他们称之为Hack,它在他们的HHVM引擎上运行.
在看到他们的网站并阅读了一下之后,我想知道从PHP到Hack的迁移有多么流畅.
让我们围绕已经部署到LEMP或LAMP堆栈的Web应用程序进行讨论.
我的一些初步想法和行动清单包括:
那么,你会怎么做呢?
我正在尝试利用由blueimp开发的jQuery文件上传插件中提供的客户端图像大小调整:https://github.com/blueimp/jQuery-File-Upload
不幸的是,我不能让图像调整大小工作.上传本身运作完美.
this.$('.fileupload').fileupload({
url: websiteUrl + 'deed/uploadimage',
dataType: 'json',
previewMaxWidth: 90,
previewMaxHeight: 90,
previewCrop: true,
imageOrientation: true,
disableImageResize: false,
add: function($, data) {
_.each(data.files, function(file){
file.model = self.addImagePreview();
});
_.defer(_.bind(data.submit, data));
},
done: function($, data) {
// Quirky shit. Iterate over data.files array while we know that
// only one file are uploaded at a time...
_.each(data.files, function(file){
file.model.set({
"uploading": false,
"src": data.response().result.image,
"preview": data.response().result.cropped
});
});
}
});
Run Code Online (Sandbox Code Playgroud)
我已经尝试在resizeImage方法中放置一个断点,看看它是否由于某种原因破坏了其中一个条件,但是从不调用该方法.
所有依赖项按此顺序加载:
load-image.min.js
canvas-to-blob.js
jquery.ui.widget.js
jquery.fileupload.js …Run Code Online (Sandbox Code Playgroud) 我遇到了一个令我困惑的问题.
我对此问题的参考是Mac上的Chrome 32和iOS 7.0.4上的Safari.
在下面的示例中,Chrome将文本中的文本.background和textarea元素完美地呈现在彼此之上,这就是我想要的.iOS上的Safari可以抵消textarea3个像素单元中的文本.虽然填充,边框和边距在两个元素上设置为相同的值,但会发生这种情况.
当我在Safari的开发人员工具中调试时,无论是通过我的iPhone设备还是iOS模拟器,在概述元素指标时,元素本身都能完美对齐.

标记
<div class="container">
<div class="background">This is a test</div>
<textarea>This is a test</textarea>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
.container {
border: 1px solid #cdcdcd;
background: #f0f0f0;
width: 400px;
height: 50px;
position: relative;
margin: 24px 0;
}
.background {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
color: #f00;
}
textarea {
width: 100%;
height: 100%;
box-sizing: border-box;
background: transparent;
border: 0;
position: relative;
z-index: 2;
}
Run Code Online (Sandbox Code Playgroud)
我没能找到解决这个问题的正确方法.正如您在PHP文档中的示例#3中看到的那样,他们声明在使用DateTime :: add中的DateInterval 添加月份时必须要注意.
对于为什么方法的行为是这样的,并且我可以做些什么来避免这种情况并没有任何解释,我发现这是一个错误.
有人对此有所了解吗?
所以我在这里磕磕绊绊,因为我已经发现PHP不会从PUT请求中读取HTTP请求体.当Content-Type请求中的标题设置为时application/json,似乎没有任何方法可以获取正文.
我正在使用Laravel,它在Symfony2的HttpFoundation lib之上构建了他们的请求层.
我用jQuery对此进行了一些调试,这些是一些示例请求:
做这样的请求,我可以通过找到内容 Input::getContent()
$.ajax({
url: 'http://api.host/profiles/12?access_token=abcdef',
type: 'PUT',
data: {"profiles":[{"name":"yolanda ellis","email":"yolanda.ellis12@example.com"}]}
});
Run Code Online (Sandbox Code Playgroud)
file_get_contents('php://input')虽然我无法获得内容.默认情况下,jQuery将数据发送为application/x-www-form-urlencoded.
当我在请求中传递另一个Content-Type时,它变得更加令人费解.就像Ember-Data一样:
$.ajax({
url: 'http://api.host/profiles/12?access_token=abcdef',
type: 'PUT',
data: {"profiles":[{"name":"yolanda ellis","email":"yolanda.ellis12@example.com"}]},
contentType: 'application/json'
});
Run Code Online (Sandbox Code Playgroud)
当这样做时,数据似乎无处可寻.这意味着我的Ember.js应用程序无法正常使用我的API.
这到底是怎么回事?
编辑
以下是Chrome DevTools中的完整请求示例:http://pastebin.com/ZEjDAsmJ
我发现这是一个特定的Laravel问题.
编辑2:找到答案
似乎我的项目中存在一个依赖项,它从标头与请求一起发送php://input时读取Content-Type: application/json.这会清除流 - 正如@ Mark_1提供的链接所指出的那样 - 当它到达Laravel时它会变空.
我有一个数组,我从我的数据库中获取.例如:
$db_record = $this->search_model->search_Employee();
foreach ($db_record as $db_data) {
echo $db_data->phone_number;
}
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,我能够毫无问题地获取记录,但我想在$db_data之后添加其他数据.
foreach ($db_record as $db_data) {
echo $db_data->phone_number;
$db_data[]['new_value']='prashant';
}
Run Code Online (Sandbox Code Playgroud)
但$db_data[]['new_value']='prashant';抛出以下错误
Cannot use object of type stdClass as array in
Run Code Online (Sandbox Code Playgroud)
如果有人可以帮助我超过5个小时,这将是很好的.