Strict(2048):CsvImportBehavior :: setup()的声明应该与ModelBehavior兼容 [英] Strict (2048): Declaration of CsvImportBehavior::setup() should be compatible with ModelBehavior

查看:300
本文介绍了Strict(2048):CsvImportBehavior :: setup()的声明应该与ModelBehavior兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误:

 严格(2048):CsvImportBehavior :: setup 
with ModelBehavior :: setup(Model $ model,$ config = Array)
[APP\Plugin\Utils\Model\Behavior\CsvImportBehavior.php,第20行]

enable-csv-import-all-controllers-models-cakephp-2rel =nofollow> http://www.pronique.com/blog/enable-csv-import-all-controllers-models-cakephp-2



当我导入我的CSV文件时,它会给出以下闪光灯消息:

 已成功从Book1.csv导入0条记录

我不明白为什么



我查看了内部的行为(CsvImportBehaviour.php在第20行): class CsvImportBehavior extends ModelBehavior {

这在第20行没有意义,这只是类声明,所以我向下移动代码,看到以下内容: public function setup(Model& $ Model,$ settings = array()){ - 这似乎是按照标准。

解决方案

要抑制错误/警告,请尝试:




  • 删除 $ Model 之前的& (不需要,因为Model是一个对象, / em> (请参阅@mark的评论):

    $ b $

    b

    • 重命名 $ Model $ model (小写)


    • 重命名 $ settings $ config




    我不知道不从CSV导入记录的原因,



    替代品



    CakePHP还有一个 CSV dataSource 作为数据源插件的一部分。



    使用它,您可以创建一个Model,而不是使用数据库,使用CSV文件作为其源。这允许你,例如,这样做;

      $ csvData = $ this-> MyCsvModel-&所有'); 

    这将返回CSV文件中的所有行。将 $ csvData 保存到另一个模型



    链接:



    https://github.com/cakephp/datasources /tree/2.0
    https:/ /github.com/cakephp/datasources/blob/2.0/Model/Datasource/CsvSource.php


    I am getting the following error:

    Strict (2048): Declaration of CsvImportBehavior::setup() should be compatible 
    with ModelBehavior::setup(Model $model, $config = Array) 
    [APP\Plugin\Utils\Model\Behavior\CsvImportBehavior.php, line 20]
    

    I followed the tutorial on this site: http://www.pronique.com/blog/enable-csv-import-all-controllers-models-cakephp-2

    When I import my CSV file, it gives the following flash message:

    Successfully imported 0 records from Book1.csv
    

    I don't understand why its not importing, does it have something to do with the error/warning its giving?

    I looked inside the behaviour (CsvImportBehaviour.php at line 20): class CsvImportBehavior extends ModelBehavior {
    That does not make sense on line 20, that's just the class declaration, so I moved down on the code and saw the following: public function setup(Model &$Model, $settings = array()) {-- this does seem to me to be according to the standards.

    解决方案

    To suppress the errors/warnings, try to:

    • remove the & before $Model (not required as Model is an object and therefore already passed byref)

    Optionally (see comment by @mark):

    • rename $Model to $model (lowercase)

    • rename $settings to $config

    I don't know the reason for not importing records from the CSV, that will require debugging on your side.

    Alternatives

    CakePHP also has a CSV dataSource as part of the datasources plug in.

    Using this, you can create a Model that, in stead of using a database, uses a CSV file as its source. This allows you to, for example, do this;

     $csvData = $this->MyCsvModel->find('all');
    

    Which will return all rows from the CSV file. Importing this into your database will be easy to implement by saving $csvData to another model

    Links:

    https://github.com/cakephp/datasources/tree/2.0 https://github.com/cakephp/datasources/blob/2.0/Model/Datasource/CsvSource.php

    这篇关于Strict(2048):CsvImportBehavior :: setup()的声明应该与ModelBehavior兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