我有这样的网址
http://localhost/belajar4/web/index.php?r=data%2Fsingle&id=2&DataSearch[TANGGAL]=2015-08-04&DataSearch[TANGGAL_SELESAI]=2015-08-12
我想得到DataSearch ['Tanggal'] dan DataSearch [TANGGAL_SELESAI]
我曾尝试过id
Yii::$app->request->queryParams['id']
这是成功的,但不是DataSearch ['Tanggal']
当我尝试DataSearch ['Tanggal']时,错误是
Undefined index: DataSearch[TANGGAL]
我认为它应该很容易回答,但我是yii2的新手,我还没有找到解决方案
以前,我有main.php声明页眉和页脚.哪个好.现在,我期待为2个不同的布局Guest User和Registered User.在哪个Registered User和Admin将有不同的页眉和页脚.
我正在使用Yii2 Basic App.我在文件夹中创建了GuestUser.php和RegisteredUser.phpviews/layouts/.
访客用户表示用户尚未登录该应用程序.并且,注册用户表示用户已登录该应用程序.
现在,我的目录结构是这样的.
views
->layouts
->main.php
->GuestUser.php
->RegisteredUser.php
->site
Run Code Online (Sandbox Code Playgroud)
现在,我如何将GuestUser.php和RegisteredUser.php用于我的应用程序.至于现在,Application 默认采用main.php.我该怎么控制呢?
GuestUser.php
<?php
use yii\helpers\Html;
use app\assets\LocalAsset;
LocalAsset::register($this);
?>
<?php $this->beginPage() ?>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?>
<title>ABC</title>
<?php $this->head() ?>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Oswald:400,700' rel='stylesheet' type='text/css'> …Run Code Online (Sandbox Code Playgroud) 我使用ajax请求将数据传递给yii2但我继续得到500错误
这是ajax请求代码:
<?php
$script = <<< JS
$('form#forward_pr').on('beforeSubmit', function(e){
var keys = $('#grid').yiiGridView('getSelectedRows');
$.post({
url: "forwardpr", // your controller action
dataType: 'json',
data: {keylist: keys},
success: function(data) {
alert('I did it! Processed checked rows.')
},
error: function(err){
console.log("server error");
}
});
return false;
} ) ;
JS;
$this->registerJS($script);
?>
Run Code Online (Sandbox Code Playgroud)
当我执行console.log(keys)时返回
[0, 1]
Run Code Online (Sandbox Code Playgroud)
这是我的控制器代码:
if (Yii::$app->request->post()) {
echo $post = json_encode($_POST['keys']);
if (isset($_POST['keylist'])) {
$keys = \yii\helpers\Json::decode($_POST['keylist']);
print_r($keys);
}else{
echo "1";
}
Run Code Online (Sandbox Code Playgroud)
上面总是执行post请求的错误部分,可能是错的;
我想要做的是从bootstrap垂直更改为水平形式,这是我尝试过的:
<?php $form = ActiveForm::begin([
'layout' => 'horizontal',
'action' => ['index'],
'method' => 'get',
'fieldConfig' => [
'horizontalCssClasses' => [
'label' => 'col-sm-2',
'offset' => 'col-sm-offset-2',
'wrapper' => 'col-sm-4',
],
],
]); ?>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, 'firstname') ?>
<?= $form->field($model, 'lastname') ?>
</div>
<div class="col-md-6">
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'bla') ?>
</div>
</div>
<?php ActiveForm::end() ?>
Run Code Online (Sandbox Code Playgroud)
但它给了我一个错误设置未知属性:yii\widgets\ActiveForm :: layout请帮助!!!
以下活动记录WHERE IN查询不起作用。根据文档,这应该工作:
$data = $dropDownData->find()
->select('country, country_text')
->distinct()
->WHERE(['in', 'server', $servers]);
$listData = ArrayHelper::map($data,'country', 'country_text');
Run Code Online (Sandbox Code Playgroud)
sql等效项是:
$query = "SELECT DISTINCT country, country_text
FROM `dropDownData`
WHERE server IN ({$servers})";
Run Code Online (Sandbox Code Playgroud)
$ servers仅包含字符串1,2,4
我在这里做错了什么?
我有连接到mysql数据库的问题在端口33060上抛出ssh,我的conf:
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=myDatabase',
'emulatePrepare' =>true,
'username' => 'user',
'password' => 'password',
'charset' => 'utf8',
];
Run Code Online (Sandbox Code Playgroud)
我尝试连接时打开ssh tunel,我有一个错误:
SQLSTATE [28000] [1045]用户'用户'@'localhost'拒绝访问(使用密码:YES)
我究竟做错了什么?有可能在Yii2连接抛出ssh吗?
谢谢你的回答!
我使用 Yii2 框架,这是我的行为函数 ShippingController
public function behaviors()
{
return [
'access' => [
'class' => \yii\filters\AccessControl::className(),
'rules' => [
// deny all POST requests
// [
// 'actions' => ['index', 'create'],
// 'allow' => TRUE,
// ],
[
'actions' => ['index', 'create', 'init'],
'allow' => true,
'roles' => ['?'],
'matchCallback' => function ($rule, $action)
{
return $action->controller->redirect('action');
}
],
'denyCallback' => function ($rule, $action)
{
return $action->controller->redirect('not');
}
// everything else is denied
],
],
];
}
Run Code Online (Sandbox Code Playgroud)
matchCallback 运行良好,但
在 …
我正在使用 yii2 REST Api basicauth 开发一个 api。我已经在本地xampp服务器上开发成功了。我已将代码部署到运行 centos 的 vps 上。但我收到以下未经授权的回复:
\n\n{\n"name": "Unauthorized",\n"message": "Your request was made with invalid credentials.",\n"code": 0,\n"status": 401,\n"type": "yii\\\\web\\\\UnauthorizedHttpException"\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我已经正确设置了标题。
\n\n响应标头:
\n\nConnection \xe2\x86\x92Keep-Alive\nContent-Type \xe2\x86\x92application/json; charset=UTF-8\nDate \xe2\x86\x92Fri, 05 May 2017 08:40:49 GMT\nKeep-Alive \xe2\x86\x92timeout=5, max=100\nServer \xe2\x86\x92Apache\nTransfer-Encoding \xe2\x86\x92chunked\nWww-Authenticate \xe2\x86\x92Basic realm="api"\nX-Powered-By \xe2\x86\x92PHP/5.6.30\n\n\nmy headers: \nAuthorization : Basic BVrVm3Ay0jg2XBr3TeITaClg\nContent-Type : application/x-www-form-urlencoded\nRun Code Online (Sandbox Code Playgroud)\n\n当我转储标头时,我看不到授权标头:
\n\nobject(yii\\web\\HeaderCollection)#81 (1) {\n ["_headers":"yii\\web\\HeaderCollection":private]=>\n array(10) {\n ["content-type"]=>\n array(1) {\n [0]=>\n string(33) "application/x-www-form-urlencoded"\n }\n ["accept"]=>\n array(1) {\n [0]=>\n string(3) "*/*"\n }\n ["accept-encoding"]=>\n array(1) {\n [0]=>\n …Run Code Online (Sandbox Code Playgroud) 我试图在同一页面中获取所选选项的值。我正在使用 select2 小部件。
<?php
echo '<label class="control-label">Group</label>';
$data = ['1' => 'option1', '2' => 'option2'];
echo Select2::widget([
'name'=> 'group',
'data' => $data,
'options' => ['placeholder' => 'Select a option...', 'id' => 'sem'],
'pluginOptions' => [
'allowClear' => true
],
]);
?>
<input type="text" id='items' value="<?=$selectedvalue?> />'
Run Code Online (Sandbox Code Playgroud)
在这里,我想在输入框中获取该页面中的选定值。
<input type="text" id='items' value="<?=$selectedvalue?> />
Run Code Online (Sandbox Code Playgroud)
我正在使用 Yii2 我是新手。谁能帮我?
在 GridView 小部件中并显示我从自定义查询中获取的 ActiveDataprovider 结果时,我想在显示记录时获取下一行和上一行 $model->id,我需要做的是显示指向上一个和下一个帖子的链接阅读模式,我的 gridview 已经生成了 post 视图的链接,但似乎没有获取下一个 DB 行的记录 ID 的选项
我已经尝试在可用函数中使用默认值,但它们似乎没有任何相关数据
GridView::widget([
'dataProvider' => $dataProvider,
...
'columns' => [
...
[
'label'=>'Post Name',
'format' => 'raw',
'value'=>function ($data, $key, $index, $obj) {
// this is what i have right now
return Html::a($data->name, ['view', 'id' => $data->id]);
//ideally i would like something like this
return Html::a($data->name, ['view',
'id' => $data->id,
'prev' => $prev->id,
'next' => $next->id
]);
},
],
],
....
)];
Run Code Online (Sandbox Code Playgroud)