我有一块代码,我需要在我的应用程序的很多地方使用.
例:
$count_device = VSE::count_device($cpe_mac);
$c_devices = $count_device['Count_of_devices'];
$c_active = $count_device['Count_of_active'];
$c_inactive = $count_device['Count_of_inactive'];
$c_offline = $count_device['Count_of_offline'];
Run Code Online (Sandbox Code Playgroud)
现在,他们是10我的控制者.如果我需要修理任何东西,我需要修复一些10地方.
我正在寻求一种更好的方法来控制它.
我想过写一个函数
public static function get_device_info($cpe_mac){
$count_device = VSE::count_device($cpe_mac);
$c_devices = $count_device['Count_of_devices'];
$c_active = $count_device['Count_of_active'];
$c_inactive = $count_device['Count_of_inactive'];
$c_offline = $count_device['Count_of_offline'];
}
Run Code Online (Sandbox Code Playgroud)
当我调用该函数时: $devices = get_device_info($cpe_mac);
我只能访问1个变量$devices.
我无法访问5该函数中的所有变量.
我找到了get_defined_vars,但这不是我想要的.
如何实现这一目标?
如何移动代码块并将其包含回来?
我应该开始研究PHP Require/Include吗?
我现在正在接受任何建议.
任何提示/建议/帮助将非常感谢!
我的终端上有一个 cURL
注意:状态= b4cf8fe7-aa68-4b25-8f9a-03a67fb420c7
curl -c session_cookies.txt "https://login.uat.site.be/openid/oauth/authorize?client_id=site&state=b4cf8fe7-aa68-4b25-8f9a-03a67fb420c7&nonce5ba13e5f-256d-425d-808b-1e05d2aa3d72&response_type=code&claims=%7B%22id_token%22%3A%7B%22http%3A%2F%2Fsite.be%2Fclaims%2Froles%22%3Anull%7D%7D" 2>/dev/null| curl -v -b session_cookies.txt -L -H "Content-Type: application/x-www-form-urlencoded" -v -d 'j_username=manager-sitelogin@gmail.com&j_password=site1' "https://login.uat.site.be/openid/login.do" 2>&1 >/dev/null | grep Location | grep code=
Run Code Online (Sandbox Code Playgroud)
我收到了这个回复
< Location: https://testserver.sitenets.com/user/secure/dashboard?code=zvk495dsnq1ycLKZgN8oqfFxQogg2oql&state=b4cf8fe7-aa68-4b25-8f9a-03a67fb420c7
Run Code Online (Sandbox Code Playgroud)
注意:状态= b4cf8fe7-aa68-4b25-8f9a-03a67fb420c7
注意:状态= b4cf8fe7-aa68-4b25-8f9a-03a67fb420c7
$cmd = 'curl -c session_cookies.txt "https://login.uat.site.be/openid/oauth/authorize?client_id=site&state=b4cf8fe7-aa68-4b25-8f9a-03a67fb420c7&nonce5ba13e5f-256d-425d-808b-1e05d2aa3d72&response_type=code&claims=%7B%22id_token%22%3A%7B%22http%3A%2F%2Fsite.be%2Fclaims%2Froles%22%3Anull%7D%7D" 2>/dev/null| curl -v -b session_cookies.txt -L -H "Content-Type: application/x-www-form-urlencoded" -v -d 'j_username=manager-sitelogin@gmail.com&j_password=site1' "https://login.uat.site.be/openid/login.do" 2>&1 >/dev/null | grep Location | grep code=';
$result = shell_exec($cmd);
dd($result);
Run Code Online (Sandbox Code Playgroud)
注意:状态!= b4cf8fe7-aa68-4b25-8f9a-03a67fb420c7
注:状态 = 12345678-256d-425d-808b-1e05d2aa3d72 …
运行任何php artisan命令时,我不断收到此错误。
[ErrorException]
file_put_contents(/Applications/MAMP/htdocs/code/bheng/md-bheng/bootstrap/cache/services.json):无法打开流:没有这样的
文件或目录
我该如何阻止?
psql -E -U siteportal -d portal -h 172.19.242.32 -c "COPY externals (id,logo_path,favicon_path,cover_path,header,description,sign_enable,sign_text,footer_logo_enable,footer_logo_path,footer_text,created_at,updated_at) FROM '/Applications/MAMP/htdocs/code/site/portal/public/csv/externals.csv' DELIMITER ',' csv;"
Run Code Online (Sandbox Code Playgroud)
ERROR: could not open file "/Applications/MAMP/htdocs/code/site/portal/public/csv/externals.csv" for reading: No such file or directory
Run Code Online (Sandbox Code Playgroud)
但我肯定知道文件存在,因为我跑的时候
cat /Applications/MAMP/htdocs/code/site/portal/public/csv/externals.csv
Run Code Online (Sandbox Code Playgroud)
我有
1,"/images/account/operator/logo.png","/images/account/operator/favicon.png","/images/account/operator/external.png","site Portal","Log in using your credentials",1,"This is a secure page",1,"/images/account/operator/footer_logo.png","© 2017 site Networks Inc.","2016-12-22 13:37:42","2017-01-31 14:22:11"
Run Code Online (Sandbox Code Playgroud)
是因为许可吗?
-rwxrwxrwx@ 1 site staff 307 May 24 13:46 externals.csv
Run Code Online (Sandbox Code Playgroud)
我甚至试着chomd 777和我一起跑步sudo.但似乎没有任何帮助!
我有一个非常简单的PHP数组
$array = [];
$array['a'] = '1';
$array['b'] = '2';
$array['c'] = '3';
Run Code Online (Sandbox Code Playgroud)
如果我dd($array);出去了
array:3 [?
"a" => "1"
"b" => "2"
"c" => "3"
]
Run Code Online (Sandbox Code Playgroud)
如果我解码dd(json_encode($array));,我得到了这个
"{"a":"1","b":"2","c":"3"}"
Run Code Online (Sandbox Code Playgroud)
我希望能够在我的Javascript中访问此变量,所以我尝试过
的console.log($阵列);
我有
$ array未定义
我正在使用Laravel. {{ }} == echo
的console.log( '{{$阵列}}');
我有
500 Internal Error
htmlentities()期望参数1为字符串,给定数组(查看:/Users/bheng/Sites/portal/resources/views/cpe/index.blade.php)
console.log('{{json_encode($ array)}}');
我有
要加载的页面,但数据看起来很糟糕
{"a":"1","b":"2","c":"3"}
console.log(JSON.parse('{{json_encode($ array)}}'));
我有
未捕获的SyntaxError:位于1的JSON中出现意外的令牌
console.log(JSON.parse('{{json_decode($ array)}}'));
我有
json_decode()期望参数1为字符串,给定数组
console.log('{{json_decode($ array)}}');
我有
json_decode()期望参数1为字符串,给定数组
我只是希望能够在Javascript中以Javascript Array或JSON的形式访问我的数组.
有人可以请我填一下吗?
我在Laravel 5.8中-我一直遇到这个CORS问题

