first, I’m sorry for the strange topic title because of Idk what is the good title for this kind of question.
I have this situation, I need to check if the customer’s level is distributor then they’ll be given the price of distributor for items that they bought. and the same rule for retail level. I have this code :
Did you check if the $_POST[‘Penjualan’][‘id_item’] has the apropriate value?
also check if the ‘level_harga’ field has ‘distributor’ value and same value on id_item field with above POST value in the same record of your database
and somehow it works ! I’m not really sure what’s make it work anyway if you masters knows, please tell me what makes this code working. thanks a lot !
Something doesn’t seem right there. findByAttributes() should only be returning a single instance of your Harga model, so you shouldn’t be able to successfully iterate over it using foreach. Maybe I’m missing something obvious.
public function actionTest()
{
$users = User::model()->findByAttributes(array('id'=>1));
foreach ($users as $user)
echo $user->id;
}
Running this produces the PHP notice "Trying to get property of non-object" on the echo line.
If I disable error reporting, nothing is output.
Clearly iterating over a model instance is not supported in my version of PHP. I suspect that either the code that’s been posted above is not the same as the code that is actually running, or something else is happening which is masking this issue.
Exactly. If you are not sure when the code is running correctly you could use foreach when use findAllByAttributes. In other case use directly the $harganya->harga;