konichiwa
(Amisam Sonpx)
August 17, 2009, 9:29am
1
I have a file controller
and a function CreateAction:
$model->t_datetime = new CDbException('NOW()');
$model->t_fees = 5;
if($model->save())
$connection = Yii::app()->db;
$transaction=$connection->beginTransaction();
try {
if(md5('pay')== $_GET['mod']){
Connection was declared (defined)
but when I submit then I have error:
PHP Error
Description
Undefined variable: connection
and IF I move: $connection = Yii::app()->db;
$model->t_datetime = new CDbException('NOW()');
$model->t_fees = 5;
$connection = Yii::app()->db;
if($model->save())
$transaction=$connection->beginTransaction();
try {
if(md5('pay')== $_GET['mod']){
then I got Message:
Undefined variable: transaction
error in lint 115:
00115: $transaction->rollBack();
How can i Solve it ?
Dave
(Deventer)
August 17, 2009, 9:35am
2
Take a look at your brackets.
It seems that $model->save() fails and as a result the connection variable will not be initialized. You skipped the brackets which means that only the next line following the if statement will be enclosed. The line
$connection->beginTransaction();
will always be executed regardless if the save fails or not.
sluderitz
(Sluderitz)
August 17, 2009, 9:50am
3
You are using CDbException, I think you are trying to use CDbExpression?
CDbException != CDbExpression
konichiwa
(Amisam Sonpx)
August 17, 2009, 10:20am
4
Dave:
Take a look at your brackets.
It seems that $model->save() fails and as a result the connection variable will not be initialized. You skipped the brackets which means that only the next line following the if statement will be enclosed. The line
$connection->beginTransaction();
will always be executed regardless if the save fails or not.
Thanks u, I Solved it
but now I still have problem with FindbyA…
$requestuid = Users::model()->findAllByAttributes(array('id'=>Yii::app()->user->id));
echo $requestuid->balance;
I want to get balance money, but when I execute then I got the message:
PHP Error
Description
Trying to get property of non-object
00072: echo $requestuid->u_balance;
What can I do ?
Dave
(Deventer)
August 17, 2009, 11:04am
5
FindAll always returns an array. If you want to retrieve a single object use "findByAttributes" instead of "findAllByAttributes"