Symfony 1.4 order a widgets data - symfony1

I have a sfWidgetFormDoctrineChoiceMany widget, I was wondering if there was a way to order the data inside it in ascending order
'locations_list' => new sfWidgetFormDoctrineChoiceMany(array('model' => 'Location')),

To set ordering on sfWidgetFormDoctrineChoiceMany (and sfWidgetFormDoctrineChoice too) you should provide a order_by option. Like this:
// ...
'locations_list' => new sfWidgetFormDoctrineChoiceMany(array(
'model' => 'Location',
'order_by' => array('Name', 'asc'), // <--- replace 'Name' with your column name in camel-case format
)),
// ...
When I need to get a quick reference on widget supported options, I always go to it's source. Usually they have a nice documentation right in PHP comments. Check this link to sfWidgetFormDoctrineChoice source:
https://github.com/nationalfield/symfony/blob/a2d4442dfeb26355e89360f6e725c1f19c3a1ee0/lib/plugins/sfDoctrinePlugin/lib/widget/sfWidgetFormDoctrineChoice.class.php#L33

Related

Breezejs clear multple keys

We have the following mapping in EF6:
HasRequired(x => x.modulemain).WithMany().HasForeignKey(t => t.moduleid);
HasOptional(t => t.modulerslt).WithMany().HasForeignKey(t => new { t.moduleid, t.trmendrs });
HasOptional(x => x.modulegoal).WithMany().HasForeignKey(t => new { t.moduleid, t.trmgcode });
HasOptional(x => x.modulefase).WithMany().HasForeignKey(t => new { t.moduleid, t.trmfcode });
Breezejs understands this mapping with the combination of the two keys. BUT there is a problem: Whenever the user 'clears (sets its value to NULL)' the modulegoal/modulefase/modulerslt sets the moduleid value to an empty string and the 'second key' as well. The problem is that the first keys is being used in multiple references. So clearing one of the references, mismatches the other (important) references. Is there any way to tell breeze to NOT clear the first key?

How to handle GET params within urlManager's rule in Yii?

I pass a query string to SearchController::actionDefault in form of GET parameter q:
/search/?q=...
However I need to define a rule that would automatically initialize this parameter with some value or define another param.
If I'll request mysite.com/showall I need get the same content like in /search/?q=*
This is what I've tried:
'/showall' => '/search/default/index/?r=*',
I solved this!
there is possible to set defaultParams in urlManager, and finaly it looks like in application config file:
...
'components' => array(
...
'urlManager' => array(
...
'rules' => array(
....
'/show_all' => array( '/search/default/index', 'defaultParams' => array('show_all'=>'-') ),
....
),
...
),
...
),
The accepted answer also works when you are getting different requests and you need to map it to the same GET param.
For example I want all of these requests:
user/pics
user/photos
user/pictures
to actually generate: user/index?content=photos.
This might be one of a way to go:
'<controller:user>/(<content:photos>|pics|pictures)' => array('<controller>/index', 'defaultParams'=>array('content'=>'photos')),

How to apply classes to labels using Zend\Form and add line endings within the rendered form?

I've followed the tutorial for Zend Framework 2 and I see on the rendered form that the convention for binding the label is to wrap the input element in the label tags as opposed to using the 'for' attribute. While the tutorial didn't cover it, I deduced (correctly) that the attributes array allows for setting a class on the input element itself but what I really want to do is apply a class onto the label defined under options.
Here's an example used in the tutorial (from AlbumForm.php):
$this->add(array(
'name' => 'title',
'attributes' => array(
'class' => 'required', // <- I added this
'type' => 'text',
),
'options' => array(
'label' => 'Title',
),
));
That will render as this:
<label><span>Title</span><input name="title" class="required" type="text" value=""></label>
Optionally, I could live with having the class applied to the span tag but I'd prefer to use the class on the label and then use css child selectors for the span and input elements
I've re-read the tutorial plus the comments on the appropriate section and even dug into the Zend\Form API documentation itself and I don't see how I could apply a class attribute to the label in declaring a form element in this manner.
Another minor nitpick with form rendering is that it appears to be rendered inline with no line breaks between form elements. I've gotten around this by adding a line break in the view scripts (add.phtml and edit.phtml) like so:
echo $this->formRow($form->get('title')) . "\n";
However, this seems like a pain to have to do with every echoed form statement within the view and using the formCollection() also renders the entire form output inline. For legibility purposes I'd like to at least have line breaks where appropriate when viewing the source (I'd wish for proper indentation, too, but that seems like a tall order since even IDE's get it wrong much of the time)
So, is there a built-in option for either of these concerns that I'm missing or, alternatively, a way to define a factory or helper? If I'd need to write a helper, I'd want it to apply to all modules.
To add a class to the label use the 'label_attributes' key in your configuration:
$this->add(array(
'name' => 'title',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Title',
'label_attributes' => array(
'class' => 'required',
),
),
));
To add new lines, you can either write your own FormRow view helper or render the label and element separately within your view script like this:
$form = $this->form;
$form->prepare();
echo $this->form()->openTag($form) . "\n";
echo $this->formLabel($form->get('title')) . "\n";
echo $this->formInput($form->get('title')) . "\n";
echo $this->formElementErrors($form->get('title'));
// other elements
echo $this->form()->closeTag($form) . "\n";

Change default controller path in lithium

I'm writing a new version of an API and would like to support legacy versions by having distinct sets of controllers for each version. Within the default "app\controllers" path in Lithium, I would like to have for example "v1" and "v2" paths.
I have tried accomplishing this within the route itself by doing something like:
Router::connect('/{:version}/{:controller}/{:action}{:args}', array(
'controller'=> '\app\controllers\{:version}\{:controller}Controller',
), array());
Then I tried overriding the path in the libraries bootstrap module by doing something like:
if( preg_match('/^\/(v[0-9\.]+)/', $_SERVER['REQUEST_URI'], $match) ) {
Libraries::paths(array(
'controllers' => "controllers\\".$match[1].'\\{:name}Controller',
'models' => "models\\".$match[1]."\\{:name}",
));
}
I spent about a half a day at work searching google and the very sparse lithium docs. I am not sure what release of Lithium we are using as I have stepped into this pre-existing code base.
Thanks for any tips you may have!
In your routes.php file, you should re-configure the Dispatcher default rules with
Dispatcher::config(array('rules' => array(
'v1' => array('controller' => 'app\controllers\v1\{:controller}Controller')
)));
and a continuation route to match /v1/... requests
Router::connect('/v1/{:args}', array('v1' => true), array(
'continue' => true, 'persist' => array('controller', 'v1')
));
You can easily use :version instead of a predefined version number if you need so.

using ahDoctrineEasyEmbeddedRelationsPlugin to embed i18n Translation

I'm using ahDoctrineEasyEmbeddedRelationsPlugin to add dynamic i18n translations to my object, so I wrote this in my object Form class
$this->embedRelations(array(
'Translation' => array(
'considerNewFormEmptyFields' => array('content', 'lang')
));
The result I got is only one input per record, "content".
I've tried this in the FormTranslation class, but no luck:
$this->useFields(array('content', 'lang'));
So what I did was to create a manual doctrine relation with a foreignAlias called "translations", and then:
$this->embedRelations(array(
'translations' => array(
'considerNewFormEmptyFields' => array('content', 'lang')
));
this almost worked, I get the lang field now, but only in the list of existing tranlations, not in the new translation form
Any ideas if I can archieve this? Thanks!
Hm , I always use for example for 'en' and 'uk' culture :
considerNewFormEmptyFields' => array('en','uk')

Resources