小编ndm*_*ndm的帖子

CakePHP 3-创建hiddenField

根据文档

http://book.cakephp.org/3.0/en/views/helpers/form.html#options-for-select-checkbox-and-radio-inputs

我使用“ HiddenField”创建值为0的隐藏输入。

 echo $this->Form->Label("Stats ");            
                echo $this->Form->checkbox('stats', [
                                'value' => '1',
                                'hiddenField' => '0',
                            ]);
Run Code Online (Sandbox Code Playgroud)

我的HTML(没有隐藏字段)应为:

<input type="checkbox" name="stats" value="1" required="required">
Run Code Online (Sandbox Code Playgroud)

我昨天做了,但是今天不起作用,我还没有更新蛋糕的版本。。没什么,疯狂的:\

php cakephp cakephp-3.0

5
推荐指数
1
解决办法
1185
查看次数

如何在表默认字段之外选择特定字段?

我希望使用JOIN从表中选择数据,并在CakePHP中选择一个视图,如下所示:

$this->Annonces->find('all')
        ->where($arrFiltres)
        ->order($arrOrder)
        ->join([
            'table' => 'annonces_suivis',
            'alias' => 'AnnoncesSuivis',
            'conditions' => [...],      
        ]);
Run Code Online (Sandbox Code Playgroud)

并希望能够从第一个表和连接表的索引中选择所有字段,如下所示:

->select(['Annonces.*', 'AnnoncesSuivis.id']);
Run Code Online (Sandbox Code Playgroud)

但这会产生错误的SQL查询.

cakephp query-builder cakephp-3.0

5
推荐指数
1
解决办法
1万
查看次数

如何在CakePHP 3.0中获取$ this-> webroot

我在我的services.ctp文件中有这段代码,之前在CakePHP 2.3.10中工作正常.

href="<?php echo $this->webroot . 'intro/services/1'; ?>
Run Code Online (Sandbox Code Playgroud)

我刚刚将此文件复制到CakePHP 3.0.0中,它不再工作并抛出以下错误消息

错误:找不到C:\ apache2\htdocs\myprojxxxx\webroot\Helper.

$this->webrootCakePHP 3.0中有什么不同之处?

请帮忙!

cakephp cakephp-3.0

5
推荐指数
2
解决办法
2万
查看次数

如何在模型中使用:$this-&gt;Auth-&gt;user('id')?蛋糕php 3.0

我一直在研究瘦控制器胖模型的方式。之前,我在我的控制器中使用了它:

$this
    ->find('all')
    ->contain(['Declarator'])
    ->where(['user_id' => $this->Auth->user('id')])
    ->order(['Declarations.created' => 'DESC']);
Run Code Online (Sandbox Code Playgroud)

但是,$this->Auth->user('id'), 在模型中不起作用。

还有什么其他方法可以从模型中的经过身份验证的用户那里获取 id?

authentication cakephp model cakephp-3.0

5
推荐指数
1
解决办法
5475
查看次数

设置CakePHP 3插件测试

我曾经bin/cake bake plugin PluginName创建过一个插件.部分原因是它创建phpunit.xml.dist,但烘焙不会创建所需的文件夹结构或tests/bootstrap.php文件.

问题

我运行时收到"未执行测试"消息phpunit:

$ phpunit
PHPUnit 5.1.3 by Sebastian Bergmann and contributors.

Time: 239 ms, Memory: 4.50Mb

No tests executed!
Run Code Online (Sandbox Code Playgroud)

背景资料

我在我的插件文件夹下创建了我的测试tests/TestCase.我不认为它们是问题,但我会在最后发布它们.

我正在使用默认phpunit.xml.dist文件,我正在使用它tests/bootstrap.php:

$findRoot = function ($root) {
    do {
        $lastRoot = $root;
        $root = dirname($root);
        if (is_dir($root . '/vendor/cakephp/cakephp')) {
            return $root;
        }
    } while ($root !== $lastRoot);
    throw new Exception("Cannot find the root of the application, unable to run tests");
}; …
Run Code Online (Sandbox Code Playgroud)

testing configuration phpunit cakephp cakephp-3.0

5
推荐指数
1
解决办法
1442
查看次数

PHP:无法加载动态库 intl.so (OSX)

我正在尝试运行 CakePHP 应用程序。我已经在这个应用程序中工作了一段时间,最近我不得不安装一个新的依赖项(使用作曲家)。安装后,出现此错误,我无法再运行该应用程序:

PHP 警告:PHP 启动:无法加载动态库 '/usr/lib/php/extensions/no-debug-non-zts-20121212/intl.so' - dlopen(/usr/lib/php/extensions/no-debug -non-zts-20121212/intl.so, 9): 库未加载:/usr/local/opt/icu4c/lib/libicui18n.56.dylib 引用自:/usr/lib/php/extensions/no-debug-non-zts-20121212/intl.so 原因:在未知中找不到图像在第 0 行

当我打开该文件夹时,我可以看到该库的不同版本:

libicui18n.57.dylib
Run Code Online (Sandbox Code Playgroud)

但是系统正在寻找

libicui18n.56.dylib
Run Code Online (Sandbox Code Playgroud)

如何安装该库的 56 版本或升级 intl 使其使用版本 57?

这是我需要做的吗?

谢谢!!

php apache macos cakephp icu

