Zend Framework2 - 在Controller使用自定义插件plugins 和 视图助手Helper

JetBrains全家桶生产就绪指南:平台架构、配置避坑与调试实战 JetBrains IDE并非普通编辑器,而是基于IntelliJ Platform构建的四层可插拔开发环境——涵盖Platform Core内核、语言插件、第三方扩展及用户状态配置。其性能瓶颈常源于索引引擎、VFS虚拟文件系统或Xdebug协议兼容性等底层机制,而非表面安装问题。技术价值体现在语义级代码导航、跨框架智能感知与AI辅助编码闭环;典型应用场景包括Spring Boot微服务调试、Webman+Swoole协程断点追踪、.NET项目资源编译集成及团队标准化配置治理。本文聚焦真实工程现场验证的架构 阅读详情

1、定义插件

class MyPlugin extends AbstractPlugin {

    private $myPlugin;

    public function __construct(PluginManager $pm) {
        $this->myPlugin= $pm->getServiceLocator()->get('Translator');   //插件ID     
    }
  
//使用参数
    public function __invoke($message, $textDomain = 'default', $locale = null) {
        return $this->translator->translate($message, $textDomain, $locale);
    }

}

 --- 注册插件 ----

module.config.php

'controller_plugins' =>array(
    'invokables'=>array(
        'abcPlugin'  =>Admin\Plugins\MyPlugin,
    )
),


3、可以在插件中使用控制器方法

  //查询数据库

private functiongetInfoTable()
{
    $sm= $this->getController()->getServiceLocator();
    return$sm->get('Admin\Model\InfoTable');
}


4、在Controller调用

$this->abcPlugin('example message');


5、在控制器使用Helper

$helper = $this->getServiceLocator()->get('viewhelpermanager')->get('helperName');

$helper(params1,...);



=============在视图插件中添加方法==============

1.插件类

class InfoHelper extends AbstractHelper
{
    protected $infoTable;
    
    /**
     * 在.config中注册,注意对应的名称空间,视图中可直接调用$this->xxxx
     * $infoWhere可定义$cate_path_id: string; $categoryIds: int/array $categoryIds:指定分类ID
     * 适用于视图中调用
     * return bool
     */
    public function __invoke($infoWhere=[], $limit=null, $order=null)
    {
        $infoTable = $this->getInfoTable();        
        $where = array(
            'status'=>1,            
        );
        $where = array_merge($where, $infoWhere);
        //param: ($where=null, $qs=null, $paginated=false, $limit=null, $order=null)
        $resultSet = $infoTable->fetchAll($where, null, false, $limit, $order);        
        return $resultSet;
    }
    
    
    public function infoPhoto($infoWhere=[], $uploadWhere=[], $limit=null, $order=null)
    {        
        $infoTable = $this->getInfoTable();        
        $where = array(
            'status'=>1,
        );
        $infoWhere = array_merge($where, $infoWhere);
        
        //param: ($infoWhere=null, $uploadWhere=null, $limits=null, $order=null)        
        $resultSet = $infoTable->getInfoPhotoRowsFull($infoWhere, $uploadWhere, $limit, $order);        
        return $resultSet;
    }
    
    
    public function getInfoTable()
    {
        if (!$this->infoTable){
            $this->infoTable = $this->getView()->getHelperPluginManager()->getServiceLocator()->get('Admin\Model\InfoTable');
        }
        return $this->infoTable;
    }
    
}

2、注册插件(.config中)

3、在视图中调用helper方法

$infoPhoto = $this->plugin('infoHelper')->infoPhoto();








ROS知识:用户实现Controller组件 ROS基础概念中,控制是一个大块的知识团,本篇指导大家,如果自己实现控制,如何下手?在学习本节内容,需要以下背景知识:ROS基本概念:Topic、publish、subscribe 、ros-service、C++;URDF基本概念 阅读详情

相关推荐

Zend Framework教程之Zend_Controller_Plugin插件用法详解

主要介绍了Zend Framework教程之Zend_Controller_Plugin插件用法,结合实例形式详细分析了Zend_Controller_Plugin插件的原理,使用方法与相关注意事项,需要的朋友可以参考下

Zend Framework教程-Zend_Controller_Plugin插件的使用

原文:http://www.zendframework.com/manual/en/zend.controller.plugins.html 简介 控制器(Controller)结构包含一个可以在控制器周期内确定事件发生时调用用户代码的插件系统。 前端控制器(Front controller)使用插件 broker 作为用户插件注册,同时插件 broker 确保前端控制器中注册

梦想摆渡的专栏 3243

Navcat最新版的激活和安装教程(全网最靠谱,最快捷的方式)

现在最新版本navcat已经出到了16.3了,并且新版navcat也支持连接redis和图标等更多样化的功能,但是比较头疼的一件事就是,只能试用14天。那么接下来小编教大家如何用最简单的方式使用最新版navcat16.

weixin_50737119的博客 2万+

