how to get data from an array in php - codeigniter

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;
}

Related

ACF how to get categorie taxonomy image to display inside grid

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?

integrate symfony and ajax

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

Only show items owned by the currently logged in user in category list view

I'd like to be able to provide a "Category List" view that only shows Articles that the currently logged in user owns.
Is there somewhere I can edit the query used to populate the Category List view or an extension that provides this functionality.
Thank you for any help you can provide. -J.
Thank you for your answer. I've written the plugin. Instead of passing in an array of Articles the onContentBeforeDisplay function is called for every article and an ArrayObject of the single article gets passed in. I've been able to identify the articles I want not to be displayed but still cannot get them not to display.
The $params variable has values such as "list_show_xxx" but I can't seem to change or access them.
here is a var_dump($params):
object(Joomla\Registry\Registry)#190 (1) { ["data":protected]=> object(stdClass)#250 (83) { ["article_layout"]=> string(9) "_:default" ["show_title"]=> string(1) "1" ["link_titles"]=> string(1) "1" ["show_intro"]=> string(1) "1" ["info_block_position"]=> string(1) "1" ["show_category"]=> string(1) "1" ["link_category"]=> string(1) "1" ["show_parent_category"]=> string(1) "0" ["link_parent_category"]=> string(1) "0" ["show_author"]=> string(1) "1" ["link_author"]=> string(1) "0" ["show_create_date"]=> string(1) "0" ["show_modify_date"]=> string(1) "0" ["show_publish_date"]=> string(1) "1" ["show_item_navigation"]=> string(1) "1" ["show_vote"]=> string(1) "0" ["show_readmore"]=> string(1) "1" ["show_readmore_title"]=> string(1) "1" ["readmore_limit"]=> string(3) "100" ["show_tags"]=> string(1) "1" ["show_icons"]=> string(1) "1" ["show_print_icon"]=> string(1) "1" ["show_email_icon"]=> string(1) "1" ["show_hits"]=> string(1) "1" ["show_noauth"]=> string(1) "0" ["urls_position"]=> string(1) "0" ["show_publishing_options"]=> string(1) "0" ["show_article_options"]=> string(1) "0" ["save_history"]=> string(1) "1" ["history_limit"]=> int(10) ["show_urls_images_frontend"]=> string(1) "0" ["show_urls_images_backend"]=> string(1) "1" ["targeta"]=> int(0) ["targetb"]=> int(0) ["targetc"]=> int(0) ["float_intro"]=> string(4) "left" ["float_fulltext"]=> string(4) "left" ["category_layout"]=> string(9) "_:default" ["show_category_heading_title_text"]=> string(1) "1" ["show_category_title"]=> string(1) "0" ["show_description"]=> string(1) "0" ["show_description_image"]=> string(1) "0" ["maxLevel"]=> string(1) "1" ["show_empty_categories"]=> string(1) "0" ["show_no_articles"]=> string(1) "1" ["show_subcat_desc"]=> string(1) "1" ["show_cat_num_articles"]=> string(1) "0" ["show_base_description"]=> string(1) "1" ["maxLevelcat"]=> string(2) "-1" ["show_empty_categories_cat"]=> string(1) "0" ["show_subcat_desc_cat"]=> string(1) "1" ["show_cat_num_articles_cat"]=> string(1) "1" ["num_leading_articles"]=> string(1) "1" ["num_intro_articles"]=> string(1) "4" ["num_columns"]=> string(1) "1" ["num_links"]=> string(1) "4" ["multi_column_order"]=> string(1) "0" ["show_subcategory_content"]=> string(1) "0" ["show_pagination_limit"]=> string(1) "1" ["filter_field"]=> string(5) "title" ["show_headings"]=> string(1) "1" ["list_show_date"]=> string(1) "0" ["date_format"]=> string(0) "" ["list_show_hits"]=> string(1) "1" ["list_show_author"]=> string(1) "1" ["orderby_pri"]=> string(5) "order" ["orderby_sec"]=> string(5) "rdate" ["order_date"]=> string(9) "published" ["show_pagination"]=> string(1) "2" ["show_pagination_results"]=> string(1) "1" ["show_feed_link"]=> string(1) "1" ["feed_summary"]=> string(1) "0" ["feed_show_readmore"]=> string(1) "0" ["display_num"]=> string(2) "10" ["menu_text"]=> int(1) ["show_page_heading"]=> int(0) ["secure"]=> int(0) ["page_title"]=> string(16) "Non-K2 News List" ["page_description"]=> string(33) "BBIC" ["page_rights"]=> NULL ["robots"]=> NULL ["access-edit"]=> bool(true) ["access-view"]=> bool(true) } }
I've tried $params->data->list_show_author = "0" but then the page doesn't load, problem is accessing and changing the variables in $param.
So the last step is to figure out how not to show the article. Any ideas?
Have a look here:
http://docs.joomla.org/Plugin/Events/Content#onContentBeforeDisplay
You need to write a plugin. Use that event trigger onContentBeforeDisplay
With the $context variable you can check what is actually displayed so you can find out if its the Category List view. If it is, you can do some manipulating.
The $article variable contains the articles which are being rendered. You will need to look into the $params variable and check if the user-id of the article belongs to the user. The user-id of the current user can be accessed like so: JFactory::getUser()->id
Unset any article which doesn't belong to the user (you will probably have to loop through as the articles are probably stored in an array).
Pro tip: Start of by using var_dump on all the arguments that are passed to onContentBeforeDisplay

Issue in printing a session array variable

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

Magento access price variable in product object

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());
}

Resources