使用过yii框架的同学都知道,yii框架中的form表单可以使用yii内部定义form组件来进行提交,小编今天就带着大家来看看,yii中的form表单组件吧!
话不多说上代码:
<?php //引入命名空间 use yii\helpers\Html; ?> <?php //表单:Html::beginForm(提交地址,提交方法,属性数组);?> $form = ActiveForm::begin([ 'action' => ['test/getpost'], 'method'=>'post', ]); ?> <?=Html::beginForm('','post',['id'=>'form','class'=>'form','data'=>'myself']);?> <?php //(二)输入框:Html::input(类型,name值,默认值,属性数组;)?> <?=Html::input('text','test','',['class'=>'form-control','placeholder'=>'hehe'])->hint('Please enter your test')->label('Name');?> <?=Html::input('email','email','admin@admin.com',['class'=>'form-control']);?> <?=Html::input('password','pwd','',['class'=>'form-control']);?> <?Html::input('hidden','hidden','',['class'=>'form-control']);?> <hr/> <?php //Html::表单类型input(name值,默认值,属性数值);?> <?=Html::textInput('test','hehe',['class'=>'form-control']);?> <?=Html::textInput('email','admin@admin.com',['class'=>'form-control']);?> <?Html::passwordInput('pwd','',['class'=>'form-control']);?> <?Html::hiddenInput('hidden','',['class'=>'form-control']);?> <hr/> <?php //(三) 文本域 Html::textarea()?> <?=Html::textarea('area','',['class'=>'form-control','row'=>'3']);?> <hr/> <?php //单选按钮 Html::checkbox(name值,是否选中,属性数组)?> <?=Html::radio('sex',true,['class'=>'form-control']);?> <?=Html::radioList('height','1',['1'=>'160','2'=>'170','3'=>'180'],['class'=>'form-control']);?> <?php //复选框?> <?=Html::checkbox('haha',true,['class'=>'form-control']);?> <?php //复选框列表?> <?=Html::checkboxList('xixi','1',['1'=>'160','2'=>'170','3'=>'180'],['class'=>'form-control']);?> <?php //下拉列表?> <?=Html::dropDownList('list','2',['1'=>'160','2'=>'170','3'=>'180'],['class'=>'form-control'])?> <?=Html::label('显示的','test',['style'=>'color:#ff0000']);?> <hr/> <?php //上传控件?> <?=Html::fileInput('img',null,['class'=>'btn btn-default']);?> <hr/> <?php //按钮?> <?=Html::button('普通按钮',['class'=>'btn btn-primary']);?> <?=Html::submitButton('提交按钮',['class'=>'btn btn-primary']);?> <?=Html::resetButton('重置按钮',['class'=>'btn btn-primary']);?> <?=Html::endForm()?>
文本框:textInput();
密码框:passwordInput();
单选框:radio(),radioList();
复选框:checkbox(),checkboxList();
下拉框:dropDownList();
隐藏域:hiddenInput();
文本域:textarea([‘rows’=>3]);
文件上传:fileInput();
提交按钮:submitButton();
重置按钮:resetButtun();
以下是代码示例:
<?php $form = ActiveForm::begin(['action' => ['test/getpost'],'method'=>'post',]); ?> <? echo $form->field($model, 'username')->textInput(['maxlength' => 20]) ?> <? echo $form->field($model, 'password')->passwordInput(['maxlength' => 20]) ?> <? echo $form->field($model, 'sex')->radioList(['1'=>'男','0'=>'女']) ?> <? echo $form->field($model, 'edu')->dropDownList(['1'=>'大学','2'=>'高中','3'=>'初中'], ['prompt'=>'请选择','style'=>'width:120px']) ?> <? echo $form->field($model, 'file')->fileInput() ?> <? echo $form->field($model, 'hobby')->checkboxList(['0'=>'篮球','1'=>'足球','2'=>'羽毛球','3'=>'乒乓球']) ?> <? echo $form->field($model, 'info')->textarea(['rows'=>3]) ?> <? echo $form->field($model, 'userid')->hiddenInput(['value'=>3]) ?> <? echo Html::submitButton('提交', ['class'=>'btn btn-primary','name' =>'submit-button']) ?> <? echo Html::resetButton('重置', ['class'=>'btn btn-primary','name' =>'submit-button']) ?> <?php ActiveForm::end(); ?>
以上就是本章所有内容,希望会给大家带来帮助。
相关推荐:
以上是Yii框架中的form表单的详细内容。更多信息请关注PHP中文网其他相关文章!

tomakephpapplicationsfaster,关注台词:1)useopcodeCachingLikeLikeLikeLikeLikePachetoStorePreciledScompiledScriptbyTecode.2)MinimimiedAtabaseSqueriSegrieSqueriSegeriSybysequeryCachingandeffeftExting.3)Leveragephp7 leveragephp7 leveragephp7 leveragephpphp7功能forbettercodeefficy.4)

到ImprovephPapplicationspeed,关注台词:1)启用opcodeCachingwithapCutoredUcescriptexecutiontime.2)实现databasequerycachingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandredececonnection.4 limitsclection.4.4

依赖注入(DI)通过显式传递依赖关系,显着提升了PHP代码的可测试性。 1)DI解耦类与具体实现,使测试和维护更灵活。 2)三种类型中,构造函数注入明确表达依赖,保持状态一致。 3)使用DI容器管理复杂依赖,提升代码质量和开发效率。

databasequeryOptimizationinphpinvolVolVOLVESEVERSEVERSTRATEMIESOENHANCEPERANCE.1)SELECTONLYNLYNESSERSAYCOLUMNSTORMONTOUMTOUNSOUDSATATATATATATATATATATRANSFER.3)

phpisusedforsenderemailsduetoitsbuilt-inmail()函数andsupportiveLibrariesLikePhpMailerandSwiftMailer.1)usethemail()functionforbasicemails,butithasimails.2)butithasimimitations.2)

PHP性能瓶颈可以通过以下步骤解决:1)使用Xdebug或Blackfire进行性能分析,找出问题所在;2)优化数据库查询并使用缓存,如APCu;3)使用array_filter等高效函数优化数组操作;4)配置OPcache进行字节码缓存;5)优化前端,如减少HTTP请求和优化图片;6)持续监控和优化性能。通过这些方法,可以显着提升PHP应用的性能。

依赖性注射(DI)InphpisadesignPatternthatManages和ReducesClassDeptions,增强量产生性,可验证性和Maintainability.itallowspasspassingDepentenciesLikEdenceSeconnectionSeconnectionStoclasseconnectionStoclasseSasasasasareTers,interitationApertatingAeseritatingEaseTestingEasingEaseTeStingEasingAndScalability。

cachingimprovesphpermenceByStorcyResultSofComputationsorqucrouctationsorquctationsorquickretrieval,reducingServerLoadAndenHancingResponsetimes.feftectivestrategiesinclude:1)opcodecaching,whereStoresCompiledSinmememorytssinmemorytoskipcompliation; 2)datacaching datacachingsingMemccachingmcachingmcachings


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

禅工作室 13.0.1
功能强大的PHP集成开发环境

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器