Fetch list data from database in Joomla component - joomla

I am creating custom component in joomla and it saves list data in database like these:
["2013-05-04","2013-05-05","2013-05-06","2013-05-07","2013-05-08","2013-05-09","2013-05-10","2013-05-11","2013-05-12"]
Is there any way so that i can fetch these data nicely on module ?
Thanks.

If i got your question you want to show these out put in you module.See the below example:
<?php
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
$output = json_decode($json , true);
print_r($output);
?>
Output:
Array
(
[a] => 1
[b] => 2
[c] => 3
[d] => 4
[e] => 5
)
Then you can use this output as below:
<?php
foreach ($output as $value){
echo $value;
}
?>
For more info check the this : http://php.net/manual/en/function.json-decode.php
Hope this helps you.

It is done through json_decode() function.

Related

Laravel overwrite value in request

I trouble to overwrite existing request value.
Below example info is my input array and product is my input array key.
e.g,
HTML
<input type="text" name="info[product]" value="10" />
PHP
echo request('info.product');
OUTPUT
10
Edit
print_r(request()->all());
Array
(
[info] => Array
(
[product] => 10
)
[_method] => PUT
[info.product] => 20
)
Question : But now I am required to overwrite this default 10 value to 20 using laravel.
Use the merge() method:
$array['input']['product'] = 20;
request()->merge($array);
Or do this when you'll need the data from request:
$data = request()->all();
$data['input']['product'] = 20;
Try this:
Input::merge(['input.product' => 'new value']);
and don't forget to import Input facade at the top.( use Input;)

how to create 2 variable session in Codeigniter

How to Create 2 variable session
I have create but for $se not show
I think your after something like Multiple session but question unclear
Examples
Backend
$session_vals1 = array(
'some_data' => 1
);
$this->session->set_userdata('backend', $session_vals1);
To access
$session_vals1_data = $this->session->userdata('backend');
echo $session_vals1_data['some_data'];
Frontend
$session_vals2 = array(
'some_data' => 2
);
$this->session->set_userdata('frontend', $session_vals1);
To access
$session_vals1_data = $this->session->userdata('frontend');
echo $session_vals1_data['some_data'];

Codeigniter echo session Multidimensional Array variable

Okay im using codeigniter and i got a session where i want to echo [user_id], i can see its an "Multidimensional Array", but i cant seem to get it right...
This is the print_r from all session userdata:
Array (
[session_id] => b7e721332248
[ip_address] => ::1
[user_agent] => Mozilla/5.0
[last_activity] => 1409104940
[user_data] => [name] => 2 [uniq] => 2
[flexi_auth] => Array ( [user_identifier] => mail.com [user_id] => 2 [admin] => 1
[group] => Array ( [3] => Master Admin )
[privileges] => Array ( )
[logged_in_via_password] => 1
[login_session_token] => 11017021313jhbjh1h2j3b213mab913269d95 ) )
if i type:
print_r($this->session->all_userdata()); // i will get all
echo $this->session->userdata('uniq'); //returns 2
echo $this->session->userdata('user_id'); //returns nothing(THIS IS THE PROBLEM)
Ive tried something like this:
$this->session->userdata(1,1); //1,1 would be array 2 and number 2 which would be user_id
Is it because i can only print out if I loop through them somehow?
You're trying to call the data directly, if you're want to access user_data or flexi_auth you need to assign the data to a variable then target it since they're arrays.
$session_data = $this->session->all_userdata();
echo $session_data['user_data']['uniq']; // 2
$user_data = $this->session->userdata('user_data');
echo $user_data['uniq']; /// 2
$flexi_auth = $this->session->userdata('flexi_auth');
echo $flexi_auth['user_id']; /// 2
If you're trying to target a string directly
echo $this->session->userdata('last_activity');
You can simply access user name stored in session like this
echo $this->session->userdata['user_data']['name'];
Be sure you have some userdata in session or use like this to avoid any errors
echo #$this->session->userdata['user_data']['name'];
adding # does not generate any errors. hope you got the answer you were looking for.

K2 extra fields access in BT Content slider

