首页 \ 问答 \ Laravel4:我如何使用Eloquent / Model(Laravel4: How can I use Eloquent/Model)

Laravel4:我如何使用Eloquent / Model(Laravel4: How can I use Eloquent/Model)

我已经阅读并阅读了http://laravel.com/docs/eloquent上的文档,我尝试了一些我在这里找到的代码,这是我到目前为止的代码模型

dbeloquent.php

<?php
class dbeloquent extends Eloquent {

   protected  $table = "users";


    public  function showTbl()
        {
             dd(dbeloquent::$table);
        }
}

//end of model
?>

    route.php

<?php
Route::get('/', function () {
    $model = new dbeloquent();   
    dd($model->someFunction());
});
?>

我想首先展示我的桌子,但这就是我所拥有的

访问未声明的静态属性:dbeloquent :: $ table

请有人帮帮我


I've read and followed documentation found here http://laravel.com/docs/eloquent and I tried some of the examples i found here here is the code that I have so far model

dbeloquent.php

<?php
class dbeloquent extends Eloquent {

   protected  $table = "users";


    public  function showTbl()
        {
             dd(dbeloquent::$table);
        }
}

//end of model
?>

    route.php

<?php
Route::get('/', function () {
    $model = new dbeloquent();   
    dd($model->someFunction());
});
?>

I want to show my tables first but here is what I'm having

Access to undeclared static property: dbeloquent::$table

somebody help me please


原文:https://stackoverflow.com/questions/22006637
更新时间:2022-05-06 19:05

最满意答案

总是有很多方法可以做到,因此要将文件上传到S3存储桶中,您可以:

  • 使用aws CLI并运行aws s3 cp ...
  • 使用aws CLI并运行aws s3api put-object ...
  • 使用aws SDK(您选择的语言)

您也可以使用sync方法,但对于单个文件,则不需要同步整个目录,并且通常在寻找更好的性能时,最好启动多个cp实例以受益于多线程vs同步单线程。

基本上所有这些方法都是aws S3 API调用的封装。 从亚马逊文件

直接从代码中调用REST API调用可能很麻烦。 它要求您编写必要的代码来计算有效签名以验证您的请求。 我们推荐以下替代方案:

  • 使用AWS软件开发工具包发送您的请求(请参阅示例代码和库)。 使用此选项,您不需要编写代码来计算请求身份验证的签名,因为SDK客户端使用您提供的访问密钥来验证您的请求。 除非您有充分的理由不这样做,否则应始终使用AWS软件开发工具包
  • 使用AWS CLI创建Amazon S3 API调用。 有关设置AWS CLI和示例Amazon S3命令的信息,请参阅以下主题:在Amazon Simple Storage Service开发人员指南中设置AWS CLI。 在AWS Command Line Interface用户指南中使用Amazon S3和AWS Command Line Interface。

所以亚马逊会推荐使用SDK。 在一天结束时,我认为它确实是你最舒服的一件事,以及你将如何将这段代码整合到你的程序的其余部分。 对于一次性行动,我总是去CLI。

就性能而言,使用其中一个或另一个不会再起作用,它们只是对AWS API调用的封装。 对于传输优化,您应该查看aws s3传输加速并查看是否可以启用它


There's always more than way to make on thing, so to upload a file into a S3 bucket you can :

  • use aws CLI and run aws s3 cp ...
  • use aws CLI and run aws s3api put-object ...
  • use aws SDK (your language of choice)

you can also use sync method but for a single file, there's no need to sync a whole directory, and generally when looking for better performance its better to start multiple cp instances to benefit from multi thread vs sync mono-thread.

basically all this methods are wrapper for the aws S3 API calls. From amazon doc

Making REST API calls directly from your code can be cumbersome. It requires you to write the necessary code to calculate a valid signature to authenticate your requests. We recommend the following alternatives instead:

  • Use the AWS SDKs to send your requests (see Sample Code and Libraries). With this option, you don't need to write code to calculate a signature for request authentication because the SDK clients authenticate your requests by using access keys that you provide. Unless you have a good reason not to, you should always use the AWS SDKs.
  • Use the AWS CLI to make Amazon S3 API calls. For information about setting up the AWS CLI and example Amazon S3 commands see the following topics: Set Up the AWS CLI in the Amazon Simple Storage Service Developer Guide. Using Amazon S3 with the AWS Command Line Interface in the AWS Command Line Interface User Guide.

