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

form render problem

I try to make a form

In the controller I write this :

<?php

use Phalcon\Mvc\Controller;

class CrudController extends Controller

{

public function indexAction(){

$this->view->form = new CrudForm;

//print($this->view->form);

}

}

In the model I just write :

<?php

use Phalcon\Mvc\Model;

class Crud extends Model { //public $id;

public $name;

public $email;

public $city;

}

In the \forms\Crudform.php I write :

<?php

use Phalcon\Forms\Form;

use Phalcon\Forms\Element\Text;

use Phalcon\Forms\Element\Hidden;

use Phalcon\Validation\Validator\PresenceOf;

use Phalcon\Validation\Validator\Email;

class CrudForm extends Form

{

public function initialize($entity = null, $options = array())

{

  if (!isset($options['edit'])) {

      $element = new Text("id");

      $this->add($element->setLabel("Id"));

  } else {

      $this->add(new Hidden("id"));

  }

.......... }

.........

In the \views\crud\index.php, I try to render the form with : $form->render("name")

But, no form displayed.

Do I miss something in my codes ?



77.7k
Accepted
answer

Might be only a typo, but the extension of view files should be phtml instead of php



3.5k

thank you Lajos Bencz