草庐IT

any_variable

全部标签

php - 在 CodeIgniter 中为 ( :any)

我试图让我的CodeIgniter应用程序像WordPress一样工作。我希望能够制作这些类型的URL:http://www.example.com/my-post-examplehttp://www.example.com/new-headline-herehttp://www.example.com/i-love-stackoverflow我的路线:$route['(:any)']="core/index/$1";这将调用我的核心Controller并将页面名称传递给索引函数。然后我在我的数据库中查找页面名称并将该页面显示给用户。到目前为止一切顺利。但是,有时我想调用另一个Cont

PHP 最佳实践 : repass variables from config file when calling functions or use global?

我有一个在多个站点上使用的程序。它使用require('config.php');设置任何站点相关变量,如mysql连接信息、路径等。假设我在一个函数中使用了这些依赖于站点的变量之一,例如$backup_path。这个变量最初是在config.php中声明的,并没有出现在主程序文件中。我需要在函数ma​​kebackup($table_name);中访问这个变量(也在一个单独的functions.php文件中)。是不是比较好说makebackup('my_table');然后在函数内部使用“global$backup_path”,还是调用函数更好makebackup('my_table

php - 函数内的 Laravel undefined variable

我从url中获取了我的$id,但我找不到在函数中使用它的方法。如何将$id传递给查询函数?我尝试了global$id但我仍然无法获得值,只是空页面。我的Controller。classBookControllerextendsController{publicfunctionbookIndex($id,$slug){//echo$idworkswithoutaproblem$findcover=Thing::with(array('cover'=>function($query){$query->where('imageable_type','App\Models\Thing')->w

php - 简写做类似 : if($variable == 1 || $variable == "whatever" || $variable == '492' ) . 的事情

我发现我自己在做这种类型的IF语句分配。例如:if($variable==1||$variable=="whatever"||$variable=='492'){...}除了分配的时间,我将$variable与4-5个东西进行比较,有时更多。有写这个的捷径吗?您可以看到重复$variable==会变得多余。我很希望它能工作,但它没有:if($variable==(1||"whatever"||492){...} 最佳答案 您可以使用这种简写方式,但请记住,使用or子句显式列出它们的效率较低:if(in_array($variable

php - 我有一个 require ("config.php") 和数组,但仍然出现 undefined variable 错误

我有一个看起来像这样的函数:require("config.php");functiondisplayGta(){(...lotsofcode...)$car=$car_park[3];}和一个看起来像这样的config.php:为什么我会收到Notice:Undefinedvariable:car_park? 最佳答案 尝试添加global$car_park;在你的函数中。当您包含$car_park的定义时,它会创建一个全局变量,并且要从函数内部访问它,您必须将其声明为全局变量,或通过$GLOBALS超全局变量访问它。参见manu

php - 为什么 $variable = 0759 给出 61?

这个问题在这里已经有了答案:Whatdoesaleadingzerodoforaphpint?(4个答案)关闭8年前。我不知道如何用谷歌搜索这个,所以我在这里问。为什么当我声明一个变量$something=0759时,它变成了61。我知道答案一定很简单所以请原谅我的愚蠢。

php - 如何剥离数据 :image part from a base64 string of any image type in PHP

我目前正在执行以下操作以在PHP中解码base64图像:$img=str_replace('data:image/jpeg;base64,','',$s['image']);$img=str_replace('data:image/png;base64,','',$s['image']);$img=str_replace('data:image/gif;base64,','',$s['image']);$img=str_replace('data:image/bmp;base64,','',$s['image']);$img=str_replace('','+',$img);$data

php - Symfony2 : Session Global variable in PHP template

Symfony文档说:Duringeachrequest,Symfony2willsetaglobaltemplatevariableappinbothTwigandPHPtemplateenginesbydefault.TheappvariableisaGlobalVariablesinstancewhichwillgiveyouaccesstosomeapplicationspecificvariablesautomatically:app.security-Thesecuritycontext.app.user-Thecurrentuserobject.app.request-T

PHP:获取 TEXTBOX 的值然后将其传递给 VARIABLE

我的问题是:我想获取textbox1的值,然后将其传输到另一个页面,其中textbox1的值将出现在textbox2中。下面是我的PHP代码:Name:我还添加了下面的代码,错误是“Notice:Undefinedindex:name”或 最佳答案 在testing2.php中使用以下代码获取名称:if(!empty($_POST['name'])){$name=$_POST['name']);}当您创建下一个页面时,使用$name的值来预填充表单字段:Name:">但是,在这样做之前,一定要使用正则表达式来验证$name只包含有效

闭包中的 PHP undefined variable

以下代码片段返回一堆输入字段,但我无法设置它们的值,因为$data未定义(它在闭包内)。$row=array_map(function($n){$name=sprintf('point[%0d]',$n+1);$value=$data['measurements'][$n];returnform_input($name,$value,"class='input-mini'");},range($i*6,$i*6+5));我知道全局变量并不酷。解决这个问题的最佳方法是什么? 最佳答案 Inheritingvariablesfromth