How to work two views with the same model or two models with the same table?

I need to create two forms, customer and employee all have the same data and I just wanted to do the same table for both, my table is called person. How do I use the same model twice? or How to create two views at the same model? How Phalcon I would help me work?



60.8k
edited Nov '15

models/Customers.php

class Customers extends Model {
    function getSource(){
        return 'person';
}

models/Employee.php

class Employee extends Model {
    function getSource(){
        return 'person';
    }
}

However this seems wrong, you should have 1 model per table, i dont see how making 2 mdoels of a same table can be worth it.

$customer = new Models/Customer();
$cutomer->is_employee = 1;
$cusotmer->save();

$next_customer = new Models/Customer();
$cutomer->is_employee = 0;
//create a basket id or whatever

$customer->save();

?

//edit

How to create two views at the same model

inside the controller action you can do

public function indexAction(){
    $this->view->pick('index/customer');
    //or
    $this->view->pick('common/employee')
    ...
    //you get the idea
}

https://docs.phalconphp.com/en/latest/reference/views.html#picking-views