Helpers\Hooks
Helpers\Hooks
Add modules with hooks
The hooks helper allows modules to be created within the module folder. Hooks allow code to be injected into various parts of the framework as well as creating new routes for modules to use.
The following hooks have been created and placed in the following files to allow you to make use of them.
- meta - placed in app/templates/default/header.php
- css - placed in app/templates/default/header.php
- afterBody - placed in app/templates/default/header.php
- footer - placed in app/templates/default/footer.php
- js - placed in app/templates/default/footer.php
- routes - placed in index.php
The hooks: meta, css, afterBody, footer and js are placeholders to execute code from modules. The routes hook enables custom routes to be defined from a module.
Place a hook where it can be executed
To use a hook first make reference to it:
use Helpers\Hooks;
$hooks = Hooks::get();
Once initiated calls can be called by running $hooks->run('hookName'), this will then run all code attached to the hook for instance to run all code attached to the css hook (used for injecting css files):
<?php
use Helpers\Hooks;
//initialise hooks
$hooks = Hooks::get();
?>
<!DOCTYPE html>
<html lang="<?php echo LANGUAGE_CODE; ?>">
<head>
<?php
//hook for plugging in css
$hooks->run('css');
?>
Add code to a hook
To add code to a hook call Hooks::addHook() this method expects 2 parameters:
- The hook to inject into.
- The path to the class, start with the namespace followed by the class then @method to be called.
use Helpers\Hooks;
Hooks::addHook('css', 'App\Models\Demo\Controllers\Demo@css');
Once run any code inside the class method will be executed on the page where the hook is being called.
Calling custom routes
Define the routes hook and pass in a path to the class and method to be used.
use Helpers\Hooks;
Hooks::addHook("routes", 'App\Modules\Demo\Controllers\Demo@routes');
Next in the class create an alias for Router. Next in the method the routes will be used in call Router followed by the route desired, instead of calling a controller use a closure to run the code against the route.
<?php
namespace App\Modules\Demo\Controllers;
use Core\Router;
class Demo
{
public function routes()
{
Router::any('democall', function () {
echo 'called from demo module';
});
}
}
In the above example a route is defined, it's called when the example.com/democall is ran in the address bar. This closure echo's a message. The code inside the closure can call views and models the same as controller methods do.
Creating a Module
To create a module create a folder inside the Modules folder, the convention is to use StudyCase for example a module called demo should name named Demo. Inside the module folder create a Controllers, Models and views folder, those folders should hold the classes for controllers and models. The views is for the output of the module pages.
index.php should also be created in the route of the module folder, this file defined all hooks the module will be attached to.
Helpers\Hooks的更多相关文章
- Config
Config Config App Auth Cache Database Languages Mail Modules Routing Session Config Settings for the ...
- CI框架入门笔记
当前(2019-03-22)CodeIgniter 框架的最新版本是 3.1.5,于2017年6月发布,距今快两年了也没有更新,这与 Laravel 的更新速度相比差距太大了.因为确实,它是一个很古老 ...
- 对CI框架中几个文件libraries
对CI框架中几个文件libraries,helpers,hooks夹说明 来源:未知 时间:2014-10-20 11:37 阅读数:117 作者:xbdadmin [导读] 1.lib ...
- ASP.NET Core 中文文档 第四章 MVC(3.6.1 )Tag Helpers 介绍
原文:Introduction to Tag Helpers 作者:Rick Anderson 翻译:刘浩杨 校对:高嵩(Jack) 什么是 Tag Helpers? Tag Helpers 提供了什 ...
- ASP.NET Core 中文文档 第四章 MVC(3.6.2 )自定义标签辅助类(Tag Helpers)
原文:Authoring Tag Helpers 作者:Rick Anderson 翻译:张海龙(jiechen) 校对:许登洋(Seay) 示例代码查看与下载 从 Tag Helper 讲起 本篇教 ...
- [asp.net core]定义Tag Helpers
原文地址 https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/authoring Getting started wi ...
- [asp.net core] Tag Helpers 简介(转)
原文地址 https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/intro What are Tag Helpers? ...
- 使用 Git Hooks 实现自动项目部署
最近在某服务器上面搭建 git 开发和部署环境,git 开发环境很简单,按照 ProGit 一书的相关知识就可以轻松搞定,实现了类似 Github 的使用 SSH + 私有 Clone 的方式. 关于 ...
- CI框架之HOOKS使用流程及原理
Ci框架中Hooks可以理解:在框架的执行流程过程中,允许开发者在固定的某些时间点上(如:调用控制器前,调用控制器后等时间点上),调用其他函数来扩充CI框架执行流程的一种方法.技术上来就是通过 ...
随机推荐
- win7旗舰版通知windows不是正版副本解决方法
原文转载http://www.cnblogs.com/simple_666/archive/2013/04/13/win7%E6%97%97%E8%88%B0%E7%89%88%E9%80%9A%E7 ...
- kendoui-在线文本编辑器
文本编辑器用过很多,fckeditor是我之前用的最多的,但是问题也有很多,诸如安全问题,浏览器兼容问题..所以最近也一直在找替代产品,正好在研究kendo,所以就尝试了下kendo提供的edit控件 ...
- Tkinter教程之Checkbutton篇
本文转载自:http://blog.csdn.net/jcodeer/article/details/1811306 #Tkinter教程之Checkbutton篇#Checkbutton又称为多选按 ...
- centos6.4 挂载ntfs分区
默认情况下,CentOS 6.4不支持Widows NTFS硬盘分区读写,要想把NTFS格式的磁盘挂载到CentOS 6.3下面需要安装第三方的插件ntfs-3g,这里我们采用编译安装插件. 1.安装 ...
- 设置mysql 在mac中的环境变量
在mac os的用户目录下有一个隐藏文件.bash_profile,编辑它就可以完成环境变量的创建. 比如要将mysql的运行目录加到环境变量中,可以在.bash_profile中新增如下一行: ex ...
- windows防火墙无法启动,服务不存在
系统的防火墙无法启动,系统服务里面也没有防火墙的服务,用下面第一种方法,导 入注册表,重启服务器,在服务里面有防火墙的服务了,然后启动就好了,需要重新配置防火墙 在控制面板中启动防火墙的时候提示无法识 ...
- HDU 5919 -- Sequence II (主席树)
题意: 给一串数字,每个数字的位置是这个数第一次出现的位置. 每个询问对于序列的一个子区间,设一共有k个不同的数,求第ceil(k/2)个数的位置. 因为强制在线,所以离线乱搞pass掉. 主席树可解 ...
- Java设计模式系列之状态模式
状态模式(State)的定义 定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新.允许一个对象在其内部状态改变时改变它的行为.对象看起来似乎修改了它 ...
- iOS事件机制(二)
从上一篇的内容我们知道,在iOS中一个事件用一个UIEvent对象表示,UITouch用来表示一次对屏幕的操作动作,由多个UITouch对象构成了一个UIEvent对象.另外,UIResponder是 ...
- 问题-XE8报Object factory for class{xx-xx-xx-xx-xx} is missing. To register it, you can drop component[TFDGUIxWaitCursor] into your project.
问题现象:XE8开发数据访问程序时放入了FDPhysMSSQLDriverLink1.FDConnection1.FDConnection1.FDQuery1.DBGrid1,设计期没法,运行期报&q ...