zoukankan      html  css  js  c++  java
  • onethink 插件模板定位

    <?php
    // +----------------------------------------------------------------------
    // | OneThink [ WE CAN DO IT JUST THINK IT ]
    // +----------------------------------------------------------------------
    // | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
    // +----------------------------------------------------------------------
    // | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
    // +----------------------------------------------------------------------
    
    namespace HomeController;
    use ThinkController;
    
    /**
     * 扩展控制器
     * 用于调度各个扩展的URL访问需求
     */
    class AddonsController extends Controller{
    
    	protected $addons = null;
    
    	public function execute($_addons = null, $_controller = null, $_action = null){
    		if(C('URL_CASE_INSENSITIVE')){
    			$_addons = ucfirst(parse_name($_addons, 1));
    			$_controller = parse_name($_controller,1);
    		}
    
    		if(!empty($_addons) && !empty($_controller) && !empty($_action)){
    			$Addons = A("Addons://{$_addons}/{$_controller}")->$_action();
    		} else {
    			$this->error('没有指定插件名称,控制器或操作!');
    		}
    	}
    
    	protected function display($templateFile = '', $charset = '', $contentType = '', $content = '', $prefix = '') {
    		$templateFile = $this->getAddonTemplate ( $templateFile );
    		$this->view->display ( $templateFile, $charset, $contentType, $content, $prefix );
    	}
    	function getAddonTemplate($templateFile = '') {
    		if (file_exists ( $templateFile )) {
    			return $templateFile;
    		}
    		//dump ( $templateFile );
    		$oldFile = $templateFile;
    		if (empty ( $templateFile )) {
    			$templateFile = T ( 'Addons://' . _ADDONS . '@' . _CONTROLLER . '/' . _ACTION );
    		} elseif (stripos ( $templateFile, '/Addons/' ) === false && stripos ( $templateFile, THINK_PATH ) === false) {
    			if (stripos ( $templateFile, '/' ) === false) { // 如index
    				$templateFile = T ( 'Addons://' . _ADDONS . '@' . _CONTROLLER . '/' . $templateFile );
    			} elseif (stripos ( $templateFile, '@' ) === false) { // // 如 UserCenter/index
    				$templateFile = T ( 'Addons://' . _ADDONS . '@' . $templateFile );
    			}
    		}
    		
    		if (stripos ( $templateFile, '/Addons/' ) !== false && ! file_exists ( $templateFile )) {
    			$templateFile = ! empty ( $oldFile ) && stripos ( $oldFile, '/' ) === false ? $oldFile : _ACTION;
    		}
    		// dump ( $templateFile );//exit;
    		return $templateFile;
    	}
    
    }
    

    上面是定位源码,重写了display方法

    下面是使用方法

    <?php
    
    namespace AddonsHelloController;
    use HomeControllerAddonsController;
    
    class HelloController extends AddonsController{
        public function replyText(){
            $this->display('replyText');
        }
    }
    

    通过链接访问插件

    <a class="item" href="{:addons_url('Hello://Hello/replyText')}">自定义菜单</a>
    

      

      

      

  • 相关阅读:
    实验一:初步认识程序在内存中运行
    读了 东方学帝 的 《薛定谔方程和狄拉克方程等在共量子论中处于什么地位?》
    别跟我说 正电子 是 狄拉克方程 推导 出来 的
    ∫ 1 / ( b / x
    我很好奇 俄罗斯 小哥 数学家 为 华为 解决 的 数学问题 是 什么
    对 潮汐 现象 的 计算机 程序 模拟
    二阶微分 没有意义, 二阶导数 才有意义
    关于 郭峰君 的 d ( x² + y² + z² ) = d ( c² t² )
    圆面积 公式 推导
    理论模型 和 计算能力
  • 原文地址:https://www.cnblogs.com/bushe/p/4618885.html
Copyright © 2011-2022 走看看