so Amazon would recommend to use the SDK. At the end of the day, I think its really a matter to what you're most comfortable and how you will integrate this piece of code into the rest of your program. For one-time action, I always go to CLI.

In term of performance though, using one or the other will not make difference as again they're just wrapper to AWS API call. For transfer optimization, you should look at aws s3 transfer acceleration and see if you can enable it

相关问答

更多
  • 怪胎我终于找到了解决方案或者至少找到了解决方案。 将我的基于客户端aws-sdk的解决方案迁移到服务器生成signedUrl的解决方案后,我仍然面临同样的错误。 简而言之,它通过在标题的内容类型中设置两侧来解决问题。 我的代码如果有人有一天面临同样的问题: 服务器Node.js var AWS = require('aws-sdk'); AWS.config.update({accessKeyId: "myKey", secretAccessKey: "mySecret"}); AWS.config.re ...
  • https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS “此外,对于可能对服务器数据造成副作用的HTTP请求方法(特别是对于GET以外的HTTP方法,或对某些MIME类型的POST使用),规范要求浏览器”预检“请求,请求支持来自服务器的方法使用HTTP OPTIONS请求方法,然后,在服务器“批准”后,使用实际的HTTP请求方法发送实际请求。“ https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS ...
  • 您需要使用读取流,而不是写入流。 此外,您不应该将流包装在Buffer中。 var param = { Bucket: 'sql-dev', Key: 'Report', Body: fs.createReadStream('./temp/ALL.csv') }; s3bucket.putObject(param, function(err, data){ if(err) console.log(err); else console.log(data); }); ...
  • 根据putObject的API文档 ,您可能正在查找WebsiteRedirectLocation参数。 你为什么不试一试: $result = $client->putObject(array( 'Bucket' => $hello, 'Key' => $hellokey, 'Body' => 'the body', 'ContentType' => 'text/html', 'WebsiteRedirectLocation' => 'http://www.cnn. ...
  • 基于亚马逊文档 ,我坚持使用TransferUtility.Upload : 为管理传入和传出Amazon S3的传输提供高级实用程序。 TransferUtility提供了一个简单的API,用于将内容上传到Amazon S3并从中下载内容。 它广泛使用Amazon S3分段上传来实现增强的吞吐量,性能和可靠性。 通过指定文件路径而不是流来上传大文件时,TransferUtility使用多个线程一次上传单个上传的多个部分。 在处理大容量内容和高带宽时,这可以显着提高吞吐量。 但请注意可能的并发问题以及有关使 ...
  • 总是有很多方法可以做到,因此要将文件上传到S3存储桶中,您可以: 使用aws CLI并运行aws s3 cp ... 使用aws CLI并运行aws s3api put-object ... 使用aws SDK(您选择的语言) 您也可以使用sync方法,但对于单个文件,则不需要同步整个目录,并且通常在寻找更好的性能时,最好启动多个cp实例以受益于多线程vs同步单线程。 基本上所有这些方法都是aws S3 API调用的封装。 从亚马逊文件 直接从代码中调用REST API调用可能很麻烦。 它要求您编写必要的代 ...
  • 而不是...... ContentType: 'text/html' ...明确告诉浏览器内容的字符编码: ContentType: 'text/html; charset=utf-8' 这将设置S3将在HTTP Content-Type响应标头中返回的内容类型和子类型 ,浏览器使用该标头正确解释对象数据。 Instead of this... ContentType: 'text/html' ...explicitly tell the browser the character encoding ...
  • 在传递给putObject()函数的参数中,包含一个Metadata键,其中包含要与S3对象一起存储的元数据的键/值对。 例: s3.putObject({Key: 'sea/animal.json', Metadata: {MyKey: 'MyValue', MyKey2: 'MyValue2'}, Body: '{"is dog":false,"name":"otter","stringified object?":true}'}, function(err, data) { ... }); 请参阅: ...
  • 至少在签名版本2中, Content-Type标头中的值是签名算法的一个组成部分...所以如果getSignedUrl不知道你要放在那里,它将生成一个签名,无效。 您应该可以将它添加到参数中的键/值对中: ContentType, 'text/plain' // using the appropriate mine type string In Signature Version 2, at least, the value from the Content-Type header is an integ ...
  • CloudFront使用该信息来了解从S3缓存对象的时间。 或者,如果您在没有CloudFront的情况下从S3提供静态网站,浏览器将使用它来确定在本地浏览器缓存中缓存文件的时间。 That info is used by CloudFront to know how long to cache objects from S3. Or if you are serving a static website from S3 without CloudFront, it would be used by bro ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。