action.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * This is the template for generating the action script for the form.
  4. * The following variables are available in this template:
  5. * - $modelClass: the model class name
  6. * - $viewName: the name of the view
  7. */
  8. ?>
  9. <?php
  10. $actionName=$modelClass;
  11. if(strrpos($modelClass,'Form')===strlen($modelClass)-4)
  12. $actionName=substr($modelClass,0,strlen($modelClass)-4);
  13. ?>
  14. public function action<?php echo $actionName; ?>()
  15. {
  16. $model=new <?php echo $modelClass; ?>;
  17. // uncomment the following code to enable ajax-based validation
  18. /*
  19. if(isset($_POST['ajax']) && $_POST['ajax']==='<?php echo $this->class2id($modelClass); ?>-form')
  20. {
  21. echo CActiveForm::validate($model);
  22. Yii::app()->end();
  23. }
  24. */
  25. if(isset($_POST['<?php echo $modelClass; ?>']))
  26. {
  27. $model->attributes=$_POST['<?php echo $modelClass; ?>'];
  28. if($model->validate())
  29. {
  30. // form inputs are valid, do something here
  31. return;
  32. }
  33. }
  34. $this->render('<?php echo $viewName; ?>',array('model'=>$model));
  35. }