appform / application / classes / controller / sample.php

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Sample extends Controller {

	public function action_index()
	{
		$this->request->response = '<h1>Hello, world!</h1>';
	}
	
	/**
	 * IMPORTANT: This is just sample code! It does not actually run. 
	 */   	
  public function action_edit($id = NULL) {
    // save the data
    if (!empty($_POST)) {
      // sample code paths for edit and create
      if(is_numeric($id)) {
        // EDIT: load the model with ID
        $model = ORM::factory('user', $id);
      } else {
        // CREATE: do not specify id
        $model = ORM::factory('user');
      }
      $model->values($_POST);
      // since we combine both editing and creating here we need a separate variable
      // you can get rid of it if your actions don't need to do that
      $result = false;
      if(is_numeric($id)) {
        // EDIT: check using alternative rules
        $result = $model->check();
      } else {
        // CREATE: check using default rules
        $result = $model->check_edit();
      }
      if($result) {
        // validation passed, save model
        $model->save();
      } else {
        // Get errors for display in view --> to AppForm
        // Note how the first param is the path to the message file (e.g. /messages/register.php)
				$content->set('errors', $model->validate()->errors('register'));
        // Pass on the old form values --> to AppForm                   
        $content->set('defaults', $_POST);        
      }
    }
  }
} 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.