dpqaaczn141761 2014-03-17 12:38
浏览 24
已采纳

访问yii应用程序中表单的文本字段中的用户名(使用yii用户管理模块)

I am using User_Management_Module_0.4 in my yii app.

I have a model business to store users business in table.

table having fields username( I need same user name which is stored in users table which is of user management module)

in my _form.php I try to get the username of loged in user but its not working.

whats wrong in my code?? please tell me _form.php

<div class="form">

<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'shops-form',
'type'=>'horizontal',
'enableClientValidation'=>false,
'enableAjaxValidation'=>false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>

<p class="note">Fields with <span class="required">*</span> are required.</p>




<div class="row">

    <?php echo $form->textFieldRow($model,'name',$model->getUserOptions()); ?>
</div>

business.php (model)

public function getUserOptions()
{$username = Yii::t("UserModule.user", "username");

    //$uname =Yii::app()->user->username;

    return $username;


}
  • 写回答

1条回答 默认 最新

  • douyi8732 2014-03-17 12:56
    关注

    You're using an ActiveForm. If you look at the documentation at http://www.yiiframework.com/doc/api/1.1/CActiveForm#textField-detail, you can see that the third param are the html options.

    If you want the username of logged user into the field, you can set the attribute $model->name = Yii::app()->user->name or your custom function $model->name = $model->getUserOptions(); into your controller that renders the view with the form.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)