rrd108/cakephp-datalist 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rrd108/cakephp-datalist

Composer 安装命令:

composer require rrd108/cakephp-datalist

包简介

Datalist plugin for CakePHP 3

README 文档

README

Build Status codecov

Datalist plugin for CakePHP

Many of the HTML 5 new widgets are automatically supported by CakePHP. Unfortunatelly datalist is not supported by default.

With the datalist HTML 5 element you can create a widget similar to select elements, but with datalist you are not forced to select one of the options, but you can add any new value also.

If you are looking for plain datalist support by a CakePHP plugin you should check dereuromark/cakephp-tools

This plugin adds an extra feature on a plain datalist. If you create a new option, than CakePHP will save the value in the associted model as a new record.

Backward compatibility

From version 1.0.0 we have renamed the widget, so in the AppView.php and in your template files you should use datalistJs instead of datalist as described below. Sorry for breaking backward compatibility, but there were only a few installs of the previous versions and as dereuromark/cakephp-tools implemented plain datalist, this was the easiest way to do...

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install the plugin is via composer:

composer require rrd108/cakephp-datalist

Than you should load the plugin by issuing the following command in your terminal.

bin/cake plugin load Datalist

As the plugin extends the core HTML widgets you should load the form helper in your /src/View/AppView.php file like this:

public function initialize() 
{ 
    parent::initialize(); 
    $this->loadHelper('Form', [
        'templates' => 'Datalist.form-templates',
        'widgets' => [
            'datalistJs' => ['Datalist\View\Widget\DatalistJsWidget']
        ]
    ]);
} 

Usage

In any model where you want to use datalist you should add datalist behavior. For example in your /src/Model/Table/SkillsTable.php you should have the following code, where Languages should be associated to SkillsTable and name is the field on what we want to use datalist.

public function initialize(array $config)
{
    parent::initialize($config);

    $this->addBehavior(
        'Datalist.Datalist', 
        ['Languages' => 'name']
    );
    
    $this->belongsTo('Languages', [
        'foreignKey' => 'language_id',
        'joinType' => 'INNER'
        ]);
}

If you want more datalists you can add more models to the behavior.

$this->addBehavior(
    'Datalist.Datalist', 
    ['Languages' => 'name', 'Countries' => 'country']
);
}

Than in your controller you do a simple find operation and set the result to the view.

//src/Controller/SkillsController.php
public function add()
{
    // your controller code
    $languages = $this->Skills->Languages->find('list', ['limit' => 200]);
    $this->set(compact('languages'));
}

By this the $languages variable is available at /src/Template/Skills/add.ctpfile.

<?= $this->Form->create($skill) ?>
<?php
    echo $this->Form->control(
        'language_id',
        ['type' => 'datalistJs', 'options' => $languages]
    );
?>

The end result should work like a charm and if you do not select one of the options but type in a new one, CakePHP will save it as a new entry in the associated model. Alt Text

rrd108/cakephp-datalist 适用场景与选型建议

rrd108/cakephp-datalist 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 594 次下载、GitHub Stars 达 6, 最近一次更新时间为 2018 年 07 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 rrd108/cakephp-datalist 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rrd108/cakephp-datalist 我们能提供哪些服务?
定制开发 / 二次开发

基于 rrd108/cakephp-datalist 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 594
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-06