Is there any drawback in Symfony when generating modules without the --non-verbose-templates option?
I can only see that whenever you change the model, you also have to change the _form partial by hand.
Thanks
The difference is that verbose-templates expands the form. For example, in a non-verbose-template the output is:
//..
<?php echo $form ?>
//..
and in a verbose-template:
//...
<tr>
<td><?php echo $form['field_1']->renderLabel() ?></td>
<td><?php echo $form['field_1']->renderError() ?></td>
//etc..
</tr>
//etc.
//...
Related
I've been Googling this to no avail. I have a multi-checkbox form element in one of my forms. Here's the code I used to create it:
$this->add(array (
'name' => 'thingyId',
'type' => 'MultiCheckbox',
'options' => array (
'value_options' => $thingyArray,
)
));
In my view script, I have this:
<?= $this->formRow($form->get('thingyId')); ?>
The form element shows up fine, but all of the checkboxes are on a single line. How do I get it so that each checkbox is on a new line?
If you view this link, you can see that the fourth argument is partial. So, you can use many ways to accomplish the task.
Method 1:
echo $this->formRow($element, null, null, 'template-file');
Now, create a template file named as template-file.phtml to render the element however you like.
//template-file.phtml
<span><?php echo $label; ?></span><br/>
<?php foreach ($element->getValueOptions() as $key => $value): ?>
<input type="checkbox" name="<?php echo $element->getName() ?>[]" value="<?php echo $value; ?>">
<span><?php echo $key; ?></span><br/>
<?php endforeach; ?>
Method 2
Create your own view helper by extending the default helper.
namespace Application\View\Helper;
class MyFormRow extends \Zend\Form\View\Helper\FormRow
{
/**
* #var string
*/
protected $partial = 'template-file';
}
Now, inform our application about our new helper in your module,
namespace Application;
class Module
{
public function getViewHelperConfig()
{
return array(
'invokables' => array(
'myFormRow' => 'Application\View\Helper\MyFormRow'
)
);
}
}
Lastly use the helper:
echo $this->myFormRow($element);
I came across this question when I was having this issue myself. The code that was being used was the following:
<?php
$oMultiCheckboxField = $oForm->get('multicheckboxelement');
echo $this->formMultiCheckbox($oMultiCheckboxField);
?>
The only additional parameter you could pass to the formMultiCheckbox view helper was whether to append or prepend the label.
How I eventually chose to solve this is with the following code:
<?php
$oMultiCheckboxField = $oForm->get('multicheckboxelement');
$oMultiCheckboxViewHelper = new \Zend\Form\View\Helper\FormMultiCheckbox();
$oMultiCheckboxViewHelper->setSeparator('<hr>');
echo $oMultiCheckboxViewHelper->render($oMultiCheckboxField);
?>
From what I recall, ZF1 had the option to set the separator (I clearly remember this at least for radio buttons). Why there isn't a clearer way to do this in ZF2 is a bit puzzling. If there are better ways to do this, I would certainly like to know about it.
Is there a way to see the methods lists that is being called in the shopping cart view.
<ul class="checkout-types">
<?php foreach ($this->getMethods('methods') as $method): ?>
<?php if ($methodHtml = $this->getMethodHtml($method)): ?>
<li><?php echo $methodHtml; ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
This code is in the views anywhere the "Proceed to Checkout" button shows up but my Paypal Express button isn't in the list. I can trace it back to the Block abstract but then the code looses me (ie what calls setChild to make 'methods' a child and to give it a block?).
I have a module called main which is my default module and a module called song.
I want to put into my main module an "add form" of my song module.
I don't know if I have to use component, how and where to process the form.
Could you please help me ?
Have you checked the documentation? Specially this part of the doc?
It covers the form system by using a basic contact form:
You have the controller (the actions.class.php inside your main module) which create an instance of the form and handle the submission (validation, save, etc ..)
Then the template (contactSuccess.php), which display the form
The main difference is that you probably have a model called Song, so you will have to use the SongForm instead of creating a new one (using new sfForm()). For this part, you can see, on the same documentation page, the part Forms Based on a Model which cover the case of an article model.
Edit:
A step by step:
In your main/actions/actions.class.php:
public function executeIndex($request)
{
$this->form = new SongForm();
if ($request->isMethod('post'))
{
$this->form->bind($request->getParameter('song'));
if ($this->form->isValid())
{
$song = $this->form->save();
$this->getUser()->setFlash('notice', 'Thank you, the song has been added');
$this->redirect('main/index');
}
}
}
In your template, main/templates/indexSuccess.php:
<?php if ($sf_user->hasFlash('notice')): ?>
<div class="flash_notice"><?php echo $sf_user->getFlash('notice') ?></div>
<?php endif ?>
<?php echo $form->renderFormTag('main/index') ?>
<table>
<?php echo $form ?>
<tr>
<td colspan="2">
<input type="submit" />
</td>
</tr>
</table>
</form>
And you're done.
I really encourage you to read the whole Jobeet tutorial. You will learn lots of things. Basically every thing I described here, is in this tutorial.
For the sf_guard_user field, you should redefine it as hidden, and then set a default value with the current connected user.
Create a new form: /lib/form/CustomSongForm.class.php
<?php
class CustomSongForm extends SongForm
{
public function configure()
{
parent::configure();
$this->widgetSchema['sf_guard_user_ud'] = new sfWidgetFormInputHidden();
}
}
Then you can define the default, like you said:
}$this->form->setDefault('sf_guard_user_id', $this->getUser()->getId());
in the objects list generated with the admin generator, the batch Action are shown in a select with a submit button.
I want to transform it and get only link (for example i have the action delete and i want to have a link to delete instead of choosingthe action and than click on the button.)
i have the _list_batch_actions.php file but i could'nt see how to get the href for the tag:
<li class="sf_admin_batch_actions_choice">
test // this is what i added but not woorking
<select name="batch_action">
<option value=""><?php echo __('Choose an action', array(), 'sf_admin') ?></option>
<option value="batchDelete"><?php echo __('Delete', array(), 'sf_admin') ?></option>
</select>
<?php $form = new BaseForm(); if ($form->isCSRFProtected()): ?>
<input type="hidden" name="<?php echo $form->getCSRFFieldName() ?>" value="<?php echo $form->getCSRFToken() ?>" />
<?php endif; ?>
<input type="submit" value="<?php echo __('go', array(), 'sf_admin') ?>" />
</li>
Any idea on how i can use it ?
Solution one:
The batch actions are submitted by form by default. You can rewrite the template to put links instead of a form.
Check your auto generated controler in the cache
(you need before to see your admin page in order to generate the cache).
apps/backend/dev/modules/autoYourModule/actions/action.class.php
You will find a function executeBatch().
You can copy this function and put it in your admin module controler and then modify its behaviour in order to do what you need.
Solution two:
Use javascript to hide your form and put a link which will select the delete action in your select box, the submit the form using javascript.
i need to remove short description in the view.phtml and replace with attribute.phtml tab...how to do it? Thanks.
Edit your theme's template/catalog/product/view.phtml (not the base theme's, that can get overwritten) and replace this:
<?php if ($_product->getShortDescription()):?>
<div class="short-description">
<h2><?php echo $this->__('Quick Overview') ?></h2>
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
</div>
<?php endif;?>
with this:
<?php echo $this->getChildHtml('additional') ?>
And further down where you see the same line delete it. This avoids duplication.