这是我的控制器,我正在尝试从我的数据库字段中获取类别ID和专业知识数据。一切正常,但问题是我没有获得类别ID。当我尝试在视图控制器上打印所有记录时,会出现问题。这是我的代码$cat_id =Yii::$app->request->get('categori_id');
的一部分。
//start premium adviser section
public function actionPremiumsearch()
{
if(isset($_GET['login-button1']))
{
$model=new UserDetail();
$request = Yii::$app->request;
$post = $request->get();
$cat_id =Yii::$app->request->get('categori_id');
//var_dump($cat_id);exit;
//print_r($cat_id);exit;
$expertise =Yii::$app->request->get('expertise');
//print_r($expertise);exit;
//var_dump($cat_id);exit;
//$cat = $request->cat_id();
//echo $cat;
//print_r($post);
//$cat_id = $request->get('categori_id');
//echo $cat_id;
//$cat_id = $post['categories']['categori_id'];
//echo $cat_id;exit;
//print_r($cat_id);exit;
//print_r($post);
//$cat_id = $post['categori_id'];
//print_r($cat_id);
//$service_id = $post['Service']['id'];
//echo $service_id.' '.$expertise.' '.$cat_id;
//exit;
//echo "button1";
$query = new Query;
// compose the query
$query->select('kpt_users.*,kpt_user_details.*,kpt_user_services.*')
->from('kpt_users')
->join( 'INNER JOIN',
'kpt_user_details',
'kpt_user_details.user_id =kpt_users.id'
)
->join( 'LEFT JOIN',
'kpt_user_services',
'kpt_user_services.user_id= kpt_users.id'
)
//->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_services.service_id'=>$service_id])
->Where('kpt_users.status = 1')
->andWhere('kpt_users.user_role_id = 2')
//->andFilterWhere(['like', 'kpt_user_services.service_id', $this->service_id])
//->andFilterWhere(['like', 'kpt_user_details.categori_id', $this->categori_id])
//->andFilterWhere(['like', 'kpt_user_details.expertise', $this->expertise])
//->andWhere(['like', 'kpt_user_services.service_id', $service_id])
//->andWhere(['like', 'kpt_user_details.categori_id', $categori_id])
// ->andWhere(['like', 'kpt_user_details.expertise', $expertise])
//->andWhere('kpt_user_details = 2')
//->andWhere(['like', 'categori_id', $cat_id])
//->andWhere(['like', 'name', 'alex'])
//->andWhere(['like','kpt_user_services.service_id'=>$service_id,'kpt_user_details.categori_id'=>$cat_id])
->limit(2);
// build and execute the query
$rows = $query->all();
//var_dump($rows);exit;
return $this->render('personalinsurance', [
'result' => $rows,
'model' => $model,
]);
}
if(isset($_GET['login-button2'])){
//echo "kanak";
//echo "button1";
$query = new Query;
// compose the query
$query->select('kpt_users.*,kpt_user_details.*,kpt_user_services.*')
->from('kpt_users')
->join( 'INNER JOIN',
'kpt_user_details',
'kpt_user_details.user_id =kpt_users.id'
)
->join( 'LEFT JOIN',
'kpt_user_services',
'kpt_user_services.user_id= kpt_users.id'
)
//->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_services.service_id'=>$service_id])
->limit(4);
// build and execute the query
$rows = $query->all();
//var_dump($rows);exit;
return $this->render('corporateinsurance', [
'result' => $rows,
]);
}
if(isset($_GET['login-button3'])){
//echo "kanak3";
//echo "button1";
$query = new Query;
// compose the query
$query->select('kpt_users.*,kpt_user_details.*,kpt_user_services.*')
->from('kpt_users')
->join( 'INNER JOIN',
'kpt_user_details',
'kpt_user_details.user_id =kpt_users.id'
)
->join( 'LEFT JOIN',
'kpt_user_services',
'kpt_user_services.user_id= kpt_users.id'
)
//->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_services.service_id'=>$service_id])
->limit(4);
// build and execute the query
$rows = $query->all();
//var_dump($rows);exit;
return $this->render('sbasedplanning', [
'result' => $rows,
]);
}
if(isset($_GET['login-button4'])){
// echo "kanak4";
//echo "button1";
$query = new Query;
// compose the query
$query->select('kpt_users.*,kpt_user_details.*,kpt_user_services.*')
->from('kpt_users')
->join( 'INNER JOIN',
'kpt_user_details',
'kpt_user_details.user_id =kpt_users.id'
)
->join( 'LEFT JOIN',
'kpt_user_services',
'kpt_user_services.user_id= kpt_users.id'
)
//->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_services.service_id'=>$service_id])
->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_details.categori_id'=>$category_id])
->limit(4);
// build and execute the query
$rows = $query->all();
//var_dump($rows);exit;
return $this->render('taxplanning', [
'result' => $rows,
]);
}
}
这是我的视图控制器,带有foreach
- 循环。当我尝试打印记录时,缺少类别ID。如何使用类别ID获取所有数据?
<?php foreach ($result as $rows):
$path = Yii::$app->params['imagePath'];
// print_r ($rows);exit;
?>
<?php $first_name = $rows['first_name'];
//echo $first_name;exit;
$agency_name = $rows['agency_name'];
$seller_name = $rows['seller_name'];
$reff_no = $rows['reff_no'];
$credentials = $rows['credentials'];
$photo = $rows['photo'];
$contact = $rows['contact'];
//echo $contact;exit;
$year_exp = $rows['year_exp'];
$expertise = $rows['expertise'];
$gender = $rows['gender'];
$title = $rows['title'];
$rnf = $rows['reff_no'];
$user_name = $rows['user_name'];
$user_email = $rows['user_email'];
$first_name = $rows['first_name'];
$user_id = $rows['user_id'];
$user_role_id = $rows['user_role_id'];
$service_id1 = $rows['service_id'];
//print_r( $service_id1);
// $service_name = $rows['service_name'];
$credentials = $rows['credentials'];
//echo "User Name: {$user_name}" . "<br>";
//echo "Ratings: {$rating}" . "<br>";
// echo "RNF: {$reff_no}" . "<br>";
//echo "Service Name: {$title}" . "<br>";
//echo "Service id: {$service_id}" . "<br>";
//echo "user role id: {$user_role_id}" . "<br>";
?>
<div class="parent">
<div class="col-lg-12 no-padding">
<div class="col-lg-6">
<div class="big-image">
<?php if($rows['photo']){ ?>
<img src=<?php echo $path; ?><?php echo $rows['photo']; ?> />
<?php } else { ?>
<?php echo Html::img('@web/images/banner/product-main.png'); ?>
<?php } ?>
<?php //echo Html::img('@web/images/banner/product-main.png'); ?></div>
</div>
<div class="col-lg-6">
<div class="product-name">
<h2><?php //echo $first_name?></h2>
<h2><a target="_blank" href="index.php?r=userslisting/user&id=<?php echo $rows['user_id']; ?>"><?php echo $rows['first_name'];?></a> </h2>
</div>
<div class="rating-point">
<p>Reating 4.5/5</p>
</div>
<div class="star">
<span><?php echo Html::img('@web/images/banner/star-full.png'); ?></span>
<span><?php echo Html::img('@web/images/banner/star-full.png'); ?></span>
<span><?php echo Html::img('@web/images/banner/star-full.png'); ?></span>
<span><?php echo Html::img('@web/images/banner/star-hafe.png'); ?></span>
<span><?php echo Html::img('@web/images/banner/star-0.png'); ?></span>
</div>
<div class="rating-point rnf">
<p class="pro-title">RNF</p>
<p class="pro-head-1"><?php echo $rnf?></p>
</div>
<div class="rating-point rank">
<p class="pro-title">Rank/Title</p>
<p class="pro-head-1"><?php echo $title?></p>
</div>
<div class="rating-point ss">
<p class="pro-title">service specialzation</p>
<p class="pro-head-1"><?php echo $expertise?></p>
</div>
<div class="rating-point creden">
<p class="pro-title">Credentials</p>
<p class="pro-head-1"><?php echo $credentials ?></p>
</div>
<div class="rating-point yoe">
<p class="pro-title">Years OF Experience</p>
<p class="pro-head-1"><?php echo $year_exp ?></p>
</div>
<div class="rating-point mail">
<p class="pro-title">Email</p>
<p class="pro-head-1"><?php echo $user_email; ?></p>
</div>
<div class="view-more">
<input type="button" class="btn btn-primary serch-select view-more" value="ENQUIRE" name="ENQUIRE">
<div class="enquiry">
<?php if (Yii::$app->session->hasFlash('contactFormSubmitted')): ?>
<div class="alert alert-success">
Thank you for contacting us. We will respond to you as soon as possible.
</div>
<?php else: ?>
<form id="contact-form" action="" method="post" role="form">
<div class="form-group">
<div class="col-lg-12 no-padding">
<div class="name-1"><input type="text" name="name" class="form-control transparent" value="" placeholder="Name" required> </div>
<div class="contact-1"><input type="text" name="contact" class="form-control transparent" value="" placeholder="Contact No." required> </div>
</div>
</div>
<div class="form-group">
<div class="col-lg-12 no-padding">
<div class="email-1"><input type="email" name="email" class="form-control transparent" value="" placeholder="Email" required> </div>
<div class="subject-1"><input type="text" name="subject" class="form-control transparent" value="" placeholder="Subject" required></div>
</div>
</div>
<div class="form-group"><textarea name="message" class="form-control" rows="6" placeholder="Message"></textarea></div>
<input id="form-token" type="hidden" name="<?=Yii::$app->request->csrfParam?>"
value="<?=Yii::$app->request->csrfToken?>"/>
<div class="form-group submit-button">
<input type="hidden" name="user_id" value="<?php echo $rows['user_id']; ?>" />
<input type="hidden" name="user_name" value="<?php echo $rows['first_name'].' '.$rows['last_name']; ?>" />
<input type="hidden" name="user_email" value="<?php echo $rows['user_email']; ?>" />
<input type="submit" class="btn btn-primary" name="contact-button">
</div>
</form>
<?php endif; ?>
</div>
</div>
</div>
</div>
<div class="clear"></div>
<?php endforeach; ?>
这是我的表格
<div class="serch-select-premium">
<?php $form = ActiveForm::begin(['action' =>['site/premiumsearch'], 'id' => '', 'method' => 'get',]); ?>
<?= $form->field($model, 'type_a_keyword')->textInput(['maxlength' => true, 'placeholder' => "Type a keyword"])->label(false); ?>
<?= Html::submitButton('Personal Insurance', ['class' => '','id' => 'personalinsurance', 'name' => 'login-button1']) ?>
<?= Html::submitButton('Corporate Insurance', ['class' => '','id' => 'corporateinsurance', 'name' => 'login-button2']) ?>
<?= Html::submitButton('Solution Based Planning', ['class' => '', 'id' => 'sbasedplanning','name' => 'login-button3']) ?>
<?= Html::submitButton('Tax Planning', ['class' => '','id' => 'taxplanning', 'name' => 'login-button4']) ?>
<?php ActiveForm::end(); ?>
</div>