对于我的下拉列表,我正在使用此代码.
<?= $form->field($medicinerequest, '[' . $id . ']' . 'medicine_name')
->DropDownList(ArrayHelper::map(\app\models\Medicine::find()
->asArray()->all(), 'id', 'medicine_name','medicine_id' ),
[ 'prompt' => 'Please Select' ])?>
Run Code Online (Sandbox Code Playgroud)
我正在获取图片中的下拉列表.但是我希望它在一行中用连字符( - )连接起来.我怎样才能做到这一点?

我在Database中定义了一个列为float.该列在模型中显示为数字.我想格式化Gridview中的columnn有两个小数位,无法找到方法,怎么做.
我试图使用此代码,但得到的错误如 - 未知格式类型:数字
[
'label' => 'Charges',
'attribute' => 'category_charges',
'contentOptions' => ['class' => 'col-lg-1'],
'format' => ['number',2]
],
Run Code Online (Sandbox Code Playgroud)
谢谢.
嗨我想知道按照 AppAsset.php中的Process one之类的文档中描述的流程注册Asset Bundle的优势
public $js = [
'js/myjsfile.js'
];
Run Code Online (Sandbox Code Playgroud)
然后在视图文件中添加Namespace
namespace app\assets;
Run Code Online (Sandbox Code Playgroud)
然后添加use语句
use app\assets\AppAsset;
AppAsset::register($this);
Run Code Online (Sandbox Code Playgroud)
如果我使用Process Two,而不是完成所有这些
$this->registerJs('js/myjsfile.js', $this::POS_READY);
Run Code Online (Sandbox Code Playgroud)
它工作正常.那我为什么要使用Process One呢?
谢谢.
我正在尝试使用指南中给出的Yii2的条件验证器,如:
型号代码
public function rules()
{
// $discharged = function($model) { return $this->discharged == 1; };
return [
[[ 'admission_date','discharge_date', 'doctor_appointment_date', 'operation_date'], 'safe'],
[[ 'package','tpa_name', 'discharged', 'bed_type', 'room_category', 'ref_doctor', 'consultant_doctor', 'operation_name'], 'integer'],
[['advance_amount', 'operation_charges'], 'number'],
[['patient_name', 'ref_doctor_other'], 'string', 'max' => 50],
[['general_regn_no', 'ipd_patient_id'], 'string', 'max' => 20],
[['admission_date', 'discharge_date', 'doctor_appointment_date', 'operation_date'],'default','value'=>null],
['ipd_patient_id', 'unique'],
[['bed_type','admission_date','room_category'],'required'],
['discharge_date', 'required', 'when' => function($model) {
return $model->discharged == 1;
}],
];
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中像:
public function actionCreate()
{
$model = new PatientDetail();
if ($model->load(Yii::$app->request->post()) && $model->save()) …Run Code Online (Sandbox Code Playgroud) 我创建了一个复选框输入作为类型布尔值,用于将值存储为dishcharged - 已选中或未选中.Checked将存储1并且未选中将存储0.
现在我想在网格视图和视图中将值1和0 显示为是或否.怎么能实现这一点.
我的_form.php代码就像
$form->field($model, 'discharged')->checkBox(['label' => 'Discharged',
'uncheck' => '0', 'checked' => '1'])
Run Code Online (Sandbox Code Playgroud)
我试过像
[
'attribute'=>'discharged',
'value'=> ['checked'=>'Yes','unchecked=>'no']
],
Run Code Online (Sandbox Code Playgroud)
但看起来不正确的语法.
谢谢.
我正在尝试使用yii2 Jui自动完成小部件.
我有这个代码正确显示自动完成日期,但我无法保存数据.
$data=ArrayHelper::map(State::find()->all(), 'id', 'state_name' );
$data=array_merge($data);
Run Code Online (Sandbox Code Playgroud)
然后
echo 'State' .'<br>';
echo AutoComplete::widget([
'model'=>$model,
'attribute' => 'state_id',
'clientOptions' => [
'source' => $data,
],
]);
Run Code Online (Sandbox Code Playgroud)
任何解决方案将不胜感激.谢谢.
我Yii::$app->formatter在我的一个属性中使用:
控制器代码
$model->discharge_date=Yii::$app->formatter->asDatetime
($model->discharge_date, 'php:d-M-Y H:i');
Run Code Online (Sandbox Code Playgroud)
型号代码
[['admission_date','discharge_date'],'date','format' => 'php:d-M-Y H:i'],
Run Code Online (Sandbox Code Playgroud)
一切都工作正常,除非出院日期留空,更新时填写此行:
<span class="not-set">(not set)</span>
我无法知道这将来自哪里,就像数据库中的值一样 NUll
谢谢.
我已将日期字段appointment_date配置为datetimemysql db中的字段.
在我的模型Appointment.php规则设置如下:
public function rules()
{
return [
[['appointment_date','weekdays'], 'safe'],
[['appointment_date'], 'date','format' => 'd-M-yyyy H:m'],
Run Code Online (Sandbox Code Playgroud)
并在我设置的组件下的web.php中
'formatter' => [
'defaultTimeZone' => 'UTC',
'timeZone' => 'Asia/Kolkata',
Run Code Online (Sandbox Code Playgroud)
在我看来,我试图格式化显示日期,如下所示:
[
Yii::$app->formatter->asDatetime('appointment_date')
],
Run Code Online (Sandbox Code Playgroud)
现在我收到了错误 -
appointment_date' is not a valid date time value: DateTime::__construct(): Failed to parse time string (appointment_date) at position 0 (a): The timezone could not be found in the database
Array
(
[warning_count] => 1
[warnings] => Array
(
[6] => Double timezone specification
)
[error_count] => 3 …Run Code Online (Sandbox Code Playgroud) 我正在使用 Kartik Depdrop 小部件。
一切正常,除了在我没有选择创建新记录时的值的情况下,更新依赖字段应该显示,Please select而它显示下拉列表中的第一个值并且它在更新时被保存,而我希望即使在更新时也根据情况保存“请选择”的值,即 null。
示例 - 我选择了一个房间类别 - 依赖值是包,也可以为空。所以我没有在依赖字段包中选择任何值。但是当我来更新表单时,下拉列表中的第一个值默认显示,而我想要please select作为默认值。
如何纠正?
$form->field($model, 'package')->widget(DepDrop::classname(), [
'data'=>ArrayHelper::map(\app\models\Package::find()->all(), 'id', 'package_name' ),
'pluginOptions'=>[
'depends'=>['room_category'],
'placeholder'=>'Select...',
'url'=> \yii\helpers\Url::to(['patient-detail/subcat']),
]
])
Run Code Online (Sandbox Code Playgroud)
注意:如果我在创建的依赖下拉列表中选择一个值,则更新时的值显示正确。
我有一个表ipd_charges列
table - ipd_charges
id doctor room_category charges_cash charges_cashless
1 1 1 200 300
2 1 2 300 400
Run Code Online (Sandbox Code Playgroud)
表 - patient_admission
id patient_name tpa_name(if not null, equivalent to charges_cashless)
1 1 Null
2 2 1
Run Code Online (Sandbox Code Playgroud)
table daily_ward_entry
id patient_name room_name doctor_name charges ( from ipd charges)
1 1 1 1 200
2 2 2 1 400
Run Code Online (Sandbox Code Playgroud)
我试图使用这个失败的查询:
$model = \app\models\IpdCharges::find()
->where(['doctor'=>$id])
->andwhere(['room_category'=>$this->room_name])->one();
Run Code Online (Sandbox Code Playgroud)
谢谢.如果需要更多信息,请告诉我.
非常感谢帮助.