I need to create multiple views of the same mode

I have a table or model Person objects originate suppliers, customers, employees, transportitas.

I would have to create more models, controllers or views with different names or you can use the same model, controller or view. In what way I proceed?



30.7k

Hi,

if you can alter the structure of ypur 'person" database table, just add a "type" field, where type = Supplier or Customer or Employee ...

you can then use the same controller and views.

First the router:

use Phalcon\Mvc\Router;

// Create the router
$router = new Router();

// Define a route
$router->add(
    "/:action/:type",
    array(
        "controller" => person,
        "action"     => 1,
        "type"     => 2
    )
);

The controller:

public function createAction()
    {
        $type = $this->request->get("type");
        //other stuff
        $this->view->type = $type;
        //other stuff
    }

The view:

<h1>Create new {{ type }}</h1>
//your form here where you will put an hidden field
{{ hiddenField(["type":type]) }}


34.1k

IF I could do that. But the forms have different options, and validation functions within it, in addition to design, that's why I would like to create different forms



30.7k

you can do that by using a "switch $type case ... " in controller and pick the right view https://docs.phalconphp.com/en/latest/reference/views.html#picking-views



34.1k

Ok, Yo voy a revisar, dependiendo de esto no crearia una vista por cada controlador