I need to send data using ajax in Symfony2 action.
For this I use the following js code:
$.ajax({
type: "POST",
url: "{{ path('slch_create_slot',{ 'uuid': meeting.uuid })}}",
data: request,
cache: false,
success: function(){
alert(data);
location.href = "{{ path('slch_new_meeting_step2',{ 'uuid': meeting.uuid })}}";
}
});
Symfony2 side I use the following code:
if($request->isXmlHttpRequest()){
$json = $request->getContent();
$tableau = json_decode($json, true);
var_dump($tableau);
....
$response = new Response(json_encode(array('response' => 'ok')));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
When retrieving the Symfony2 response I get the following results:
array(1) {
["slots"]=>
array(4) {
[0]=>
array(5) {
["hour"]=>
string(2) "14"
["minute"]=>
string(1) "0"
["day"]=>
string(2) "11"
["month"]=>
string(1) "1"
["year"]=>
string(4) "2015"
}
[1]=>
array(5) {
["hour"]=>
string(2) "14"
["minute"]=>
string(1) "0"
["day"]=>
string(2) "12"
["month"]=>
string(1) "1"
["year"]=>
string(4) "2015"
}
[2]=>
array(5) {
["hour"]=>
string(2) "14"
["minute"]=>
string(1) "0"
["day"]=>
string(2) "13"
["month"]=>
string(1) "1"
["year"]=>
string(4) "2015"
}
[3]=>
array(5) {
["hour"]=>
string(2) "14"
["minute"]=>
string(1) "0"
["day"]=>
string(2) "14"
["month"]=>
string(1) "1"
["year"]=>
string(4) "2015"
}
}
}
{"response":"ok"}
can you tell me why I have the request in the Symfony2 response ?
you're doing var_dump($tableau) which dumps the request. That's why you're receiving it. Get rid of that line and you won't receive it anymore. – acontell 1 hour ago
Related
I have a classifieds site created with Wordpress and ACF, I created a Custom Post CLASSIFIEDS and a Taxonomy named "Main Category". I added in "Main Category" the various categories concerning the classifieds (Real esate, Job,...).
I created with ACF a field "Image Category" that I assigned to the "Main Category" Taxonomy, so I can add an image to each of the Princiaples Categories. My goal is to be able to display a grid with my different ads and to display the image of the main category in each ad card.
So I tried with function inside my functions.php :
function render_custom_field_image_block() {
// Object can be a post, term or user.
$object = wpgb_get_object();
echo ("VALUE :");
var_dump($object);
// If this is not a post (you may change this condition for user or term).
if ( ! isset( $object->post_type ) ) {
return;
}
// categorie_image is the field name about my category image field created with ACF
$image_id = get_post_meta( $object->ID, 'categorie_image', true );
if ( empty( $image_id ) ) {
return;
}
// You can change the image size "medium_large" to suit your needs.
$image_url = wp_get_attachment_image_url( $image_id, 'medium_large' );
if ( empty( $image_url ) ) {
return;
}
printf(
'<img src="%s" alt="%s" width="100%" height="250px" style="object-fit:contain">',
esc_url( $image_url ),
esc_attr( get_post_meta( $image_id, '_wp_attachment_image_alt', true ) )
);
}
But not working and the var_dump on $object don't contain info about categorie image except the ID of the categorie :
VALUE :object(WP_Post)#13417 (31) {
["ID"]=>
int(12593)
["post_author"]=>
array(4) {
["ID"]=>
int(1)
["display_name"]=>
string(10) "erikdenice"
["posts_url"]=>
string(45) "/author/erikdenice/"
["avatar"]=>
array(11) {
["size"]=>
int(96)
["height"]=>
int(96)
["width"]=>
int(96)
["default"]=>
string(2) "mm"
["force_default"]=>
bool(false)
["rating"]=>
string(1) "g"
["scheme"]=>
NULL
["processed_args"]=>
NULL
["extra_attr"]=>
string(0) ""
["found_avatar"]=>
bool(true)
["url"]=>
string(81) "https://secure.gravatar.com/avatar/635ba97b42d5681c19c4fc0f641bfa6e?s=96&d=mm&r=g"
}
}
["post_date"]=>
int(1666982551)
["post_date_gmt"]=>
string(19) "2022-10-28 16:42:31"
["post_content"]=>
string(14) "Vends cabinets"
["post_title"]=>
string(14) "Vends cabinets"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(6) "closed"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(14) "vends-cabinets"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
int(1666982551)
["post_modified_gmt"]=>
string(19) "2022-10-28 16:42:31"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(62) "/?post_type=pt-annonces&p=12593"
["menu_order"]=>
int(0)
["post_type"]=>
string(11) "pt-annonces"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
["object_type"]=>
string(4) "post"
["post_sticky"]=>
bool(false)
["metadata"]=>
array(21) {
["_edit_lock"]=>
string(12) "1666975261:1"
["_edit_last"]=>
string(1) "1"
["type_de_lannonce_Catégorie"]=>
string(2) "43"
["_type_de_lannonce_Catégorie"]=>
string(19) "field_63471b1906e2f"
["type_de_lannonce"]=>
string(0) ""
["_type_de_lannonce"]=>
string(19) "field_63471b1903469"
["cabinets_concerne_cab"]=>
string(2) "61"
["_cabinets_concerne_cab"]=>
string(19) "field_63471b192cb91"
["cabinets"]=>
string(0) ""
["_cabinets"]=>
string(19) "field_63471b190355e"
["ville_concernee_par_lannonce"]=>
string(5) "PARIS"
["_ville_concernee_par_lannonce"]=>
string(19) "field_634af425dbd97"
["le_prix"]=>
string(6) "350000"
["_le_prix"]=>
string(19) "field_634acfab8dcdd"
["personne_contacter_nom"]=>
string(0) ""
["_personne_contacter_nom"]=>
string(19) "field_63471b196156d"
["personne_contacter"]=>
string(0) ""
["_personne_contacter"]=>
string(19) "field_63471b190370e"
["autres_images"]=>
string(0) ""
["_autres_images"]=>
string(19) "field_63471b1903789"
["wpgb"]=>
array(17) {
["post_format"]=>
string(0) ""
["permalink"]=>
string(0) ""
["columns"]=>
int(1)
["rows"]=>
int(1)
["content_background"]=>
string(0) ""
["overlay_background"]=>
string(0) ""
["content_color_scheme"]=>
string(0) ""
["overlay_color_scheme"]=>
string(0) ""
["attachment_id"]=>
string(0) ""
["gallery_ids"]=>
string(0) ""
["mp3_url"]=>
string(0) ""
["ogg_url"]=>
string(0) ""
["mp4_url"]=>
string(0) ""
["ogv_url"]=>
string(0) ""
["webm_url"]=>
string(0) ""
["embed_video_url"]=>
string(0) ""
["video_ratio"]=>
string(4) "16:9"
}
}
["permalink"]=>
string(54) "/pt-annonces/vends-cabinets/"
["post_terms"]=>
array(2) {
[0]=>
object(WP_Term)#13411 (13) {
["term_id"]=>
int(43)
["name"]=>
string(8) "CABINETS"
["slug"]=>
string(8) "cabinets"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(43)
["taxonomy"]=>
string(20) "categorie_principale"
["description"]=>
string(0) ""
["parent"]=>
int(0)
["count"]=>
int(1)
["filter"]=>
string(3) "raw"
["link"]=>
string(57) "/categorie_principale/cabinets/"
["color"]=>
string(0) ""
["background"]=>
string(0) ""
}
[1]=>
object(WP_Term)#13409 (13) {
["term_id"]=>
int(61)
["name"]=>
string(5) "VENTE"
["slug"]=>
string(5) "vente"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(61)
["taxonomy"]=>
string(12) "type_cabinet"
["description"]=>
string(0) ""
["parent"]=>
int(0)
["count"]=>
int(1)
["filter"]=>
string(3) "raw"
["link"]=>
string(46) "/type_cabinet/vente/"
["color"]=>
string(0) ""
["background"]=>
string(0) ""
}
}
["post_format"]=>
string(8) "standard"
["post_media"]=>
NULL
}
So my question is how to get the URL of the categorie_image?
Hi I'm Trying to display results from controller to view in Codeigniter. I fetching the results from model to controller and then displaying the details to map and inside div.
I'm using biostall for displaying on map.It is working perfectly.Also i want to display inside div also which is not working. Here is my Code..
My Model Code..
function getRegaddress($citycheck,$lat,$lng,$itemid,$hotelid) {
$return =array();
// Here goes Query....
//$query = mysql_query($results);
if ($query->num_rows() >0) {
foreach ($query->result() as $row) {
array_push($return, $row);
}
// return $query->result();
}
return $return;
}
}
Here The Controller code
$data = $this->maps_model->getRegaddress($citycheck,$lat,$lng,$itemid,$hotelid);
$data['hotelname'] = $hotelname;
$config['center'] = $lat.",".$lng;
$this->load->library('googlemaps');
$this->googlemaps->initialize($config);
foreach ($data as $coordinate) {
// $data = array();
// $data['values']=$coordinate->hotelname;
$marker = array();
$marker['title'] = $coordinate->hotelname;
$marker['position'] = $coordinate->lat.','.$coordinate->lng;
$this->googlemaps->add_marker($marker);
}
$data = array();
$data['map'] = $this->googlemaps->create_map();
$this->load->view('templates/_header');
$this->load->view('content/temp-view', $data);
$this->load->view('templates/footer');
View Code
<?php echo $map['js']; ?>
<div class="col-lg-8">
<div class="media">
<h3 class="media-heading text-danger-theme"><?php echo $hotelname; ?></h3>
<?php echo $map['html']; ?>
</div>
</div>
</div>
</div>
</div>
In the result ... The map marker is showing the details from database. But When I display the delalername on the div it is showing an error like ...
Severity: Notice
Message: Trying to get property of non-object
Filename: controllers/mapcontrol.php
Line Number: 84
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: controllers/mapcontrol.php
Line Number: 84
Why i'm getting this error? Anyone Knows Please Help ...
Here is the structure of output
array(3) { [0]=> object(stdClass)#23 (15) { ["hotelid"]=> string(1) "2" ["hoteltype"]=> string(1) "3" ["hotelname"]=> string(18) "Sreekrishna food" ["dealerloc"]=> string(27) "Bengaluru, Karnataka, India" ["lat"]=> string(18) "12.971598700000000" ["lng"]=> string(18) "77.594562699999980" ["dealercity"]=> string(9) "Bengaluru" ["dealeraddress"]=> string(27) "Bengaluru, Karnataka, India" ["type"]=> string(2) "ar" ["stype"]=> string(3) "ggs" ["email"]=> string(15) "local#gmail.com" ["mobile"]=> string(10) "9947485214" ["phone"]=> string(10) "9947485214" ["website"]=> string(0) "" ["distance"]=> string(22) "0.00005899369716644287" } [1]=> object(stdClass)#24 (15) { ["hotelid"]=> string(1) "3" ["hoteltype"]=> string(1) "3" ["hotelname"]=> string(15) "Aey food" ["dealerloc"]=> string(42) "Shivaji Nagar, Bengaluru, Karnataka, India" ["lat"]=> string(18) "12.985650300000000" ["lng"]=> string(18) "77.605692699999960" ["dealercity"]=> string(13) "Shivaji Nagar" ["dealeraddress"]=> string(42) "Shivaji Nagar, Bengaluru, Karnataka, India" ["type"]=> string(2) "ar" ["stype"]=> string(3) "ggs" ["email"]=> string(9) "std#ff.il" ["mobile"]=> string(10) "9947485214" ["phone"]=> string(10) "9947485214" ["website"]=> string(0) "" ["distance"]=> string(18) "1.2265085392649464" } [2]=> object(stdClass)#25 (15) { ["hotelid"]=> string(1) "1" ["hoteltype"]=> string(1) "3" ["hotelname"]=> string(17) "Super - foods" ["dealerloc"]=> string(47) "FM Cariappa Colony, Bengaluru, Karnataka, India" ["lat"]=> string(18) "12.977923000000000" ["lng"]=> string(18) "77.612083499999930" ["dealercity"]=> string(18) "FM Cariappa Colony" ["dealeraddress"]=> string(47) "FM Cariappa Colony, Bengaluru, Karnataka, India" ["type"]=> string(2) "ar" ["stype"]=> string(3) "ggs" ["email"]=> string(11) "ddd#gfgf.in" ["mobile"]=> string(10) "9947485214" ["phone"]=> string(10) "9947485214" ["website"]=> string(12) "www.music.in" ["distance"]=> string(18) "1.2580702750661623" } }
I have a query like this :
$this->db->select('shop_users.user_id');
$this->db->select('users.*');
$this->db->from('shop_users');
$this->db->join('users' , 'users.id = shop_users.user_id' );
$this->db->where('shop_users.shop_id',$gets['shop_id']);
$user = $this->db->get()->result();
$data['user'] = $user;
var_dump($user);
return;
content of var_dump() is :
> array(1) { [0]=> object(stdClass)#76 (29) { ["user_id"]=> string(5)
> "33691" ["id"]=> string(5) "33691" ["username"]=> string(16)
> "" ["password"]=> string(32)
> "" ["name"]=> string(8) "سوده"
> ["family"]=> string(17) "Ù…Øمد کاشی" ["email"]=> string(21)
> "" ["avatar"]=> string(11) "default.gif"
> ["status"]=> string(1) "1" ["submit_date"]=> string(19) "2015-12-26
> 13:17:20" ["last_activity"]=> string(1) "0" ["activecode"]=> string(1)
> "0" ["submit_ip"]=> string(0) "" ["city"]=> string(1) "1" ["zone"]=>
> string(1) "0" ["city_name"]=> string(1) " " ["phone"]=> string(20)
> "" ["bankAcount"]=> string(13) ""
> ["bankCart"]=> string(1) " " ["bank"]=> string(1) " " ["admin_seen"]=>
> string(1) "1" ["gender"]=> string(1) " " ["finance"]=> string(1) "0"
> ["coupons"]=> string(1) "0" ["shaba"]=> string(1) " " ["ref"]=>
> string(1) "0" ["done"]=> string(1) "0" ["hasmobile"]=> string(1) "0" }
> }
now, how can I fetch user_id ?
I've test below codes but them return null:
$user->user_id;
$user['user_id'];
$user[0]['user_id'];
or
$user[0]->user_id;
You have to access to first element of your array because it is your array of returned values. (array in array)
You get a array from this query. You can get first item at frist and than get attrs of the item.
if($user && count($user)>0){
echo $user[0]->user_id;
}
I have an peculiar session array variable,I need to pick one element to display on the screen.I'm not sure how to do that in smarty.Please give me the syntax how to manipulate the element in smarty.Here is the array values. I need to select ["school_name"] from the set.Please help
array(6) {
["id"]=> string(32) "cb60942f64d2b7bae2076926ae430f1d"
["sa"]=> NULL ["start_cache_timer"]=> int(1377752940) ["user"]=>
array(17) {
["host_id"]=> string(1) "9"
["user_id"]=> string(2) "16"
["school_name"]=> string(10) "Joseph High School"
["code"]=> string(10) "2E4C5339F8"
["academic_id"]=> string(2) "21"
["title"]=> string(2) "Mr"
["first_name"]=> string(3) "Jon"
["last_name"]=> string(7) "Bachura"
["name"]=> string(11) "Jon Bachura"
["email"]=> string(12) "jon#yeks.org"
["role"]=> string(1) "1"
["times_login"]=> int(656)
["acc_status"]=> string(1) "3"
["user_status"]=> string(1) "3"
["admin_user_id"]=>
string(2) "16"
["life"]=>
array(2) {
["current"]=>
int(1377756843)
["start"]=>
int(1377756843)
}
["training"]=>
array(1) {
["start_time"]=>
float(1377752946.14)
}
}
["mrole"]=>
NULL
["extAjaxSession"]=>
int(3)
}
Use $smarty.session:
$smarty.session.user.school_name
How do I access the price in one of the simple products? The following is the beginning of the array I want to access from my var_dump($_product->debug()); (stackoverflow wouldn't let me post the whole thing). I am working on the issue related to this post: Magento Retrieve simple product price for configurable product
["_cache_instance_products"]=>
array(9) {
["0 (Mage_Catalog_Model_Product)"]=>
array(33) {
["entity_id"]=>
string(2) "69"
["entity_type_id"]=>
string(1) "4"
["attribute_set_id"]=>
string(2) "10"
["type_id"]=>
string(6) "simple"
["sku"]=>
string(13) "1001-blu-ven1"
["has_options"]=>
string(1) "0"
["required_options"]=>
string(1) "0"
["created_at"]=>
string(19) "2013-04-02 22:12:27"
["updated_at"]=>
string(19) "2013-04-02 23:54:41"
["parent_id"]=>
string(2) "78"
["color"]=>
string(1) "6"
["vendor"]=>
string(1) "5"
["name"]=>
string(14) "test_1 blue v1"
["url_key"]=>
string(14) "test-1-blue-v1"
["msrp_enabled"]=>
string(1) "2"
["msrp_display_actual_price_type"]=>
string(1) "4"
["image"]=>
string(12) "no_selection"
["small_image"]=>
string(12) "no_selection"
["thumbnail"]=>
string(12) "no_selection"
["options_container"]=>
string(10) "container2"
["url_path"]=>
string(19) "test-1-blue-v1.html"
["weight"]=>
string(6) "0.0000"
["price"]=>
string(6) "1.0000"
["status"]=>
string(1) "1"
["visibility"]=>
string(1) "1"
["enable_googlecheckout"]=>
string(1) "1"
["tax_class_id"]=>
string(1) "0"
["is_recurring"]=>
string(1) "0"
["description"]=>
string(19) "test_1 blue v1 desc"
["short_description"]=>
string(19) "test_1 blue v1 desc"
I was able to get this question answered in the other forum: https://magento.stackexchange.com/questions/4050/access-price-variable-in-product-object/4051?noredirect=1#comment5583_4051
$childProducts = Mage::getModel('catalog/product_type_configurable')
->getUsedProducts(null,$_product);
foreach($childProducts as $child) {
print_r($child->getPrice());
}