【Nav2中文网】四、首次机器人安装指南(六)设置导航插件

本教程来自:Nav2中文网 Nav2交流社区:https://fishros.org.cn/forum ROS2/Nav2千人交流群:(QQ)139707339 更多精彩教程请关注微信公众号:鱼香ROS 欢迎添加机器人小伊微信,解锁机器人学习特殊服务 在本指南的这一部分中,我们将讨论您的机器人如何利用不同的planner和控制器算法来完成导航任务。我们将根据您的机器人类型和环境讨论一些可用的算法插件。 [校准@首飞] 规划器和控制器服务器 [待校准@1571] Nav2中的导航算法是通过运行在ROS动.

生活不止眼前的苟且 1900

COT Buck和普通Buck的区别

传统的电流模控制的调制原理,由时钟脉冲信号 clk 的上升沿触发开始一个新的开关周期,d 由低变高,主开关闭合,流过它的电流和电感电流相等,并以固定斜率逐渐增大,直至 iL *Ri 与斜坡补偿信号 se 的和等于控制信号 vc;此时,比较器的输出电平由低变高,导通时间产生器被触发,其输出 d 由低变高,并产生一个固定的导通时间 Ton;然后 PWM 比较器的输出由低变高,导通时间产生器被触发,主开关闭合,电感电流逐渐增大,直到导通时间产生器计满固定的时间 Ton,d 变为低电平,主开关断开,周期结束。

模拟芯片设计 1128

Sen+MK趋势分析

Sen+MK趋势分析

地理研究与算法的博客 4万+

Zend Framework 2 入门-使用插件扩展你控制器

有时候控制器中的代码过多会对我们的操作造成不便。那么有什么好的办法呢?下面将为大家介绍一个控制器的插件。 首先,我们新建一个插件感受下他的作用 <?php /** * 插件示例 * * @author Star * @license http://mushroot.com * @version: 1.0 * */ namespace Application\Controller

wang_quan_li的专栏 955

写出GD32L233/235在读写flash的区别(用于OTA功能)

在单片机里面表示 大概是 address += sizeof(uint32_t) address += sizeof(uint64_t)1.说到OTA功能,实际上 往flash 指定区域写 数据, 拷贝数据,然后 跳转, 必要时 注意单片机的偏移量。在写本文时,L233支持单字写入,而L235只有双字写入. 一个写入地址+4 一个写入地址+8。这个是 自己写的擦除一页 数据,当然可以参考 提供的demo去实现,看自己需求。接下来是 读取 双字,也就是在L235上的读取。

teleger的博客 908

Zend Framework 2 Service Manager 配置方法

我们通常会把Service Manager配置在两个地方 1.module.config.php 2.Module.php 不同的service manager 类型有不同的配置方法 Application services Manager Application services Manager class Zend\ServiceManager\Servic

BenShuHuai的专栏 1128

lammps案例:聚乙烯和石墨烯界面pull out模拟

大家好,我是小马老师。 本文介绍lammps模拟计算界面结合力的一个案例。 本案例参考论文《The interfacial mechanical properties of functionalized graphene- polymer nanocomposites》,对论文作者表示感谢。 模型共分2层,上层为聚乙烯模型,下次为单层石墨烯,模拟过程共分3部分:建模、弛豫、拉伸。 (1)建模 使用MS建立聚乙烯和石墨烯模型,具体方法可参考之前的推文,使用build layer方法建立聚乙烯和石墨烯组合模型,

lammps_jiayou的博客 3496

宇树科技嵌入式面试题及参考答案(春晚机器人的公司)

内存对齐是指在内存中为数据对象分配存储空间时,按照一定的规则将数据存储在特定的地址上,以提高内存访问效率。不同的数据类型在内存中都有其特定的对齐要求,例如,int类型通常要求 4 字节对齐,double类型通常要求 8 字节对齐。这意味着数据的存储地址必须是其对齐字节数的整数倍。如果不进行内存对齐,处理器在访问数据时可能需要进行多次内存访问,从而降低了访问效率。指令可以用于控制结构体内存布局,它允许程序员指定结构体成员的对齐方式。其基本用法是在结构体定义之前使用来指定对齐字节数n,其中n。

大模型大数据攻城狮的专栏 3226

Zend Framework 中的插件之一:介绍

Zend Framework 大量的使用插件结构。插件可以使你轻易的扩展和定制框架,同时使你的代码和 Zend Framework 分离。典型的,Zend Framework 中的插件的工作流程如下:插件是类。类的具体定义基于组件会有所不同——你可能需要扩展一个抽象类或应用一个接口,但是事实是:插件自己本身是一个类。相关的插件将会共享一个通用的类前缀。举例来说,如果

Variations on the Kanon by Pachelbel 1371

STM32CubeMX之DAC产成正弦波

“在之前的文章中曾经介绍过用TIM产生PWM做DAC用,STM32定时器输出PWM做DAC。部分型号的STM32单片机内部有专用的DAC,本篇文章将介绍如何用内部DAC+DMA产生正弦波...

