Skip to content
saturngod edited this page Dec 4, 2012 · 6 revisions

Tutorial

Let start sample tutorial to understand routing system , Controller , Model and View.

  • Download the latest stable code.
  • unzip the folder
  • add all the files to your_localhost_path/ava

Config

config in system/config/development.php

change base_url and home_controller

const base_url="http://localhost/Ava";
const home_controller = 'home';

Create Controller

  • Delete all files in system/application/controller
  • Delete all files in system/application/model
  • Delete all files in system/application/view
  • Create home.php in system/application/controller

add following text in system/application/controller/home.php

<?php

class homeController extends Ava_Controller {
	
	function index()
	{
		
    }
}

Add Routing

<?php

class homeController extends Ava_Controller {
	
	function index()
	{
		$this->get_route("/","home");
		$this->get_route("/sample","sample");
		$this->get_route("/api/:id","api_testing");
		$this->get_route("/callback",function(){
                        echo "Closure";
		});
		$this->load->model('homeRouting');
		$this->run($this->homeRouting);
    }
}

Create Model at system/application/model/homeRouting.php

<?php
class homeRoutingModel extends Ava_Model {
	
	function home() {
		//home /
		$this->load->view('home');
	}

	function sample() {
		//sample /sample
		$this->load->view('sample');
	}
	
	function api_testing($params)
	{
		//use io library
		// header status is 200
		// if address is /api/1
		// params['id'] is 1
		
		$this->io->write(200,array("id"=>$params['id']));
	}
}

Create view at system/application/view/home.php and system/application/view/sample.php

home.php

<?php echo "HOME"; ?>

sample.php

<?php echo "sample"; ?>

Testing in browser

http://localhost/Ava/
http://localhost/Ava/home/sample

Tip

  • Controller and Model first character must be small letter
  • Controller class include [yourclassname]Controller (eg: userController , file name is user.php)
  • Model class include [yourclassname]Model (eg: userModel , file name is user.php)

Clone this wiki locally