YII2 - Strange problem with html::checkbox

I have been banging my head on this odd problem for a while not, and figured it time for some more eyeballs on code…

I have two arrays. One that lists all products and one that associates those products with a Session.

I am trying to provide a list of all products with a checkmark to allow the user to associate that product with the session the page is dealing with. ( the sessionid is fixed ). Existing assocations should be displayed already checked…

the problem I am getting is that if any of them are associated, they all get a checkmark…

probably some dumb*** php mistake, but I sure don’t see it…



<?= Html::beginForm( '/admin/sessionproducts/save', 'post' ); ?>

	<div class="checkboxgroup">


			// loop through all products

			foreach( $products as $product )


				$sessionid = $session['sessionId'];

				$productid = $product['productId'];

				$id = 'Product' . $productid;

				$label = $product['name'];

				// set checkmark to 0, in case of no associations


				// loop through all associations ( if any ), and set selected if exists..

				foreach( $sessionproducts as $sessionproduct )


					if( $sessionproduct['sessionId'] = $sessionid )

						$checkmark = 1;


						$checkmark = 0;




					<?= Html::checkbox( $id, $checked = $checkmark, 

								$options = ['label' => $label, 'uncheck' => '0'] ); ?>






	<?= Html::submitButton( 'Update', ['class' => 'btn btn-success']) ?>

	<?= Html::a( 'Cancel', ['admin/sessionproducts'], ['class' => 'btn btn-default'])   ?>

<?= Html::endForm(); ?>

Elaborate please…

Ah, sorry.

You had to write

if( $sessionproduct['sessionId'] == $sessionid ) // comparing

instead of

if( $sessionproduct['sessionId'] = $sessionid ) // populating

:rolleyes: :rolleyes: :rolleyes:

You would think that 30+ years of writing C code would have trained me to always verify comparisons… Guess not… At least not in the wee hours…

"Five minutes of code check by someone else beats five hours with the debugger…"



I thought that good IDEs should be able to give warning to this kind of code.

But now I’ve found that my PHPStorm says nothing about it.