您好,我的控制器
public function actionCreate()
{
$this->layout = "main";
$location = \Yii::$app->getRequest()->getCookies()->getValue( 'location_id' );
if ( $location != NULL )
{
$model = new ScreenTicketBooking();
if ( $model->load( Yii::$app->request->post() ) )
{
return $this->redirect( [ 'time', 'ids' => $model->show_date, 'id' => $model->movie_id ] );
}
else
{
return $this->render( 'create', [
'model' => $model,
] );
}
}
else
{
return $this->redirect( [ 'site/home' ] );
}
}
这是我的观点
<?php
use app\models\Locations;
use app\models\Movies;
use app\models\MovieShows;
use app\models\ScreenClasses;
use app\models\ScreenClassSeats;
use app\models\Screens;
use app\models\ScreenShowTimes;
use app\models\Theatres;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\ScreenTicketBooking */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="screen-ticket-booking-form col-md-4">
<?php $form = ActiveForm::begin(); ?>
<?php
$location = \Yii::$app->getRequest()->getCookies()->getValue( 'location_id' );
$movies = MovieShows::find()->where( [ 'location_id' => $location ] )->andWhere( [ '>', 'end_date',
date( 'Y-m-d' ) ] )->all();
if ( $movies != NULL )
{
foreach ( $movies as $movie )
{
$dataCategory[ ] = ArrayHelper::map( Movies::find()->where( 'status=:stat', [ 'stat' => 0 ] )
->andWhere( [ 'id' => $movie->movie_id ] )->all(), 'id',
'movie_name' );
}
}
else
{
$dataCategory = NULL;
}
$newArray = [ ];
if ( $movies != NULL )
{
foreach ( $dataCategory as $array )
{
foreach ( $array as $k => $v )
{
$newArray[ $k ] = $v;
}
}
}
echo $form->field( $model, 'movie_id' )->dropDownList( $newArray,
[ 'prompt' => '-Choose a Movie-',
'onchange' => '
$.get( "' . Url::toRoute( 'screenticketbooking/dependdrop' ) . '", { id: $(this).val() } )
.done(function( data )
{
$( "select#title" ).html( data );
});
' ] )->label( '' ); ?>
<?php $dataPost = ArrayHelper::map( MovieShows::find()
->where( 'movie_id=:mov_id', [ 'mov_id' => $model->movie_id ] )
->asArray()->all(), 'id', 'start_date' );
echo $T = $form->field( $model, 'show_date' )
->dropDownList(
$dataPost,
[ 'id' => 'title', 'prompt' => '-Select a Date-' ]
)->label( '' );
?>
<div class="form-group">
<?=
Html::submitButton( $model->isNewRecord ? Yii::t( 'app', 'OK' ) : Yii::t( 'app', 'Update' ),
[ 'name' => 'submit', 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary',
'id' => 'ajith' ] ) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
两者都完美无缺,但现在我想要的不是使用提交按钮,当选择了两个下拉菜单时,会自动重定向到操作时间。我正在使用双向依赖下拉列表。我怎么能做到这一点?
答案 0 :(得分:0)
试试这个。
<?php $dataPost = ArrayHelper::map( MovieShows::find()
->where( 'movie_id=:mov_id', [ 'mov_id' => $model->movie_id ] )
->asArray()->all(), 'id', 'start_date' );
echo $T = $form->field( $model, 'show_date' )
->dropDownList(
$dataPost,
[ 'id' => 'title', 'prompt' => '-Select a Date-', 'onchange' => 'this.form.submit()' ]
)->label( '' );
?>
在提交表单后选择'show_date'
时使用此功能。