I'm trying to access the contents of a K2 extra field inside the BT content slider plugin. If I do
print_r($row->extra_fields);
I get
[{"id":"16","value":"http:\/\/www.youblisher.com\/p\/611670-Test-Intro-to-R\/"}]
I need to access the value, but I've tried everything I could think of with no luck.
Tests I've done (also tried print_r for everything just in case):
echo $row->extra_fields[0]
echo $row->extra_fields[0]->value
echo $row->extra_fields->value
echo $row->extra_fields["value"]
Decode your string into a json object first before trying to access value.
<?php
$json = json_decode('[{"id":"16","value":"http:\/\/www.youblisher.com\/p\/611670-Test- Intro-to-R\/"}]');
print_r($json[0]->value);
?>
OK, I got it working the way I wanted it to.
I wanted to replace intro / full text with an extrafield that I called 'Accroche' . This extrafield has an ID of 132 (useful to know the ID that will be used in code below).
We will be editing 2 files :
/modules/mod_bt_contentslider/classes/content.php
and
/modules/mod_bt_contentslider/classes/k2.php
First thing to do is get the extrafield info from database :
in /modules/mod_bt_contentslider/classes/content.php (around line 77) I added [b]a.extra_fields,[/b] as follows
$model->setState('list.select', 'a.urls, a.images, a.fulltext, a.id, a.title, a.alias, a.introtext, a.extra_fields, a.state, a.catid, a.created, a.created_by, a.created_by_alias,' . ' a.modified, a.modified_by,a.publish_up, a.publish_down, a.attribs, a.metadata, a.metakey, a.metadesc, a.access,' . ' a.hits, a.featured,' . ' LENGTH(a.fulltext) AS readmore');
Save file & close
Now lets get to /modules/mod_bt_contentslider/classes/k2.php (around line 234),
Replace this original code
// cut introtext
if ($limitDescriptionBy == 'word') {
$item->description = self::substrword($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
$item->description = self::substring($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
}
$item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
// get author name & link
With this code that I've commented to make things understandable for noobs like me ;)
// REPLACE intro/full text With extra-field info
$extras = json_decode($item->extra_fields); // JSON Array we'll call extras (note final 's' : not to confuse with below variable)
foreach ($extras as $key=>$extraField): //Get values from array
if($extraField->value != ''): //If not empty
if($extraField->id == '132'): // This is ID value for extrafield I want to show --- Search your K2 extrafield's id in Joomla backoffice ->K2 ->extrafields ---
if($extraField->value != ''): // If there's content in the extrafield of that ID
$extra = $extraField->value; //Give $extra that value so we can hand it down below
endif;
endif;
endif;
endforeach;
// cut introtext
if ($limitDescriptionBy == 'word') {
// $item->description = self::substrword($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
$item->description = self::substrword($extra, $maxDesciption, $replacer, $isStrips, $stringtags);
} else {
// $item->description = self::substring($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
$item->description = self::substring($extra, $maxDesciption, $replacer, $isStrips, $stringtags) ;
}
$item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
// get author name & link
As you can see, I've commented out the intro texts as I don't want them. You can modify that if you want both introtext AND extrafield.
I'd have never figured this out without the JSON tip given above. Thanx to all :)
Hope this helps.
Cheers !

How to echo the number of reviews of the product on the product page in Magento?

I am unable to echo the number of my products reviews on one of my tabs.
Now the title of my reviews tab is Product’s Reviews and I would like to change it to Reviews(0)
I need to have a number of reviews in the brackets.
How to echo the nuber of reviews from this product?
FYI this is NOT working for me:
<?php echo $this->__(\'%d Review(s)\', $this->getReviewsCount()) ?>
Try the following code ( the code taken from Inchoo.com site ) :
// Get product review info (independent) of review page
<?php
$storeId = Mage::app()->getStore()->getId();
$summaryData = Mage::getModel('review/review_summary')
->setStoreId($storeId)
->load($_product->getId());
/* #var $summaryData Mage_Review_Model_Review_Summary */
/*
array(
['primary_id'] => 147
['entity_pk_value'] => 166
['entity_type'] => 1
['reviews_count'] => 1
['rating_summary'] => 80
['store_id'] => 1
)
*/
?>
and Echo this as <?php echo $summaryData['reviews_count']; ?>
$reviewsCount = Mage::getModel('review/review')
->getTotalReviews($product_id, true, Mage::app()->getStore()->getId());
i followed the code from Mage_Rating_Block_Entity_Detailed
as the second argument is set true in getTotalReviews so it will only get count of approved reviews.
i have found that the review summary count and ratings are taken from the code ...
$product=166;//demo product id
$storeId=Mage::app()->getStore()->getId();
$product=Mage::getModel('catalog/product')->load($product_id);
$product_review=Mage::getModel('review/review_summary')
->setStoreId($storeId)
->load($product_id);
echo $val->getReviewsCount();
echo $val->getRatingSummary();
Please try very simple code It's work for me.
<?php echo $this->getReviewsSummaryHtml($_product, 'short')?>
It's look like attached screenshot.

Resources