action.php 991 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * This is the template for generating the action script for the form.
  4. * - $this: the CrudCode object
  5. */
  6. ?>
  7. <?php
  8. $viewName=basename($this->viewName);
  9. ?>
  10. public function action<?php echo ucfirst(trim($viewName,'_')); ?>()
  11. {
  12. $model=new <?php echo $this->modelClass; ?><?php echo empty($this->scenario) ? '' : "('{$this->scenario}')"; ?>;
  13. // uncomment the following code to enable ajax-based validation
  14. /*
  15. if(isset($_POST['ajax']) && $_POST['ajax']==='<?php echo $this->class2id($this->modelClass); ?>-<?php echo $viewName; ?>-form')
  16. {
  17. echo CActiveForm::validate($model);
  18. Yii::app()->end();
  19. }
  20. */
  21. if(isset($_POST['<?php echo $this->modelClass; ?>']))
  22. {
  23. $model->attributes=$_POST['<?php echo $this->modelClass; ?>'];
  24. if($model->validate())
  25. {
  26. // form inputs are valid, do something here
  27. return;
  28. }
  29. }
  30. $this->render('<?php echo $viewName; ?>',array('model'=>$model));
  31. }