简体   繁体   中英

access a data from model table in yii

i have a database 'example_data'.In that database i have 3 table 'user' 'fetch' and 'pages'.

in the _from of fetch class, i have to fetch of user name from the user table. it means when a user is created. the user have to create a 'fetch' page. In the creation form of 'fetch' page first it should be fetch the perticular user name ,which user is creating a 'fetch' page.

here is the code of _form

<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
  'id'=>'wireframes-form',
  'enableAjaxValidation'=>false,
)); ?>
  <?php echo Yii::app()->request->getUrl(); ?>
  <p class="note">Fields with <span class="required">*</span> are required.</p>
  <?php echo $form->errorSummary($model); ?>

  <div class="row">
    <?php echo $form->labelEx($model,'user_id'); ?>
    <?php echo $form->textField($model,'user_id'); ?>
    <?php echo $form->error($model,'user_id'); ?>
  </div>

in that form how i can fetch the name of user.

Usually, you can use

Yii::app()->user->id

to get the user identity id (from PHP session). The user identity id is usually the id of the user model (set as primary key). Finally, you can get the user model data with it, like

$current_user = User::model()->findByPk(Yii::app()->user->id);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM