나는 드롭 다운 목록에서 선택한 값을 CActiveForm에서 선택한 다음 제출 한 후 로직을 수행하여 쿼리를 실행하려고합니다. 이 쿼리를 기반으로 gridview를 업데이트합니다. 이 폼은 관련된 테이블의 속성을 가지고 있지는 않지만 그 이상의 것들이 있기 때문에 어떤 로직이 끝나면 GridView를위한 필터를 만들 수 있습니다.Yii dropDownList - 선택된 항목에 대한 로직을 수행 할 위치
어디에서이 논리를 수행합니까? 나는 php, yii 및 javascript에 익숙하지 않으므로 적어도 올바른 방향으로 나를 가리켜 주시면 감사하겠습니다. 나는 yii 문서와 책을 보려고했지만 내가 필요한 것을 찾지 못했습니다. 난 뭔가 PHP와 웹 dev에 뭔가가 너무 사소한 드롭에 붙어 붙어에서 중요하지 않은 것 같아요.
이는 renderPartial
<?php
/* @var $this UserController */
/* @var $model User */
$this->breadcrumbs=array(
'Manage Users',
);
/*$this->menu=array(
array('label'=>'List User', 'url'=>array('index')),
array('label'=>'Create User', 'url'=>array('create')),
);
*/
Yii::app()->clientScript->registerScript('search', "
$('.asearch-button').click(function(){
$('.asearch-form').toggle();
$('.bsearch-form').toggle();
return false;
});
$('.bsearch-button').click(function(){
$('.bsearch-form').toggle();
$('.asearch-form').toggle();
return false;
});
$('.bsearch-form form').submit(function(){
$('#user-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
$('.asearch-form form').submit(function(){
$('#user-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<h2>Manage Users</h2>
<?php echo CHtml::link('Basic Search','#',array('class'=>'bsearch-button')); ?>
<br/>
<!-- basic search-form -->
<div class="bsearch-form" style="display:">
<?php $this->renderPartial('search',array('model'=>$model)); ?>
</div>
<?php echo CHtml::link('Advanced Search','#',array('class'=>'asearch-button')); ?>
<!-- advanced search-form -->
<div class="asearch-form" style="display:none">
<?php $this->renderPartial('advanced_search',array('model'=>$model)); ?>
</div>
<?php $this->widget('bootstrap.widgets.TbGridView', array(
'type'=>'striped condensed hover',
'id'=>'user-grid',
'selectableRows'=>1,
'selectionChanged'=>
'function(id){ location.href = $.fn.yiiGridView.getSelection(id);}',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'username',
'email',
'fname',
'lname',
array(
'name' => 'combineRoles',
'value' => '($data->getCombineRoles())',
'header'=> CHtml::encode($model->getAttributeLabel('combineRoles')),
//'filter'=> CHtml::activeTextField($model, 'combineRoles'),
),
)));
?>
내 advanced_search.php하여 advanced_search.php 양식을 호출 admin.php 내이다
<?php
/* @var $this UserController */
/* @var $model User */
/* @var $form CActiveForm */
?>
<div class="wide form">
<?php $form = $this->beginWidget('CActiveForm', array(
'action' => Yii::app()->createUrl($this->route),
'method' => 'get',
)); ?>
<?php
$dataRole = array('Project Mentor', 'Personal Mentor', 'Domain Mentor', 'Mentee');
$dataRoleVal = array(0,1,2,3);
echo $form->dropDownList($model, 'firstField', array_combine($dataRoleVal, $dataRole),
array('style' => ''));
echo $form->dropDownList($model, 'criteria', array('Exactly', 'Greater Than',
'Less Than'), array('style' => ''));
echo $form->textField($model, 'quantity', array('hint'=>'', 'style' => ''));
$data = array('Enabled', 'Disabled');
$data1 = array(0,1);
echo $form->dropDownList($model, 'disable', array_combine($data1, $data), array('style' => ''));
?>
<?php echo CHtml::submitButton('Search', array("class" => "btn btn-primary")); ?>
<?php $this->endWidget(); ?>
<!-- search-form -->
</div>
내 UserController.php
public function actionAdmin()
{
echo("<script>console.log('actionAdmin');</script>");
$model=new User('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['User'])){
$model->attributes=$_GET['User'];
}
$this->render('admin',array(
'model'=>$model,
));
}
업데이트 : 요청하신대로 내 모델 User.php
<?php
/**
* This is the model class for table "user".
*
* The followings are the available columns in table 'user':
* @property string $id
* @property string $username
* @property string $password
* @property string $email
* @property string $fname
* @property string $mname
* @property string $lname
* @property string $pic_url
* @property integer $activated
* @property string $activation_chain
* @property integer $disable
* @property string $biography
* @property string $linkedin_id
* @property string $fiucs_id
* @property string $google_id
* @property integer $isAdmin
* @property integer $isProMentor
* @property integer $isPerMentor
* @property integer $isDomMentor
* @property integer $isStudent
* @property integer $isMentee
* @property integer $isJudge
* @property integer $isEmployer
*
* The followings are the available model relations:
* @property Administrator $administrator
* @property DomainMentor $domainMentor
* @property Mentee $mentee
* @property Message[] $messages
* @property Message[] $messages1
* @property PersonalMentor $personalMentor
* @property ProjectMentor $projectMentor
* @property Ticket[] $tickets
* @property Ticket[] $tickets1
* @property Domain[] $domains
*/
class User extends CActiveRecord
{
public $password2;
public $vjf_role;
public $men_role;
public $rmj_role;
/* advanced search variables */
public $firstField;
public $quantity;
public $criteria;
/*assign variables */
public $userDomain;
public $userId;
/*temporary variables currently not stored in db*/
public $employer;
public $position;
public $start_year;
public $degree;
public $field_of_study;
public $school;
public $graduation_year;
public $combineRoles;
/*Change the value when the system is deploy */
public static $admin = 5;
/* The most expert in the Domain */
public static $condition = 8;
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return User the static model class
*/
public static function model($className = __CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'user';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('username, password, password2, email, fname, lname', 'required'),
array('activated, disable, isAdmin, isProMentor, isPerMentor, isDomMentor, isStudent, isMentee, isJudge, isEmployer', 'numerical', 'integerOnly' => true),
array('username, fname, mname, activation_chain, linkedin_id, fiucs_id, google_id', 'length', 'max' => 45),
array('password, email, pic_url', 'length', 'max' => 255),
array('lname', 'length', 'max' => 100),
array('biography', 'length', 'max' => 500),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, username, password, email, fname, mname, lname, pic_url, activated, activation_chain, disable, biography, linkedin_id, fiucs_id, google_id, isAdmin, isProMentor, isPerMentor, isDomMentor, isStudent, isMentee, isJudge, isEmployer', 'safe', 'on' => 'search'),
);
}
public function validatePassword($password)
{
$hasher = new PasswordHash(8, false);
return $hasher->CheckPassword($password, $this->password);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'administrator' => array(self::HAS_ONE, 'Administrator', 'user_id'),
'domainMentor' => array(self::HAS_ONE, 'DomainMentor', 'user_id'),
'mentee' => array(self::HAS_ONE, 'Mentee', 'user_id'),
'messages' => array(self::HAS_MANY, 'Message', 'receiver'),
'messages1' => array(self::HAS_MANY, 'Message', 'sender'),
'personalMentor' => array(self::HAS_ONE, 'PersonalMentor', 'user_id'),
'projectMentor' => array(self::HAS_ONE, 'ProjectMentor', 'user_id'),
'tickets' => array(self::HAS_MANY, 'Ticket', 'assign_user_id'),
'tickets1' => array(self::HAS_MANY, 'Ticket', 'creator_user_id'),
'domains' => array(self::MANY_MANY, 'Domain', 'user_domain(user_id, domain_id)'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'User ID',
'username' => 'User Name',
'password' => 'Password',
'password2' => 'Re-type Password',
'email' => 'e-mail',
'fname' => 'First Name',
'mname' => 'Middle Name',
'lname' => 'Last Name',
'pic_url' => 'Pic Url',
'activated' => 'Activated',
'activation_chain' => 'Activation Chain',
'disable' => 'Disabled',
'biography' => 'Biography',
'linkedin_id' => 'Linkedin',
'fiucs_id' => 'Fiucs',
'google_id' => 'Google',
'isAdmin' => 'Administrator',
'isProMentor' => 'Project Mentor',
'isPerMentor' => 'Personal Mentor',
'isDomMentor' => 'Domain Mentor',
'isStudent' => 'Student',
'isMentee' => 'Mentee',
'isJudge' => 'Judge',
'isEmployer' => 'Employer',
'vjf_role' => 'Virtual Job Fair Roles:',
'men_role' => 'Mentoring Platform Roles:',
'rmj_role' => 'Remote Mobil Judge Roles:',
'employer' => 'Current Employer',
'position' => 'Position',
'start_year' => 'Start Year',
'degree' => 'Highest Degree',
'field_of_study' => 'Field of Study',
'school' => 'University',
'graduation_year' => 'Graduation Year',
'rmj_role' => 'Remote Mobil Judge Roles:',
'firstField' => 'Type: ',
'criteria' => 'Assigned to: ',
'quantity' => 'projects, mentors, or mentees',
'combineRoles' => 'Roles',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
if ($this->firstField === 0) {
$this->isProMentor = 1;
} else if ($this->firstField === 1) {
$this->isPerMentor = 1;
} else if ($this->firstField === 2) {
$this->isDomMentor = 1;
} else if ($this->firstField === 3) {
$this->isMentee = 1;
}
$criteria = new CDbCriteria;
//$criteria->compare('id', $this->id, true);
$criteria->compare('username', $this->username, true);
//$criteria->compare('password',$this->password,true);
$criteria->compare('email', $this->email, true);
$criteria->compare('fname', $this->fname, true);
//$criteria->compare('mname', $this->mname, true);
$criteria->compare('lname', $this->lname, true);
//$criteria->compare('pic_url',$this->pic_url,true);
$criteria->compare('activated', $this->activated);
//$criteria->compare('activation_chain',$this->activation_chain,true);
$criteria->compare('disable', $this->disable);
//$criteria->compare('biography',$this->biography,true);
//$criteria->compare('linkedin_id',$this->linkedin_id,true);
//$criteria->compare('fiucs_id',$this->fiucs_id,true);
//$criteria->compare('google_id',$this->google_id,true);
//$criteria->compare('isAdmin', $this->isAdmin);
$criteria->compare('isProMentor', $this->isProMentor);
$criteria->compare('isPerMentor', $this->isPerMentor);
$criteria->compare('isDomMentor', $this->isDomMentor);
$criteria->compare('isStudent', $this->isStudent);
$criteria->compare('isMentee', $this->isMentee);
//$criteria->compare('isJudge', $this->isJudge);
//$criteria->compare('isEmployer', $this->isEmployer);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
public function getCombineRoles(){
$st = '';
if ($this->isProMentor)
$st .= 'Project ';
if ($this->isPerMentor)
$st .= 'Personal ';
if ($this->isDomMentor)
$st .= 'Domain ';
if ($this->isMentee)
$st .= 'Mentee';
return $st;
}
/* retrieve all user ids in the system */
public static function getAllUserId()
{
$userid = User::model()->findBySql("SELECT id from user, user_domain WHERE ");
return $userid;
}
public static function getCurrentUser()
{
$username = Yii::app()->user->name;
$user = User::model()->find("username=:username", array(':username' => $username));
return $user;
}
public static function getCurrentUserId()
{
$username = Yii::app()->user->name;
$user = User::model()->find("username=:username", array(':username' => $username));
if ($user == null) { Yii::app()->getController()->redirect('/coplat/index.php/site/login'); }
return $user->id;
}
public static function getUser($userid)
{
$user = User::model()->findByPk($userid);
return $user;
}
public static function getUserName($userid)
{
$user = User::model()->findByPk($userid);
return $user->username;
}
public function isAdmin()
{
return $this->isAdmin;
}
public function isProMentor()
{
return $this->isProMentor;
}
public function isPerMentor()
{
return $this->isPerMentor;
}
public function isDomMentor()
{
return $this->isDomMentor;
}
public function isMentee()
{
return $this->isMentee;
}
public function isJudge()
{
return $this->isJudge;
}
public function isEmployer()
{
return $this->isEmployer;
}
public function isStudent()
{
return $this->isStudent;
}
public static function isCurrentUserAdmin()
{
$username = Yii::app()->user->name;
$user = User::model()->find("username=:username", array(':username' => $username));
if ($user == null)
return false;
return $user->isAdmin;
}
public static function isCurrentUserMentee()
{
$username = Yii::app()->user->name;
$user = User::model()->find("username=:username", array(':username' => $username));
if ($user == null)
return false;
return $user->isMentee;
}
public static function isCurrentUserProMentor()
{
$username = Yii::app()->user->name;
$user = User::model()->find("username=:username", array(':username' => $username));
if ($user == null)
return false;
return $user->isProMentor;
}
public static function isCurrentUserDomMentor()
{
$username = Yii::app()->user->name;
$user = User::model()->find("username=:username", array(':username' => $username));
if ($user == null)
return false;
return $user->isDomMentor;
}
public static function isCurrentUserPerMentor()
{
$username = Yii::app()->user->name;
$user = User::model()->find("username=:username", array(':username' => $username));
if ($user == null)
return false;
return $user->isPerMentor;
}
public static function isCurrentUserJudge()
{
$username = Yii::app()->user->name;
$user = User::model()->find("username=:username", array(':username' => $username));
if ($user == null)
return false;
return $user->isJudge;
}
public static function isCurrentUserEmployer()
{
$username = Yii::app()->user->name;
$user = User::model()->find("username=:username", array(':username' => $username));
if ($user == null)
return false;
return $user->isEmployer;
}
public static function isCurrentUserStudent()
{
$username = Yii::app()->user->name;
$user = User::model()->find("username=:username", array(':username' => $username));
if ($user == null)
return false;
return $user->isStudent;
}
전체 모델 User.php를 붙여 모델 파일 (보호/모델/User.php) 코드를 붙여'공공 기능 검색() {}'모습을 촬영 – Athipatla
@Athipatla 감사합니다. 나는 검색 기능을 보여줄 수있는 게시물을 업데이트했다. – jsan