IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Ecstore中app的sitemaps来源

    tiandi发表于 2015-09-17 07:21:22
    love 0

    ecstore有自己的app机制,类似wp的plugin,但是和wp的plugin比较起来,实在是差得有些远了。每一个app都有其自己的router路径,存在base_settings表里的sitemap下。这次我们需要添加一个wap的赠品页面,由于ec里自带的赠品页面没有wap页面,只有site,所以需要添加wap页面的控制器,这里没有用到默认的app安装方式进行安装。实际上这个app已经存在,只是没有wap端而已。操作过程中,新建控制器文件/gift/controller/wap/gift.php后,通过页面无法访问控制器文件,猜测可能是sitemaps的问题,于是追踪kernel代码,到达最后两句。

    self::$__router = app::get($app)->router();
    self::$__router->dispatch($path);
    

    继续去查看router()方法后,这里的router()调用的是/wap/lib/router.php,在该文件里构造函数声明了sitemaps.

    function __construct($app){ 
            $this->app = $app;
            $this->sitemap = app::get('wap')->getConf('sitemaps');
            ...
    }
    

    将这里的sitemap打印出来看,发现是数组形式的内容,具体是形成了各种router,但是很明显,没有gift_wap的router。

    Array
    (
        [index] => Array
            (
                [0] => wap
                [1] => default
                [2] => 首页
                [3] => 
                [use_ssl] => 
            )
    
        [widgetsproinstance] => Array
            (
                [0] => wap
                [1] => proinstance
                [2] => 挂件实例展示
                [3] => 
                [use_ssl] => 
            )
    
         => Array
            (
                [0] => b2c
                [1] => wap_gallery
                [2] => 全部商品
                [3] => 
                [use_ssl] => 
            )
        ...
    )
    

    于是找到/wap/lib/application/module.php文件,install方法里有下面生成sitemaps的方法:

    kernel::single('wap_module_base')->create_site_config();  

    最后看这个方法的原型,需要先读取modules表里的信息,而这个表的信息是app install的时候会添加进去的。

    class wap_module_base
    {      
        final public function create_site_config() 
        {
            $conf = $this->assemble_config();
            return $this->write_config($conf);
        }
        final public function assemble_config() 
        {
            $rows = app::get('wap')->model('modules')->select()->where('enable = ?', 'true')->instance()->fetch_all();
            if(is_array($rows)){
                $conf = array();
                foreach($rows AS $row){
                    $conf[$row['path']] = array($row['app'], $row['ctl'], $row['title'], trim($row['extension']), 
                                                'use_ssl' => $row['use_ssl'] === 'true' ? true : false);
                }
                return $conf;
            }
            return false;
        }
    
        final public function write_config($conf) 
        {
            if(is_array($conf)){
                return app::get('wap')->setConf('sitemaps', $conf);
            }else{
                return false;
            }
        }
    
    }

    至此,一切简单明了了,每个app install的时候会自动生成app的module,然后重建sitemap,如果你像tiandi一样没有用cmd机制的话,那么现在你也能手动创建sitemaps了

    文章评分2次,平均分5.0:★★★★★


沪ICP备19023445号-2号
友情链接