We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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?



43.9k

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]) }}


81.2k

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



43.9k

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



81.2k

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