Spawn Framework · Contact · Community · Tutorial · Documentation · Download · About

Learn :: Model

In this lesson I show you how to use Model in project.

Model files we saved in /Application/Model/
Create now first model:
namespace Model;
class Hello
{
   public function say($name)
   {
       return 'Hello '.$name.'!';
   }
}
And use it!
namespace Controller;
class Home extends \Spawn\Controller
{   
   public function indexAction()
   {
       $hello = new \Model\Hello();
       $this -> response = $hello->say('Spawn');
   }
}
When we need create new dirs in /Application/Model/ , we must add this dir name to model namespace.
Example:
We create dir 'User' and new file in this dir: Admin.php.
If file name is Admin.php his model name and namespce id is:
//Model/User/Admin.php
namespace Model\User;
class Admin {}