我已经阅读了文档,但是无法弄清楚该怎么做,例如,我index.php在视图文件夹中的文件中有一个小脚本,medicine-issue-entry例如:
<?php
$js = 'function refresh() {
$.pjax.reload({container:"#medicine_request_entry"});
setTimeout(refresh, 60000); // restart the function every 5 seconds
}
refresh();';
$this->registerJs($js, $this::POS_READY);
?>
Run Code Online (Sandbox Code Playgroud)
在哪里可以将此代码放在单独的文件中,以及如何在相关文件中包括该代码。详细的过程将不胜感激。谢谢。
好的,我正在使用基本模板。在AppAsset.php我包括像
public $js = [
'js/autorefresh.js'
];
Run Code Online (Sandbox Code Playgroud)
并使用以下代码js在其中创建一个文件夹web folder并创建一个新文件autorefresh.js:
function refresh() {
$.pjax.reload({container:"#medicine_request_entry"});
setTimeout(refresh, 60000); // restart the function every 5 seconds
}
refresh();
Run Code Online (Sandbox Code Playgroud)
在我中index.php我添加了一行
namespace app\assets;
use app\assets\AppAsset;
AppAsset::register($this);
Run Code Online (Sandbox Code Playgroud)
但是,这同样行不通,我还缺少什么吗?当我在文件中包含代码时,registerJs它工作正常。
注意:在查看页面源文件时,文件已正确发布,然后单击链接显示脚本,但代码不起作用。
我试图在Yii2的GridView小部件中为相关模型设置过滤器,但我不断得到错误,因为过滤器值必须是整数.
我跟着这个问题.现在,我有两个型号Services.php和ServiceCharge.php.
在ServiceCharge.php关系设置如下:
public function getServiceName()
{
return $this->hasOne(Services::className(),['id'=>'service_name']);
}
Run Code Online (Sandbox Code Playgroud)
在ServiceChargeSearch.php代码中是这样的:
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\ServiceCharges;
/**
* ServiceChargesSearch represents the model behind the search form about `app\models\ServiceCharges`.
*/
class ServiceChargesSearch extends ServiceCharges
{
/**
* @inheritdoc
*/
public function attributes()
{
// add related fields to searchable attributes
return array_merge(parent::attributes(), ['serviceName.services']);
}
public function rules()
{
return [
[['id'], 'integer'],
[['charges_cash', …Run Code Online (Sandbox Code Playgroud) 好了,我可以过滤任何字段,包括相关字段中的列,但是我想知道如何过滤日期字段。
我遇到的一个解决方案是过滤器的日期选择器,我没有测试过,但是我的要求没有什么不同。
例如,我已经datetime在gridview中复制了该列,并将其格式化为
[
'attribute'=>'discharge_date',
'format'=>['DateTime','php:M']
],
Run Code Online (Sandbox Code Playgroud)
因此该列将仅显示月份。该列正确显示了月份。
现在,我想按月在此列上进行过滤。任何建议将不胜感激。谢谢。
我确实尝试过
[
'attribute'=>'discharge_date',
'value'=>'discharge_date',
'filter' => ['2015-01'=>'Jan','2015-02'=>'Feb','2015-03'=>'Mar'],
'format'=>['DateTime','php:M']
],
Run Code Online (Sandbox Code Playgroud)
效果很好,但是这里是硬编码的年份,我不希望这样。我知道这不是正确的方法。谢谢
假设我的网格视图 is_delivered 中有一个列,其中包含例如的值数组
(1,1,0), (1,1,1),(0,0,0) 一共三个组合。我已将单元格的 ID 设置为“已交付”
现在我如何根据列中的值更改行的颜色,例如红色、蓝色或黄色。
例如,如果它是 (1,1,1),那么行颜色将为绿色,如果 (1,1,0) 则行颜色将为黄色,否则为红色。
我无法弄清楚从哪里开始以及如何开始。我不能在这里使用 ==,因为它可以包含 3 个以上的值。需要使用一些运算符,如包含。
我正在尝试使用一个简单的代码,例如
<?php
$script = <<<EOD
alert ($('#delivered').val());
EOD;
$this->registerJs($script);
?>
Run Code Online (Sandbox Code Playgroud)
但它给了我一个没有任何价值的空白警报。
感谢您的任何建议。
更新列 is_delivered 值的问题
[
'attribute'=>'is_delivered',
'value' => function ($data) {
$str = '';
foreach($data->medicineRequests as $request) {
$str .= $request->is_delivered.',';
}
return $str;
},
],
Run Code Online (Sandbox Code Playgroud)
所以列 is_delivered 是一对多并从另一个模型中提取的。
好的我正在尝试使用Kartik Depdrop小部件,所有我都得到一个白色下拉列表,其值不在依赖下拉列表中显示.
我有一个州模型和一个城市模型,我有这样的设置.
在_form.php中
$catList=ArrayHelper::map(app\models\State::find()->all(), 'id', 'state_name' );
echo $form->field($model, 'state')->dropDownList($catList, ['id'=>'state_name']);
echo $form->field($model, 'district_city')->widget(DepDrop::classname(), [
'options'=>['id'=>'district_city'],
'pluginOptions'=>[
'depends'=>['state_name'], // the id for cat attribute
'placeholder'=>'Select...',
'url'=> \yii\helpers\Url::to(['patient-entry/subcat'])
]
]);
?>
Run Code Online (Sandbox Code Playgroud)
然后在模型中
public static function getCity($city_id) {
$data=\app\models\City::find()
->where(['state_name'=>$city_id])
->select(['id','city_name'])->asArray()->all();
return $data;
}
Run Code Online (Sandbox Code Playgroud)
然后在我的控制器中
public function actionSubcat() {
$out = [];
if (isset($_POST['depdrop_parents'])) {
$parents = $_POST['depdrop_parents'];
if ($parents != null) {
$cat_id = $parents[0];
$out = \app\models\PatientEntry::getCity($cat_id);
echo Json::encode(['output'=>$out, 'selected'=>'']);
return;
}
}
echo Json::encode(['output'=>'', 'selected'=>'']);
}
Run Code Online (Sandbox Code Playgroud)
当我选择状态字段时,firebug控制台正确显示数据,如:
{"output":[{"id":"172","city_name":"Along"},{"id":"173","city_name":"Bomdila"},{"id":"174","city_name":"Itanagar"},{"id":"175","city_name":"Naharlagun"},{"id":"176","city_name":"Pasighat"}],"selected":""} …Run Code Online (Sandbox Code Playgroud) 仅用于测试我在设置debug = true和false时在我的模型中添加了此代码.
if($packagedays < 1)
{
throw new \yii\base\Exception( "package days cannot be less than 1" );
}
Run Code Online (Sandbox Code Playgroud)
现在当Yii调试成立时:我得到了
异常 - yii\base\Exception包天数不能小于1
但是当我将调试设置为false时,我得到了Exception
An internal server error occurred.
Web服务器处理您的请求时发生上述错误.
我想是更换An internal server error occurred.
用
package days cannot be less than 1时debug=false
我在这里缺少什么?
谢谢.
我无法将自定义表单重定向到特定操作.
我在想的是
<?= Html::submitButton( 'delete-selected' ,['class' => 'btn btn-primary']) ?>
Run Code Online (Sandbox Code Playgroud)
这delete-selected是我在控制器中的自定义操作appointment.
我也尝试过这样的:
public function actionDeleteForm()
{
return $this->render('delete');
return $this->redirect(['delete-selected']);
}
public function actionDeleteSelected()
{
Appointment::deleteAll(['doctor_name' =>4]);
return $this->redirect(['index']);
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是使用表单删除一些记录.表单名称delete具有选择下拉字段.
我想将数据发布到操作deleteselected并在删除查询中使用$ _POST变量.
我怎样才能做到这一点?
谢谢.
我使用以下命令从CSV文件导入数据.
load data infile 'l:\health_card.csv'
into table health_card
fields terminated by ','
enclosed by '"'
LINES TERMINATED BY '\n'
ignore 1 lines
( @date, health_card_number, patient_name,age,street_address,mobile,@birth_date,@anniversary,card_rate,card_amount,relation_name)
set date = STR_TO_DATE(@date, '%m.%d.%Y'),
birth_date = STR_TO_DATE(@birth_date, '%m.%d.%Y'),
anniversary = STR_TO_DATE(@anniversary, '%m.%d.%Y')
Run Code Online (Sandbox Code Playgroud)
create table语句是这样的:
CREATE TABLE `health_card` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`health_card_number` varchar(30) DEFAULT NULL,
`patient_name` varchar(50) DEFAULT NULL,
`general_regn_number` varchar(30) DEFAULT NULL,
`date` date DEFAULT NULL,
`relation_name` varchar(300) DEFAULT NULL,
`relation` varchar(30) DEFAULT NULL,
`age` int(11) DEFAULT NULL,
`birth_date` date …Run Code Online (Sandbox Code Playgroud)