Symfony - access related table field from within a form - symfony-1.4

Is it possible to get a property of a related table of a field within a form? I'm trying to get a property called "getIdentifier" which belongs to the OriginalStone model class.
<?php foreach ($form['treatedStones'] as $fields):?>
<?php $fields['original_stone_id']->renderRow() ?>
<?php endforeach?>
I was hoping I could do something like:
<?php foreach ($form['treatedStones'] as $fields):?>
<?php $fields['original_stone_id']->getObject()->getIdentifier() ?>
<?php endforeach?>
Thanks

I assume treatedStones is an embedded doctrine form. Try $form->getEmbeddedForm('treatedStones')->getObject()->getOriginalStone()->getIdentifier()

Related

How to show multiple Google Maps with different locations created in Advance Custom Fields Wordpress plugin?

I have created two Maps fields in Advanced Custom Fields (ACF) Plugin in its field group area, please check the screenshot
But on the front end when I try to add the code as per Google Maps custom field code only one Map is showing not the second one https://www.advancedcustomfields.com/resources/google-map/
Ah yes, I'm able to figure this out. There has no need of any other different settings, just need to add one more field in ACF fields group area and show that field in the front end by doing the same settings as did on the first field but just change the location variable name and pass the second field value in it. Below is the complete code example to show the first and second map in different HTML elements.
First Map:
<?php
$location = get_field('map');
if( !empty($location) ):
?>
<div class="acf-map">
<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>"></div>
</div>
<?php endif; ?>
Second Map:
<?php
$location_second = get_field('map_second');
if( !empty($location_second) ):
?>
<div class="acf-map">
<div class="marker" data-lat="<?php echo $location_second['lat']; ?>" data-lng="<?php echo $location_second['lng']; ?>"></div>
</div>
<?php endif; ?>
As I have created two map fields in ACF plugin, first map field's name is Map and Second map field name is Map Second, so these will be used as map and map_second in code as given above.
I hope you have ACF Pro version :)
then you can use repeater field
Create repeater field "locations" then inside only one field with name "location" and use code from example "Render multiple markers onto a map"

Wordpress save metabox checkboxes selection

Having an issue whereby the checkboxes inside a metabox aren't saving. I can save one value and have it return the value of checked to the checkboxes, just not multiple values, which I need. I've tried adding a foreach loop to the update_post_meta code but it didn't work. Slightly confused as to where I'm going wrong.
checkbox code is:
$areas = $wpdb->get_results("SELECT * FROM locations ORDER BY locationName ASC");
if( count($areas) ) :
?>
<div id="locationAssignedBoxes" size="1">
<?php
foreach($areas as $area) :
?>
<input type="checkbox" id="locationAssigned" name="locationAssigned" value="<?php echo $area->id; ?>"<?php if(get_post_meta($post->ID, 'locationAssigned', true) == $area->id) { ?> checked="checked"<?php } ?> /> <?php echo $area->locationName; ?><br>
<?php
endforeach;
?>
</div>
<?php
endif;
?>
Update_post_meta code is:
update_post_meta($post->ID, 'locationAssigned', $_POST['locationAssigned']);
Thanks very much!
This isn't a cut-and-paste answer to your question, but it should help. (I'm trying to solve a similar problem.)
Your problem in general: update_post_meta() saves a single meta value, not a collection of values. Because you want to save the values of multiple checkboxes, you have two choices:
Call update_post_meta() once for each of the checkboxes, creating a
collection of meta values associated with the post.
Combine all of the checkbox values into a single string and save those as a single value with one update_post_meta() call.
These two earlier questions are related and might point you in the right direction.
Save checkboxes of a metabox with a foreach loop (invalid argument)
Listing Pages With Checkboxes In a Metabox (and saving them)

Is it possible to create a table in current database of wordpress using a static page only (not creating as plugin)?

