Speed up development with full-stack environments for every branch.

Learn More

Working with forms in Yii [PHP]

1935 Runs 10304 Views 2853 Copies


cezary 46

published 4 years ago


// This is the main controller for the application
// A controller is a class that handles all the logic
class SiteController extends CController
	// Define an action. actionIndex is a default action
	public function actionIndex()
		// Load a model and a form
		$model = new Contact;
		$form = new CForm('application.views.site.contactForm', $model);
		// If form is submitted and data is correct...
		if($form->submitted('send') && $form->validate())
			// Save data and redirect to show what has been entered
			$model -> save();
			$this -> redirect(array('site/list'));
			// else, show the form again
			$this -> render('contact', array('form' => $form));
	public function actionList()
		$this -> render('list', array('data' => Contact::model()->findAll()));
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).