php – 获取YII中的所有“页面”?

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 获取YII中的所有“页面”?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试创建自己的XMl站点地图.一切都已完成,除了我认为最容易的部分.你如何获得网站上所有页面的列表?我在/ sITe文件夹和其他一些文件夹中有很多视图.有没有办法明确请求他们的URL或可能通过控制器?

不想使用扩展名

您可以使用反射来遍历所有控制器的所有方法
Yii::import('application.controllers.*');
$urls = array();

$directory = Yii::getPathOfAlias('application.controllers');
$iterator = new directoryiterator($directory);
foreach ($iterator as $fileinfo)
{
    if ($fileinfo->isFile() and $fileinfo->getExtension() == 'PHP')
    {
        $classname = substr($fileinfo->getFilename(),-4); //strip extension
        $class = new ReflectionClass($className);

        foreach ($class->getmethods(ReflectionMethod::IS_PUBLIC) as $method)
        {
            $methodName = $method->getName();
            //only take methods that begin with 'action',but skip actions() method
            if (strpos($methodName,'action') === 0 and $methodName != 'actions')
            {   
                $controller = lcFirst(substr($className,strrpos($className,'Controller')));
                $action = lCFirst(substr($methodName,6));
                $urls[] = Yii::app()->createAbsoluteUrl("$controller/$action");
            }
        }
    }
}

脚本宝典总结

以上是脚本宝典为你收集整理的php – 获取YII中的所有“页面”?全部内容,希望文章能够帮你解决php – 获取YII中的所有“页面”?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。