有没有办法配置更漂亮来防止非多行三元运算?
想要这个:
const route = routeModule.config ? routeModule.config(router) : routeModule(router);
Run Code Online (Sandbox Code Playgroud)
不是这个:
const route = routeModule.config
? routeModule.config(router)
: routeModule(router);
Run Code Online (Sandbox Code Playgroud)
我的prettier.config.js:
module.exports = {
trailingComma: 'es5',
tabWidth: 4,
semi: true,
singleQuote: true,
printwidth: 200,
bracketspacings: true,
};
Run Code Online (Sandbox Code Playgroud) 如何创建自定义类而不是扩展组件类?
课程:
namespace common\components;
class AsyncOperation extends Thread {
public function __construct($arg) {
$this->arg = $arg;
}
public function run() {
if ($this->arg) {
$sleep = mt_rand(1, 10);
printf('%s: %s -start -sleeps %d' . "<br />", date("g:i:sa"), $this->arg, $sleep);
sleep($sleep);
printf('%s: %s -finish' . "<br />", date("g:i:sa"), $this->arg);
}
}
}
Run Code Online (Sandbox Code Playgroud)
yii2控制器:
public function actionTest() {
// Create a array
$stack = array();
//Iniciate Miltiple Thread
foreach (range("A", "D") as $i) {
$stack[] = new AsyncOperation($i);
}
// Start The …Run Code Online (Sandbox Code Playgroud) 怎么用 Yii::$app->session['somename']在yii2 assetmanager中?
如何在assetmanager中访问某些功能?
class AppAsset extends AssetBundle{
public function getLang() {
$currentLang = Yii::$app->session['lang'];
if ($currentLang == 'fa' || $currentLang == 'ar') {
return 'RTL';
} else {
return 'LTR';
}
}
public $lang;
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/iconSprite.min.css',
// how call getLang here
]
Run Code Online (Sandbox Code Playgroud)
怎么打电话给getLangcss部分?
我通过composer安装了kartik fileinput并成功安装!
但当我使用它时:
use yii\helpers\Url;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\widgets\FileInput;
echo FileInput::widget([
'name' => 'attachment_48[]',
'options' => [
'multiple' => true
],
'pluginOptions' => [
'uploadUrl' => Url::to(['/site/file-upload']),
'uploadExtraData' => [
'album_id' => 20,
'cat_id' => 'Nature'
],
'maxFileCount' => 10
]
]);
Run Code Online (Sandbox Code Playgroud)
在后端部分,我得到错误:
Class 'kartik\widgets\FileInput' not found
Run Code Online (Sandbox Code Playgroud)
我的代码出了什么问题?
任何帮助赞赏!
我在有方法测试的公共文件夹中有控制器
public function actionTest() {
$s = "sdfs";
return $s;
}
Run Code Online (Sandbox Code Playgroud)
并为这个动作设置 afterAction,例如:
public function afterAction($action) {
if ($action->id == "test") {
echo 'here afterActioin';
}
}
Run Code Online (Sandbox Code Playgroud)
我从另一个控制器调用测试操作:
public function actionTest3() {
echo Yii::$app->runAction('travia/test');
}
Run Code Online (Sandbox Code Playgroud)
问题是当我在浏览器中调用 test3 时没有显示但如果我评论 afterAction 方法将返回。问题出在哪里 afterAction 的行为是什么,不允许我的行动返回某些东西?
我在yii2中有以下代码,但验证码图像没有显示!
控制器:
public function actions() {
return [
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
'foreColor' => 0xF9AF21,
'maxLength' => 5,
'minLength' => 3,
'padding' => 5,
'offset' => 1,
'transparent' => true,
'height' => 40
],
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}
Run Code Online (Sandbox Code Playgroud)
型号:(规则)
['verifyCode', 'captcha',],
Run Code Online (Sandbox Code Playgroud)
视图:
$form->field($model, 'verifyCode')->widget(Captcha::className()])
Run Code Online (Sandbox Code Playgroud)
像这样的结果
{"id":19,"iso":"BB","name":"BARBADOS","nicename":"Barbados","iso3":"BRB","numcode":52,"phonecode":1246},{"id":20,"iso":"BY","name":"BELARUS","nicename":"Belarus","iso3":"BLR","numcode":112,"phonecode":375}]
,"_links":{"self":{"href":"http://localhost/travia-api/backend/web/v1/flight/index?id=4FR996IN2F829Md&page=1"},"next":{"href":"http://localhost/travia-api/backend/web/v1/flight/index?id=4FR996IN2F829Md&page=2"},"last":{"href":"http://localhost/travia-api/backend/web/v1/flight/index?id=4FR996IN2F829Md&page=12"}},"_meta":
Run Code Online (Sandbox Code Playgroud)
{“ totalCount”:239,“ pageCount”:12,“ currentPage”:1,“ perPage”:20}}
如何更改每页或禁用分页???
更新!
设置标题内容类型,但不起作用!
X-Pagination-Per-Page: 90
-- response --
200 OK
Date: Tue, 01 Sep 2015 12:29:45 GMT
Server: Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.19
X-Powered-By: PHP/5.5.19
X-Pagination-Total-Count: 239
Run Code Online (Sandbox Code Playgroud)
X分页计数:12 X分页当前页:1 X分页每页:20
Content-Length: 2421
Run Code Online (Sandbox Code Playgroud)
Keep-Alive:超时= 5,最大= 100连接:Keep-Alive内容类型:application / json; 字符集= UTF-8
{“结果”:[{“ id”:1,“ iso”:“ AF”,“名称”:“ AFGHANISTAN”,“ nicename”:“阿富汗”,“ iso3”:“ AFG”,“数字”:4 ,“ phonecode”:93},... {“ id”:20,“ iso”:“ BY”,“ name”:“ BELARUS”,“ nicename”:“白俄罗斯”,“ iso3”:“ BLR”, “ numco de”:112,“电话代码”:375}],_ meta“:{” totalCount“:239,” pageCount“:12,” currentPage“:1,” perPage“:20}}