Yii Framework Forum: Form without DB - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Form without DB Rate Topic: -----

#1 User is offline   Hallaj 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 14-March 10

Posted 11 April 2010 - 06:42 AM

Hello all. I'm sorry if this has been asked before but how do I actually get a workaround to post/process something with a form's input without using a database. I'm relatively new to this PHP Framework world so I'm sorry if I was supposed to see it somewhere but I didn't.

e.g: Form requests for user for an input of number. Then the number is passed to a calculator class and displays the result?

Thanks in advance :)
0

#2 User is offline   frantic 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 172
  • Joined: 01-March 10
  • Location:Saint-Petersburg

Posted 11 April 2010 - 07:53 AM

The form with DB are inherited the CActiveRecord class, but only for form creation and checking the results you may use CFormModel class. Open the ContactForm.php model in blog example and you will see how it works
0

#3 User is offline   Hallaj 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 14-March 10

Posted 11 April 2010 - 08:15 AM

Alright. Thanks a lot. I guess I missed the 'setFlash' part. I was just curious since I'll be performing the actions based from a different class and wasn't quite sure how to pass it back to the form as a result (below it, etc). I guess I'll look at 'setFlash' for now. Thanks again :)
0

#4 User is offline   frantic 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 172
  • Joined: 01-March 10
  • Location:Saint-Petersburg

Posted 11 April 2010 - 08:21 AM

It's quite simple. In your controller you should write:
Yii::app()->user->setFlash('flashname','Data was saved successfully');


And in your view:
<?php if(Yii::app()->user->hasFlash('flashname')): ?>
	<div class="flash-success">
		<?php echo Yii::app()->user->getFlash('flashname'); ?>
	</div>
<?php endif; ?>

0

#5 User is offline   Hallaj 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 14-March 10

Posted 11 April 2010 - 09:53 AM

Yup. That's pretty much how I'm doing it now. Here's my current test code.

components/Calculator.php
class Calculator {
    public static function Add($number1, $number2)
    {
        return $number1+$number2;
    }
}


views/site/calculator.php
<?php if(Yii::app()->user->hasFlash('calculator')): ?>
    <div>
        <?php echo Yii::app()->user->getFlash('calculator'); ?>
    </div>
<?php endif; ?>


controller/SiteController.php
<?php
    Yii::app()->user->setFlash('calculator', Calculator::Add($this->number1, $this->number2));
?>


Again, thanks a lot for point this out :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users