zhang062061的专栏 1513

zend framework2 - 通过配置类加载提高性能

Autoloader Classmap 使用classmap,就可以在初始化的时间返回一个‘类-文件’对应的array,从而加速加载类的速度。默认的类加载是使用StandardAutoloader,正则表达式来将类名字转换成文件名再加载,试想一下每次加载都要跑一下性能不高的正则匹配,速度能有多快呢 这是默认的自动加载配置src/module//Module.php 1

xmlife的专栏 819

PyTorch生成式人工智能(25)——基于Transformer实现机器翻译

不同于循环神经网络 (RNN) 按顺序处理数据,Transformer 以并行的方式处理输入数据(例如句子)。这种并行处理提高了效率,但并未使其能够识别输入的顺序。为了解决这个问题,Transformer 向输入的词嵌入中添加了位置编码。这些位置编码是分配给输入序列中每个位置的独特向量,其维度与输入词嵌入对齐。本节将以英语到法语的翻译为例,通过介绍如何训练 Transformer 模型将英语句子转换为法语,深入理解 Transformer 的架构及自注意力机制的运作方式。

盼小辉丶的博客 2746

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

Zendframework2-Zend_View-视图助手-区域助手(Partial Helper)

重用模板片段 在共享的视图脚本路径里放置可重用的 partials ,重用性比较好 简介     Partial 视图助手被用来在它自己的变量范围内解析特定的模板。     主要用法是(解析)可重用的模板片段     不需要操心变量名的冲突。另外,它们可从特定的模块

teari.的专栏 1157

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

springboot 模拟客户端请求controller的插件mocmvc(了解)

一.MocMvc作用 MockMvc实现了对Http请求的模拟,能够直接使用网络的形式,转换到Controller的调用,这样可以使得测试速度快、不依赖网络环境,而且提供了一套验证的工具,这样可以使得请求的验证统一而且很方便。 对模块进行集成测试时,希望能够通过输入URL对Controller进行测试,如果通过启动服务器,建立http client进行测试,这样会使得测试变得很麻烦,比如,启动速度慢,测试验证不方便,依赖网络环境等,所以为了可以对Controller进行测试,我们引入...

健康平安的活着的专栏 527

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Zend Framework中的插件(Learning Zend Framework翻译3)

目录介绍使用插件结论介绍Zend Framework大量使用插件架构。插件考虑到当保持你的代码与Zend Framework代码分离时易于扩展和框架的定制。典型地,Zend Framework中的插件像下面这样工作:·         插件是类。实际的类定义将基于组件而有所不同——你可能需要扩展一个抽象类(extend an abstract)或者实现一个接

丁豆的PHP 1299

zendframework2中变相实现自定义的controller的继承

在入口文件index.php中进行实例化 $fc = Zend_Controller_Front::getInstance();//取得Zend_Controller_Front类实例 $fc -> registerPlugin(new Verify($acl));

wang_quan_li的专栏 678

Zend Framework2(zf2) 在不同模块中调用全局配置方法

>>在Module.php 获取相关配置信息              ------也可在自定义的类中使用:只要实现 public function getServiceConfig()       public function getServiceConfig(){                 return array(             'factories'=>

xmlife的专栏 2214

Zend Framework2 - TableGateway操作多个数据表(Multiple Table)

>>方法一:      maybe something tricky like this :       public function fetchJoin()     {         $select = new \Zend\Db\Sql\Select ;         $select->from('province');         $select->columns(a

xmlife的专栏 1377

Zend framework2 - 联合查询分页

public function fetchAll($where=null, $qs=null, $paginated=false)     {                      //var_dump($this->tableGateway->getSql()->getTable());exit();  //out:lf_admin,省略getSql()将输出不加前缀名       

xmlife的专栏 1175

zend framework2-在controller-action设置layout布局视图变量

方法: 1.在控制器中写  <?php $children = $this->viewModel()->getCurrent()->getChildren(); $child = $children[0]; ?> 2.在layout.phtml中使用 escape($child->anyvar);?>

xmlife的专栏 1138

Zend Framework2 - 在Layout或视图里添加Partial 或 子视图方法

1、方法一,在layout 使用 partial                            echo $this->partial('modal/error.phtml',array('sysMsg'=>$this->sysMsg, 'modalShow'=>$this->modalShow));        ?> 2、方法二,在Controller 中添加a

xmlife的专栏 1010

Zend Framework2使用Faq随记

1. 全局变量:不要直接定义全局变量,而应在config/globa.php 或 local.php 配置,如 return array( 'service_manager' => array( 'factories' => array( //'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\Adapt

xmlife的专栏 879
上一篇: PayPal - (REST 框架 PHP) Express Checkout(EC)快捷支付使用说明
下一篇: Zend framework2-过滤器InputFilter相关使用方法
xmlife
博客等级 码龄19年 89粉丝 55原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值