I'm trying to use the directory_map('source directory',false) function to scan through user uploaded folders/files. It works and spit out the result in a multilevel array format.
I wouldn't know how deep is the multi level array would be. How do I iterate the array and display it in a readable format (e.g. in html (ol/ul) tags)?
Recursive functions, whoop!
Here is an example of a recursive function being used in one of my view files.
<tbody>
<?php function album_row($albums, $parent, $lvl) { ?>
<?php if(isset($albums[$parent])) foreach ($albums[$parent] as $album): ?>
<tr>
<td><?php echo form_checkbox('action_to[]', $album->id); ?></td>
<td><?php echo repeater('-- ', $lvl);?> <?php echo $album->title;?></td>
<td><?php echo $album->num_photos;?></td>
<td><?php echo date('M d, Y', $album->updated_on);?></td>
<td><?php echo anchor('photos/' . $album->slug, lang('photo_albums.view_label'), 'target="_blank"') . ' | ' .
anchor('admin/photos/manage/' . $album->id, lang('photo_albums.manage_label')) . ' | ' .
anchor('admin/photos/edit/' . $album->id, lang('photo_albums.edit_label')) . ' | ' .
anchor('admin/photos/delete/' . $album->id, lang('photo_albums.delete_label'), array('class'=>'confirm')); ?>
</td>
</tr>
<?php album_row($albums, $album->id, $lvl+1) ?>
<?php endforeach; }?>
<?php album_row($albums, 0, 0); ?>
</tbody>
Yours will be a little different as basically you want to create a function that checks if the content is an array or a string.
If its a string, echo. If its an array, call the same function again.
Related
I would like to generate many QR code using
"Simple QrCode"
https://www.simplesoftware.io/docs/simple-qrcode
I can make one QR code like this
{!! QrCode::size(100)->generate('http://www.mywebsite.com') !!}
but how do I make alot.
I'm beginer this code looks not good. sorry.
I can make loop but loop numbers doesn't work.
<table border="1">
<?php
for ($i=1; $i<5; $i++) {
$url = "http://localhost/acex/1.php?g=". $i;
$qr = '{!! QrCode::size(100)->generate(' . $url .') !!}';
echo "link ";
echo"<br>";
?>
<tr>
<td>
<?php
echo "link ";
?>
</td>
<td>
<?php
echo $qr;
?>
</td>
<td>
<?php
echo $url;
?>
</td>
</tr>
<?php
}
?>
</table>
As you already use SimpleSoftwareIO, just write:
use SimpleSoftwareIO\QrCode\BaconQrCodeGenerator;
and put this code in your loop:
$qrcode = new BaconQrCodeGenerator;
$qrcode->size(100)->generate("your text", 'path to save file');
It worked for me.
On our Magento 1.6.2 website we have enabled Google Sitemaps and added some manually with updates through cron.
What happens now is that the page Catalog > Google Sitemap in it's filters tells us that 4 records were found.
But it doesn't show anything below the filters.
Through looking at the source code I've found that the div with class sitemapGrid only has a total height of 33px and the div with class grid that should display the sitemaps only has a total height of 7px, 6 of which are padding.
The sitemapGrid_table is 0px high, with a 1px border.
But no tr nor td.
After some more digging I've found that the file in which it all happens is design > adminhtml > default > default > template > widget > grid.phtml
The page runs till the end of the first foreach after "grid" and then stops.
<div class="grid">
<div class="hor-scroll">
<table cellspacing="0" class="data" id="<?php echo $this->getId() ?>_table">
<?php foreach ($this->getColumns() as $_column): ?>
<col <?php echo $_column->getHtmlProperty() ?> />
<?php endforeach; ?> <!-- Runs to here and then stops executing, but who knows why? -->
<?php if ($this->getHeadersVisibility() || $this->getFilterVisibility()): ?>
<thead>
<?php if ($this->getHeadersVisibility()): ?>
<tr class="headings">
<?php foreach ($this->getColumns() as $_column): ?>
<th<?php echo $_column->getHeaderHtmlProperty() ?>><span class="nobr"><?php echo $_column->getHeaderHtml() ?></span></th>
<?php endforeach; ?>
</tr>
<?php endif; ?>
<?php if ($this->getFilterVisibility()): ?>
<tr class="filter">
<?php $i=0;foreach ($this->getColumns() as $_column): ?>
<th<?php echo $_column->getHeaderHtmlProperty() ?>><?php echo $_column->getFilterHtml() ?></th>
<?php endforeach; ?>
</tr>
<?php endif ?>
</thead>
If I comment out the first foreach, the code keeps running till it ends the first foreach in "headings". And so on (comment out one, runs till end of next one, ...)
Anyone have any idea on where the problem really lies and/or a solution?
So,
Long story short:
exception.log wasn't being filled so once that was solved I got to see that Magento couldn't find a certain blocktype.
Solved an error in config.xml and it all works just fine.
I want to pass row fetched from database to view from controller.
foreach ($usertable->result() as $note) {
$note['title'];
$this->load->view('note',$note);
}
but it didn't work.
Strictly, not the right way to send data to view (not inside for loop). This will load the view the numbers of time the loop runs.
Enclosed all the notes data into a variable say via an array data['notes'] and the now in view you can use notes variable for fetching data. Read docs for more info.
In controller:
$data['notes'] = $usertable->result();
$this->load->view('note', $data);
In view:
<table>
<tr>
<td>Note id</td>
<td>title</td>
</tr>
<?php foreach($notes as $n) { ?>
<tr>
<td><?php echo $n->id; ?></td>
<td><?php echo $n->title; ?></td>
</tr>
<?php } ?>
</table>
you can use following.
foreach ($usertable->result() as $note) {
$note[]=$note;
}
$note['title'];
$this->load->view('note',$note);
This is driving me crazy. No matter what export I do using profile, the column "assocciated", as mentioned in various magento guides is missing. I have around 7000 products and need to export them with the parent/child relationship intact, however, after export it just shows all the products without any columns mentioning the relationship also link for only 1 image is shown even when there are more than 5 images.
I would like to see the configurable products with all the associated products (seperated by comma) OR simple products with the sku of configurable product.
Is there any option to accomplish this?
Thanks.
U can use this code
(please make filename.php under your web root
<?php
require_once 'app/Mage.php';
Mage::app();
//$parentProduct= Mage::getModel('catalog/product')->load('2862');
$parentCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('type_id','configurable')
->addAttributeToFilter('status','1');
//$pid = array();
$read= Mage::getSingleton('core/resource')->getConnection('core_read');
function getAttributeValue($value){
global $read;
$query = "select value from eav_attribute_option_value where option_id = '$value'";
$customAttributeValue = $read->fetchAll($query);
return $customAttributeValue[0]['value'];
}
?>
<style>
tr td{
border:1px solid black;
}
</style>
<table>
<thead>
<tr>
<td>sku</td>
<td>simple_skus</td>
<td>type</td>
<td>class</td>
<td>silos</td>
</tr>
</thead>
<tbody>
<?php
foreach($parentCollection as $parentID){
$parentProducts = Mage::getModel('catalog/product')->load($parentID->getId());
$childProducts = Mage::getModel('catalog/product_type_configurable')
->getUsedProducts(null,$parentProducts);
?>
<?php
foreach($childProducts as $child){
?>
<tr>
<td>
<?php echo $child->getSku();?>
</td>
<td>
<?php echo " "?>
</td>
<td>
<?php echo $child->getTypeId()?>
</td>
<td>
<?php
$value = $parentProducts->getClass();
echo getAttributeValue($value);
?>
</td>
<td>
<?php
$value = $parentProducts->getSilos();
echo getAttributeValue($value);
?>
</td>
</tr>
<?php }?>
<tr>
<td>
<?php echo $parentProducts->getSku();
?>
</td>
<td>
<?php
$separation = array();
foreach($childProducts as $child){
$separation[] = $child->getSku();
}
echo implode(',',$separation);
?>
</td>
<td>
<?php echo $parentProducts->getTypeId();?>
</td>
<td>
<?php
$value = $parentProducts->getClass();
echo getAttributeValue($value);
?>
</td>
<td>
<?php
$value = $parentProducts->getSilos();
echo getAttributeValue($value);
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
then browser your filename.php from your website
from that list you can convert html to csv
check this
http://www.convertcsv.com/html-table-to-csv.htm
hope this help
Magento provides export and import for configurable products from System > Import/Export > Dataflow - Profiles, please see the attached image how it's exporting configurable products
Main columns to take care about are type and has option as parent product will be assigned with has_option as 1 ,visibility as catalog, seacrh and it's child products which will assigned value for has_option as 0 , visibililty as Not Visible Individually and it's related attributes values like shoe_type , shoe_size and gender
-magmi option to import configurable products which will assign Associated products to parent product.Before this import one need to first import simple and configurable products.
I am new with codeigniter.I want to make a select dorpdown that gets its value and title from database.I tried some codes but it did not work.There are my codes:
Model
function get_sec_info(){
$records=$this->db->query('SELECT sec_id,name FROM section');
if($records->num_rows() > 0)
return $records->result();}
Controller
function sec_ifo(){
$data['rec']=$this->mymodel->get_sec_info();
$this->load->view('article',$data);}
View
<select name="section">
<?php foreach($rec as $row) {?>
<option value="<?php echo $row->sec_id?>"><?php echo $row->name ?></option>"
<?php } ?>
It does not show any error and any option to show
In your controller you are passing value like
$data['red']=$this->mymodel->get_sec_info();
and in you view you are taking value like
<?php foreach($rec as $row) {?>
So change the vairiable $rec to $red in your view like
<?php foreach($red as $row) {?>
Your option tag is badly formed. The opening option tag is missing its closing bracket, and the closing quotation mark for the option tag's value is in the wrong place.
Corrected:
<option value="<?php echo $row->sec_id?>"><?php echo $row->name ?></option>
You should use CI form helper function instead of using html code
In model
function get_sec_info()
{
$records=$this->db->query('SELECT sec_id,name FROM section');
$ret_arr = array();
if($records->num_rows() > 0)
{
while($records->result() as $r)
$ret_arr[$r->sec_id] = $r->name;
}
return $records->result();
}
In your view
echo form_dropdown("section",$rec);
Remove your code below in view:
<select name="section">
<?php foreach($rec as $row) {?>
<option value="<?php echo $row->sec_id?>"><?php echo $row->name ?></option>"
<?php } ?>
Make sure you have loaded form helper.