大致流程如下:
視圖層
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="/test" method="post">
{:token()}
username:
<input type="text" name="username">
email:
<input type="email" name="email">
<input type="submit" value="submit">
</form>
</body>
</html>
驗證器User
<?php
namespace app\index\validate;
use think\Validate;
class User extends Validate
{
protected $rule = [
'username' => 'require|max:25|token',
'email' => 'email',
];
}
Controller層
<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
class Index extends Controller
{
public function index()
{
return view('index');
}
public function test(Request $request)
{
$result = $this->validate(
[
'__token__' => $request->param('__token__'),
'username' => $request->param('username'),
'email' => $request->param('email'),
],
'app\index\validate\User'
);
if ($result !== true) {
dump($result);
} else {
dump($request->param());
}
}
}
$config = [
//others
'modules' => [
'debug' => [
'class' => 'yii\debug\Module',
],
'gii' => [
'class' => 'yii\gii\Module',
];
],
//others
]
class yii\base\Application extends yii\base\Module
class yii\base\Module extends yii\di\ServiceLocator
class yii\di\ServiceLocator extends yii\base\Component
class yii\base\Component extends yii\base\Object
public function __construct($config = [])
{
Yii::$app = $this;
//將\yii\base\Application中的所有的屬性和方法交給Yii::$app->loadedModules數(shù)組中
static::setInstance($this);
$this->state = self::STATE_BEGIN;
//加載配置文件的框架信息 如:設(shè)置別名,設(shè)置框架路徑等等最為重要的是給加載默認組件
$this->preInit($config);
//加載配置文件中的異常組件
$this->registerErrorHandler($config);
// 調(diào)用父類的 __construct。
// 由于Component類并沒有__construct函數(shù)
// 這里實際調(diào)用的是 `yii\base\Object__construct($config)`
Component::__construct($config);
}
Component::__construct($config)
會調(diào)用 yii\base\Object::__construct()
方法public function __construct($config = [])
{
if (!empty($config)) {
// 將配置文件里面的所有配置信息賦值給Object。
// 由于Object是大部分類的基類,
// 實際上也就是有配置信息賦值給了yii\web\Application的對象
Yii::configure($this, $config);
}
$this->init();
}
'components' => [ 'log' => [...]]
從哪來,若不關(guān)心可以直接看 第二步。$this->preInit($config);
,即 yii\base\Application::preInit(&$config)
public function preInit(&$config)
{
//others...
// merge core components with custom components
// 合并核心組件和自定義組件
foreach ($this->coreComponents() as $id => $component) {
if (!isset($config['components'][$id])) {
// 若自定義組件中沒有設(shè)置該核心組件配置信息,直接使用核心組件默認配置
$config['components'][$id] = $component;
} elseif (is_array($config['components'][$id]) && !isset($config['components'][$id]['class'])) {
// 若自定義組件有設(shè)置該核心組件配置信息,但是沒有設(shè)置 'class'屬性,則添加該class屬性
$config['components'][$id]['class'] = $component['class'];
}
}
}
/**
* Returns the configuration of core application components.
* 返回核心應(yīng)用組件的配置
* @see set()
*/
public function coreComponents()
{
return [
// 日志分配器組件
'log' => ['class' => 'yii\log\Dispatcher'],
//others...
];
}
$this->preInit($config);
, 我們得到的 $config
$config = [
'modules' => [
'debug' => [
'class' => 'yii\debug\Module',
],
'gii' => [
'class' => 'yii\gii\Module',
];
],
'components' => [
'log' => [
'class' => 'yii\\log\\Dispatcher',
],
//others...
]
//others...
]
'components' => [ 'log' => [...]]
從哪來yii\base\Object::__construct($config = [])
中的 Yii::configure($this, $config);
public static function configure($object, $properties)
{
// 只是遍歷配置信息,賦值給當前對象
foreach ($properties as $name => $value) {
$object->$name = $value;
}
return $object;
}
yii\base\Object::__set($name, $value)
/**
* 為實例不存在的屬性賦值時調(diào)用
*
* Do not call this method directly as it is a PHP magic method that
* will be implicitly called when executing `$object->property = $value;`.
* 這個是PHP的魔術(shù)方法,會在執(zhí)行 `$object->property = $value;` 的時候自動調(diào)用。
*/
public function __set($name, $value)
{
// setter函數(shù)的函數(shù)名
// 由于php中方法名稱不區(qū)分大小寫,所以setproperty() 等價于 setProperty()
$setter = 'set' . $name;
if (method_exists($this, $setter)) {
// 調(diào)用setter函數(shù)
$this->$setter($value);
} elseif (method_exists($this, 'get' . $name)) {
// 如果只有g(shù)etter沒有setter 則為只讀屬性
throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
} else {
throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
}
}
當前情景下的 $object
我們可以認為是 yii\base\Application
的對象 $app
$app->modules = [
'debug' => [
'class' => 'yii\debug\Module',
],
'gii' => [
'class' => 'yii\gii\Module',
];
]
這里會調(diào)用 yii\base\Module::setModules($modules)
方法
public function setModules($modules)
{
foreach ($modules as $id => $module) {
$this->_modules[$id] = $module;
}
}
這樣便有了問題中的
["_modules":"yii\base\Module":private]=>
array(3) {
["debug"]=> object(yii\debug\Module)#33 (28) {
......
}
["gii"]=> object(yii\gii\Module)#113 (21) {
......
}
...
}
$app->components = [
'log' => [
'class' => 'yii\\log\\Dispatcher',
],
]
yii\di\ServiceLocator::setComponents($components)
方法public function setComponents($components)
{
foreach ($components as $id => $component) {
$this->set($id, $component);
}
}
public function set($id, $definition)
{
// others ...
if (is_object($definition) || is_callable($definition, true)) {
// an object, a class name, or a PHP callable
$this->_definitions[$id] = $definition;
} elseif (is_array($definition)) {
// 定義如果是個數(shù)組,要確保數(shù)組中具有 class 元素
// a configuration array
if (isset($definition['class'])) {
// 定義的過程,只是寫入了 $_definitions 數(shù)組
$this->_definitions[$id] = $definition;
} else {
throw new InvalidConfigException("The configuration for the \"$id\" component must contain a \"class\" element.");
}
} else {
throw new InvalidConfigException("Unexpected configuration type for the \"$id\" component: " . gettype($definition));
}
}
這樣便有了問題中的
["_definitions":"yii\di\ServiceLocator":private]=>
array(24) {
["errorHandler"]=> .....
["request"]=> ......
["log"]=> ......
......
}
你都用mb_detect_encoding
了,為啥不用mb_convert_encoding
呢?
直接open會被瀏覽器阻止的,location可以跳轉(zhuǎn)
echo ("<script>window.location = 'http://www.baidu.com';</script>");
一般拿openid都是放在頁面入口,通過調(diào)用微信的獲取用戶信息接口來實現(xiàn)。因為獲取時可能會涉及到跳轉(zhuǎn)動作(調(diào)到微信自己的頁面做用戶授權(quán),然后再根據(jù)跳轉(zhuǎn)時傳遞的url參數(shù)跳回來),所以一般都不會放在流程中間怕丟狀態(tài)。還有就是獲取用戶信息時有兩種方式,如果只要openid的話可以用靜默的,用戶無感知;但如果需要昵稱什么的,就得要用戶顯式的授權(quán)下了。
// dev.env.js
module.exports = merge(prodEnv, {
NODE_ENV: '"development"',
host: '0.0.0.0',
AXIOS_BASR_URL: '""',
NUM: '0'
})
可以閱讀 vue-cli 2.9.3 開發(fā)模式變量和生產(chǎn)模式變量,這一章節(jié)。
指定環(huán)境變量,就可以在生產(chǎn)模式,還是開發(fā)模式,進行狀態(tài)判斷。
Yii自帶方法
echo Yii::$app->getSecurity()->generateRandomString(6);
float元素是不能把父級元素撐高的
file_get_contents()
是專門用來獲取文件數(shù)據(jù)流的,要么拿到,要么報錯,你的目的如果只是想要請求,試試curl
,可以設(shè)置請求時長
更改下語言為英文,你應(yīng)該是中文或者其他的,或者是安裝一款字體,否則顯示的確會不正常
喏,十個 PHP 開發(fā)者最容易犯的錯誤里的第一條。
bus=virtio
你可以在本地環(huán)境測試,他執(zhí)行curl只是為了測試接口是否正常,你本地測試好可以放虛擬主機上
代碼
`
$redata = array(
0=>['id'=>1,'name'=>'張三','age'=>22,'hobby'=>'學習'],
1=>['id'=>1,'name'=>'張三','age'=>22,'hobby'=>'騎行'],
2=>['id'=>2,'name'=>'李四','age'=>20,'hobby'=>'旅游'],
);
function hebing($redata){
foreach ($redata as $k => $v) {
if($redata[$k]['id']==$redata[$k+1]['id']){
$redata[$k+1]['hobby'] = [$redata[$k]['hobby'],$redata[$k+1]['hobby']];
array_splice($redata, $k, 1);
}
}
return $redata;
}
var_dump(hebing($redata));
`
你可以ajax請求一次,但是curl你可以等第一個的執(zhí)行結(jié)果出來之后在執(zhí)行第二個,知道達到你的終止條件,然后把結(jié)果返回給ajax
-e TZ=Aisa/Shanghai
資源長時間就被釋放
這種說法,我是不認同的。我一個項目用的是純PHP多進程守護處理任務(wù),跑了一年多都沒問題。
僅從代碼上,尚未看出有什么問題。是否可以多加些運行日志,這樣有助于排查問題?
北大青鳥APTECH成立于1999年。依托北京大學優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學院和江蘇省首批服務(wù)外包人才培訓基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團,成為集合面授教學培訓、網(wǎng)
達內(nèi)教育集團成立于2002年,是一家由留學海歸創(chuàng)辦的高端職業(yè)教育培訓機構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
浪潮集團項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風格 授課風格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
曾工作于聯(lián)想擔任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍懿科技有限責任公司從事總經(jīng)理職務(wù)負責iOS教學及管理工作。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。