草庐IT

Return-Path

全部标签

php - Symfony2 : Get Route Path

在Controller中使用命令$this->generateUrl($route);我可以获得路由的URL。但是,我只想检索它的最后一部分(如routing.yml中所指定)。例如,我只想返回/$path而不是/web/app_dev.php/$path我怎样才能做到这一点? 最佳答案 你可以试试这个:$route=$this->get('router')->getRouteCollection()->get('routeName');if($route)echo$route->getPath();您还可以查看Symfony\Bu

php - 即使将 return as float 设置为 true,PHP 函数 microtime 能否返回一个整数?

我网站的一位用户前几天报告了一个错误,所以我查看了日志并进行了追踪。错误是:Undefinedoffset:1导致此错误的相关代码是:$parts=explode('.',microtime(true));$nonce=base_convert($parts[1],10,36);所以$parts[1]基本上是未定义的。这会不会是因为当调用microtime时恰好它是一个精确的秒,所以它返回一个没有任何小数位的int? 最佳答案 快速测试可以证实您的假设:打印float(1508171125)在我的系统上。所以是的,microtime

PHP 错误的文件夹? include_path ='.:/usr/share/php:/usr/share/pear'

我需要在我的网络服务器上安装此功能。此错误消息正在寻找/usr/share/phpCOLON/usr/share/pear我的php安装位于/usr/share/php5中,我没有/usr/share/pear文件夹冒号在语法中是什么意思,“和”?如果路径错误,我不确定如何在此脚本中更改它,我不想将share/php5更改为php,或者是推荐? 最佳答案 Whatdoescolonmeaninthatsyntax,"and"?是的,类似的东西。它是路径分隔符,您可以将其与逗号“,”进行比较。ifthepathiswrongI'mno

php - 使用 include-path 定义全局变量

在我的php项目中,我想确保代码保持可移植性和服务器独立性。所以我添加了一个“config.php”,我将其包含在每个php文件中,其中配置了多个config-var。我把它包含在include_once('config.php');我的问题是,此config.php中的第一个变量是:global$path;$path=$_SERVER['DOCUMENT_ROOT'];使所有包含/要求绝对且“可移植”。这当然适用于include_once('config.php');之后的所有include。-但我怎样才能使这个特定的包含绝对?我现在的“解决方案”是这段代码://setglobalp

php - PHP 中是否有内置的方法来解析这样的字符串 : '/path/to/../../up/something.txt'

假设我有一个类似路径的字符串$path='/path/to/../../up/something.txt';有没有内置于PHP中的方法来解析它并得出一个没有目录ups(../)的URL?例如$path=parsePath('/path/to/../../up/something.txt');///up/something.txt 最佳答案 realpath($path);Docs 关于php-PHP中是否有内置的方法来解析这样的字符串:'/path/to/../../up/somethi

arrays - "Can' t use function return value in write context”PHP错误

Fatalerror:Can'tusefunctionreturnvalueinwritecontextinline3,在什么情况下会触发此类错误?我的程序://QUERYVARIABLE$query="select*formuserwhereuser_name='$user_name'anduser_password='sha($user_password)'";//ESTABLISHINGCONNECTION$result=mysqli_query($dbc,$query)ordie('ErrorQueryingDatabase');while($row=mysqli_num_ro

php - htaccess : redirect an image path to a PHP script

我想要以下图片网址http://www.example.com/image-provider/article/1275449_inline3_scale_700xauto.jpg将被重定向到将实际生成内容的以下PHP脚本http://www.example.com/image-provider?url=article/1275449_inline3_scale_700xauto.jpg我在我的.htaccess中尝试了以下语法RewriteCond%{REQUEST_FILENAME}!-fRewriteRule^/image-provider/(.*)$image-provider?

php - 类 path.config 不存在 - Lumen 5.2

我在添加GoogleMaps包时遇到了一些问题作者:alexpechkarev链接:https://alexpechkarev.github.io/google-maps/流明框架版本5.2我将ServiceProvider和Facade添加到我的app.php中:$app->register(GoogleMaps\ServiceProvider\GoogleMapsServiceProvider::class);class_alias(GoogleMaps\Facade\GoogleMapsFacade::class,'GoogleMaps');但是当我转到我的命令行并磁带:phpa

php - "return $container->{$resource};"是什么意思

brakets是什么意思以及在哪里阅读更多内容return$container->{$resource}; 最佳答案 中括号是为了使用可变变量。它可以更容易地区分://getsthevalueofthe"resource"memberfromthecontainerobject$container->resource;和//getsthevalueofthe"foo"memberfromthecontainerobject$resource='foo';$container->$resource;您可以在此处阅读更多信息:http:

php - 面向对象设计 : Return Values or Set Property?

在这种情况下,什么将被视为“最佳实践”。我有一个正在收集远程资源的类,它看起来有点像这样:classGather{publicfunctiongetAll($locations){$results=array('All','My','Results');return$results;}}我的问题是,返回结果或将它们分配为属性是否被视为最佳做法?即。//This$results=$gatherer->getAll();//vsThis$gatherer->getAll();//now$gatherer->resultscanbeused这很可能是我想多了,但我没有接受过正规培训,我想知道