yii2表單學習

2021-08-15 00:19:56 字數 1629 閱讀 6179

呼叫

request

元件寫法

在controller

檔案中定義方法名字時,如果名字是駝峰形,即

actionshowuser

這樣子的,訪問鏈結需要寫為

……/web/index.php?r=test/show-user,需要在兩個單詞中間加上一條短橫線-

<?= ? >  等價於 <?php echo?>

表單的建立

<?php use yii\helpers\html; ?>

<?=html::beginform(『 『,』post』,[『id』=>』addform』,』class』=>』form』,』data』=>』fm』]); ?>

..........//裡面為其他表單框

<?=html::endform(); ?>

表單輸入框

<?=html::input(『text』,』name』,』panjican』,[『class』=>』input』]) ?>

型別    名字       預設值        樣式

<?=html::input(『password』,』pwd』,』  『,[『class』=>』pwd』]) ?>

<?=html::input(『hidden』,』hide』,』 『,[『class』=>』hide』]) ?>

表單文字框

<?=html::textarea(『intro』,』panjican』,[『class』=>』textarea』]) ?>

名字     預設值              樣式

表單單選框 

<?=html::radio(『status』,true,[『class』=>』radio』]) ?>

名字    預設值   樣式

<?=html::radiolist(『***』,1,[0 =>』female』,1=>』male』],[『class』=>』***-list』]) ?>

名字    預設值   列表選項                        樣式

表單核取方塊

<?=html::checkbox(『status』,false,[『class』=>』checkbox』] ?>

表單下拉框

<?=html::dropdownlist(『status』,1,[0 =>』no』,1=>』yes』],[class』=>』dropdown』])?>

表單表單標籤

<?=html::label(『目標』,』target』,[『class』=>』target』]) ?>

標籤值  名字        樣式

表單上傳控制項

<?html::fileinput(『image』,null,[『class』=>』upload』]) ?>

表單按鈕

<?html::button(『普通按鈕』,[『class』=>』btn』]) ?>

<?html::submitbutton(『提交按鈕』,[『class』=> 『submitbtn』]) ?>

<?html::resetbutton(『重置按鈕』,[『class』=>』resetbtn』]) ?>

如果提交表單出現亂碼,可以表單前加上

header(『content-type:text/html;charset=utf-8);

Yii2建立表單

文字框 textinput 密碼框 passwordinput 單選框 radio radiolist 核取方塊 checkbox checkboxlist 下拉框 dropdownlist 隱藏域 hiddeninput 文字域 textarea rows 3 檔案上傳 fileinput 提交按...

yii2常用ActiveForm表單

表單整體輸出樣式 form activeform begin options enctype multipart form data class form horizontal method post template template n n colclass class col sm 3 con...

yii2 常用元件 表單

簡介 yii2中最常用的元件activeform,通過對activeform的靈活運用,能有效的提公升開發效率,所以這個是不得不說的乙個yii2元件,那麼下面就來了解一下yii2.0的activeform的具體用法 用法 form signup 文字框的標題 field model,test1 la...