Question

I'm a novice to symfony php framework.I followed the symfony documentation which is a good resource for a developer.According to that i created a module and declare a symfony form and passed it to the template.But it's not rendering.Why is that?Following is my code.

actions.class.php

<?php

class frontendActions extends sfActions
{
public function executeIndex()
{
  $this->form = new LoginForm();
}
} 

indexSuccess.php

<form action="<?php echo url_for('frontend/submit') ?>" method="POST">
<table>
<?php echo $form;?>
<tr>
  <td colspan="2">
    <input type="submit" />
  </td>
</tr>
</table>
</form>

My custom form which is in lib/form folder

<?php

class LoginForm extends BaseForm
{
public function configure()
{
$this->setWidgets(array(
  'username'    => new sfWidgetFormInputText(),
  'password'   => new sfWidgetFormInputText(),
));
}
}

Here i'm bit confuse.Because there are two lib folders in symfony project.One is outside the app folder.Otherone is inside the app folder.Anyhow i put my custom form file inside the app folder one.And i tried by moving it to outsides lib folder.But both way didn't worked.

Was it helpful?

Solution 2

This is the solution which i came up with to this.I was first created a seperate form class by extending symfony base form.At that point my form didn't worked.So i added the form's attributes inside the controller's action method instead of defining it in a seperate file.Now it's working fine.

class loginActions extends sfActions
{
/**
* Executes index action
*
* @param sfRequest $request A request object
*/
public function executeIndex(sfWebRequest $request)
{
  $this->form = new sfForm();
  $this->form->setWidgets(array(
   'name'    => new sfWidgetFormInputText(),
   'password'   => new sfWidgetFormInputPassword(),
  ));
}


}

OTHER TIPS

To give a complete answer, can you copy of your routing.yml file? I think the problem is in the url_for(), if you don't have a route for frontend/submit it throws exception stops execution. Take a look to apache/php error logs.

About the folder that your LoginForm should be, follow these steps (consider 'frontend' to be the app name, and 'my_module' the module name'):

  1. It is a class that is only used inside a module => use module's lib folder (e.g. /apps/frontend/modules/my_module/lib)
  2. It is a class used in several modules of the same app => use app's lib folder (e.g. /apps/frontend/lib)
  3. It is a class used by several apps => use /lib folder

You can move a class from one folder to another and remember to refresh symfony cache.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top