I wrote my code as bellow,
<?php
/*
Template Name:Register Page
Template URI:
Author:yuva
Author URI:
Description:This Is Page for Gallery.
*/
get_header();
?>
<div class="regist">
<h2><?php the_title(); ?></h2>
<?php
global $wpdb;
$my_table=$wpdb->prefix.'your_users';
$sql="CREATE TABLE IF NOT EXISTS $my_table (id int(20) not null auto_increment,name varchar(40) not null,password varchar(20) notnull,PRIMARY KEY(id))";
include_once(ABSPATH.'wp-admin/includes/upgrade.php');
dbDelta($sql);
?>
</div>
<?php
get_footer();
?>
Can any one help me solve this?
Thank you!
Since this code has nothing to interact with the user how about writing the above code in your function.php instead of the template page??
And yes you can surely create tables if you want.
Yes it is possible, but don't forget to use CREATE TABLE IF NOT EXISTS .Otherwise your query create new table every time when page is executed and your previous data will be lost.

Show next/prev if more than one post

A little lost - believe I'm almost there though. I'm trying to make it so the next and previous links don't show unless there is more than one post.
<?php if($numberofposts != "1") : ?>
Prev
<?php endif; ?>
Hopefully it's just something simple I'm overlooking.
Check to see if $numberofposts contains a number (instead of a string). It probably does. If so, you will want to rewrite your code like this:
<?php if($numberofposts > 1) : ?>
Prev
<?php endif; ?>
If it doesn't contain a number, you should probably rewrite whatever function it's pulling from so that it does.

Adding a static text on top of view when it is not filtered

I want to add a static text (some sort of explanation/welcome text) on the very top of a view (over the filter) in Drupal 6.x with Views "2". I want this text appear only when the view is not filtered (i.e. on initial load of the page).
My problem is that the only place I figure out to make it work partially is in the views-exposed-form--MYVIEW.tpl.php. The problem is that when I place the code in this template, I don't know if the view is filtered or not, so the text appear on every single page! I don't have access to this info in that template so the only place this is available ($rows or $empty variables for example) is in views-view--MYVIEW.tpl.php.
But there I got an another problem. The order in witch it seams the variables are output are not the same as the order in witch they appeared in the file. For example, the $exposed variable content is render always on top, then $admin_links, $header and so forth.
<?php if ($header): ?>
<div class="view-header">
<?php print $header; ?>
</div>
<?php endif; ?>
<?php if (!$rows): ?>
<h3>This static text appear AFTER $exposed !!!</h3>
<?php endif; ?>
<?php if ($exposed): ?>
<div class="view-filters">
<?php print $exposed; ?>
</div>
<?php endif; ?>
<?php if ($attachment_before): ?>
<div class="attachment attachment-before">
<?php print $attachment_before; ?>
</div>
<?php endif; ?>
So even if I place my static content before this code, the filter form always appear on top!
I found the reason why is doing this: the exposed filter form is rendered as a part of the content-top <div></div>, but not the result (and $header, $footer, etc).
So is this by design? Do I miss something? How can I get my static text on the very top of the content-top!?
Well, after some tweaking and lecture on preprocess function in the theming system, I found a solution to my problem. I share it with you and if you find a more elegante approach; let me know!
What I did is this...
1) In the template.php file of the theme, I add two fonctions:
function YOURTHEME_preprocess_views_view__MYVIEW(&$variables) {
if ($variables['rows'] || $variables['empty']) {
$GLOBALS['dont_show_static_text'] = TRUE;
}
}
function YOURTHEME_preprocess_views_exposed_form__MYVIEW(&$variables) {
if ($GLOBALS['dont_show_static_text']) {
$variables['custom_flag1'] = TRUE;
}
}
So, if my views is showing some results ($row) or a blank result ($empty), then I set a flag to be use in the template file....
2) In my views-exposed-form--MYVIEW.tpl.php
...
<?php if (!$custom_flag1): ?>
<h2>Some static text here</h2>
<?php endif; ?>
...
And voilĂ ! My static text is showing up only on the initial load of the view and it shows on TOP of the filter (not under!).
Hope this help someone else!

Resources