我试过了
php artisan make:middleware Cors
Run Code Online (Sandbox Code Playgroud)
添加这些代码
<?php
namespace App\Http\Middleware;
use Closure;
class Cors
{
public function handle($request, Closure $next)
{
return $next($request)
->header(‘Access-Control-Allow-Origin’, ‘*’)
->header(‘Access-Control-Allow-Methods’, ‘GET, POST, PUT, DELETE, OPTIONS’)
->header(‘Access-Control-Allow-Headers’, ‘X-Requested-With, Content-Type, X-Token-Auth, Authorization’);
}
}
Run Code Online (Sandbox Code Playgroud)
重新启动我的本地Apache 2 sudo apachectl -k restart
打开app/Http/Kernel.php-添加了这1行
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'admin' => \App\Http\Middleware\AdminMiddleware::class,
'dev' => \App\Http\Middleware\DevMiddleware::class,
'cors' => \App\Http\Middleware\Cors::class, <----- …Run Code Online (Sandbox Code Playgroud) 由于在本地,我只做了php artisan serve并且效果很好。在我的生产虚拟机中,我不确定是否应该执行相同的操作php artisan serve &
,这样我就不必安装Nginx、配置文档根目录等。
这样做有什么缺点吗?
我有这个简单的日期选择器 jQuery,在我的应用程序中,我的用户可以回到过去,但不能回到未来。我想根据 url 浏览器中的日期参数显示当前日期。
让我们说
var url_string = window.location.href;
var url = new URL(url_string);
var dateParam = url.searchParams.get("date"); <<----- current date
Run Code Online (Sandbox Code Playgroud)
$(".clock").click(function() {
$( "#expiryDate" ).datepicker('setDate', date); <<---- Note here
$("#expiryDate").datepicker({
dateFormat: 'yy-mm-dd',
defaultDate: date,
showAnim: "fold",
gotoCurrent: true,
maxDate: 0,
onSelect: function() {
var dateSelected = $(this).datepicker('getDate');
dateSelected = moment(dateSelected).format('YYYY-MM-DD');
// $( "#expiryDate" ).datepicker('setDate', dateSelected);
playSound('forward');
if(dateParam == null) {
var url = document.location.href+"&date="+dateSelected;
}else {
var url = document.location.href;
url = url.replace(dateParam,dateSelected);
}
document.location = url;
} …Run Code Online (Sandbox Code Playgroud) 我正在使用 L 5.8,并且我有一个包含 3 个输入的表单
现在,我可以使用此软件包通过 SSH 连接到特定服务器laravelcollective/remote": "~5.8。我需要预先 配置IP、UN、PW 等config/remote.php:
'connections' => [
'production' => [
'host' => '1.1.1.1',
'username' => 'code',
'password' => '8888',
'key' => '',
'keytext' => '',
'keyphrase' => '',
'agent' => '',
'timeout' => 10,
],
],
Run Code Online (Sandbox Code Playgroud)
然后,我可以轻松运行任何命令,甚至链接它们
$commands = ['cd /home/code && ./runMe.sh'];
SSH::run($commands, function($line)
{
echo $line.PHP_EOL;
});
Run Code Online (Sandbox Code Playgroud)
结果
我的门户将连接到该服务器并成功运行该命令,并且我已经验证了它。
我需要从表单输入中读取它。是否可以使用相同的插件并动态设置该文件remote.php?
或者
我是否应该开始寻找其他东西,因为这是一条死胡同?
请指教,
我的Nodemon不停地启动和寻找index.js,但我想像app.js现在大多数人使用的那样使用app.js.
如何更新我的 nodemon 以查找 app.js?
我尝试卸载,重新安装也无济于事。
?? vidjot nodemon
[nodemon] 1.17.3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node index.js`
module.js:540
throw err;
^
Error: Cannot find module '/Users/bheng/Sites/vidjot/index.js'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
[nodemon] app crashed - waiting for file changes before starting...
Run Code Online (Sandbox Code Playgroud)
包.json
{
"name": "vidjot",
"version": "1.0.0",
"description": "app to create video idea",
"main": …Run Code Online (Sandbox Code Playgroud)