5
推荐指数
1
解决办法
4898
查看次数

在 CakePHP 3 中检索相关数据 (hasMany)

Events hasMany TicketTypes
TicketTypes belogsTo Events
Run Code Online (Sandbox Code Playgroud)

我正在尝试检索具有相关票证类型的所有事件:

$query= $this->Events
    ->find()
    ->select(['id', 'name'])
    ->autoFields(false)
    ->contain(['TicketTypes' => function($q) { 
        return $q->select(['TicketTypes.id', 'TicketTypes.name']); }])
;
Run Code Online (Sandbox Code Playgroud)

生成的 SQL 查询:

SELECT Events.id AS `Events__id`, Events.name AS `Events__name` FROM events Events
Run Code Online (Sandbox Code Playgroud)

但我的预期是:

SELECT Events.id AS `Events__id`, Events.name AS `Events__name`, TicketTypes.id AS `TicketTypes__id`, TicketTypes.name AS `TicketTypes__name` FROM events Events LEFT JOIN ticket_types TicketTypes ON Events.id = (TicketTypes.event_id)
Run Code Online (Sandbox Code Playgroud)

这是我的模型的配置方式:

class EventsTable extends Table
{
    public function initialize(array $config)
    {
        $this->displayField('name');

        $this->addAssociations([
            'hasMany'=> ['TicketTypes']
        ]);
    }
}

class TicketTypesTable …
Run Code Online (Sandbox Code Playgroud)

cakephp associations query-builder cakephp-3.0

5
推荐指数
1
解决办法
2013
查看次数

如何在PHP7上使用CakePHP 2解决错误处理程序中的“未捕获的TypeError”?

致命错误

错误:未捕获的TypeError:传递给ErrorHandler :: handleException()的参数1必须是Exception的实例,在/opt/lampp/htdocs/quiz/lib/Cake/Error/ErrorHandler.php:108中给出的Error实例:堆栈跟踪: #0 [内部功能]:ErrorHandler :: handleException(Object(Error))#1 {main}抛出

文件:/opt/lampp/htdocs/quiz/lib/Cake/Error/ErrorHandler.php
行:108

我在php7上使用cakephp 2.6.1。我遇到了错误。请帮帮我

php cakephp cakephp-2.x

5
推荐指数
1
解决办法
2734
查看次数

Cakephp3.1:在同一关联模型上同时使用matching()和notMatching()

我想实现食谱及其相关成分的搜索功能。用户应该指定他想要从搜索中排除的成分,同时指定他正在寻找的食谱中包含的成分。

这是我的两个发现者:

public function findByContainingIngredients(Query $query, array $params)
{
    $ingredients = preg_replace('/\s+/', '', $params['containing_ingredients']);

    if($ingredients) {
        $ingredients = explode(',', $ingredients);
        $query->distinct(['Recipes.id']);
        $query->matching('Ingredients', function ($query) use($ingredients) {
            return $query->where(function ($exp, $query) use($ingredients) {
                return $exp->in('Ingredients.title', $ingredients);
            });
        });
    }
    return $query;
}


public function findByExcludingIngredients(Query $query, array $params)
{
    $ingredients = preg_replace('/\s+/', '', $params['excluding_ingredients']);

    if($ingredients) {
        $ingredients = explode(',', $ingredients);
        $query->distinct(['Recipes.id']);
        $query->notMatching('Ingredients', function ($query) use ($ingredients) {
            return $query->where(function ($exp, $query) use ($ingredients) {
                return $exp->in('Ingredients.title', $ingredients);
            });
        });

    }
    return …
Run Code Online (Sandbox Code Playgroud)

cakephp associations matching query-builder cakephp-3.1

5
推荐指数
1
解决办法
1334
查看次数

cakephp 3.x 保存嵌套(深层)关联

我有来自 3rd 方服务调用的产品数据,然后我从中创建一个对象并将其保存到我的 MySQL 数据库中。我的模型如下:

'products' hasMany>> 'product_skus' hasMany>> 'product_sku_attributes'

表关系

在我的 ProductsTable.php initialize() 方法中,我有:

$this->hasMany('ProductSkus', [
    'foreignKey' => 'product_no',
    'dependent' => true,
]);
Run Code Online (Sandbox Code Playgroud)

在我的 ProductSkusTable.php initialize() 方法中,我有:

$this->hasMany('ProductSkuAttributes', [
    'foreignKey' => 'product_sku_id',
    'bindingKey' => 'id',
    'propertyName' => 'product_sku_attributes',
    'dependent' => true,
]);
Run Code Online (Sandbox Code Playgroud)

我的控制器:

$products = TableRegistry::get('Products');
$entity = $products->newEntity($product_data[0]);
$products->save($entity, [
    'associated' => [
        'ProductSkus',
        'ProductSkus.ProductSkuAttributes',
    ]
]);
Run Code Online (Sandbox Code Playgroud)

这是我的实体调试中的相关片段:

'product_skus' => [
    (int) 0 => object(App\Model\Entity\ProductSkus) {

        'sku' => 'BDS1401H',
        'sku_price' => (float) 366.76,
        'sku_weight' => (float) 38.1,
        'sku_img_main' …
Run Code Online (Sandbox Code Playgroud)

orm cakephp associations cakephp-3.x

5
推荐指数
1
解决办法
1881
查看次数