tutida/pack 问题修复 & 功能扩展

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

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

tutida/pack

最新稳定版本:2.0.2

Composer 安装命令:

composer require tutida/pack

包简介

CakePHP4 variables in JS

README 文档

README

You can easy to pass CakePHP4 variables to JS in View.

Requirements

  • PHP >= 7.0
  • CakePHP >= 4.0

Installation

In Application.php

<?php $this->addPlugin('Pack');

In controller.

<?php class AppController extends Controller { public function initialize() { $this->loadComponent('Pack.Pack'); } ... }

In layout php or template php.

 <?= $this->Pack->render();?>

Usage

Just set variables in your controller.

<?php $entity = $this->Hoge->get($id); $array = [...]; $this->Pack->set('entity', $entity); $this->Pack->set('array', $array); ## OR ## $this->Pack->set(compact('entity', 'array')); 

Just get the variables in your JS in view.

 Pack.entity; Pack.array;

Methods

  1. set($varName, $variable) … Set variable in Pack.
  2. remove($varNamee) … Remove variable in Pack.
  3. show() … Show all variable in Pack.
  4. rename($namespace) … Change Pack's namespace in JS.

example

In controller

 $this->Pack->rename('Hoge'); $this->Pack->set('array', $array);

In js

 Hoge.array;

统计信息

  • 总下载量: 83.72k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 0
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固