NanoMVC

Extending

Custom Controller, Model, or View

NanoMVC allows you to easily extend core classes like NanoMVC_Controller, NanoMVC_Model, or NanoMVC_View to add your own logic and base functionality.

Extending NanoMVC_Controller

Create your custom controller base class inside the /myapp/plugins/ directory:

// File: /myapp/plugins/my_controller.php

class My_Controller extends NanoMVC_Controller {
  // Add your common controller logic here
}

Now in your controllers, extend My_Controller instead of NanoMVC_Controller:

// File: /myapp/controllers/hello.php

class Hello_Controller extends My_Controller {
  function index() {
    $this->view->display('hello_view');
  }
}

Note: You do not need to manually include your custom base class. NanoMVC will autoload it automatically if it is placed in the plugins directory and named as classname.php.

Extending NanoMVC_Model or NanoMVC_View

The same process works for NanoMVC_Model and NanoMVC_View:

You can then use your extended versions in your application wherever needed.

← to Custom Database Plugin to Autoloading Plugins →

← Back to Documentation