Pass a variable to a template .phtml block in Magento - magento

This code is write in market.phtml
<?php echo $this->getLayout()->createBlock('core/template')->setData('vendorId',$vendor->getCustomerId())->setTemplate('marketplace/vendors/badge.phtml')->toHtml();?>
In Badge.php
echo $this->vendorId;
But my output is null. Is this correct way to pass data to block?

You need to change your variable like this and check it
<?php echo $this->getLayout()->createBlock('core/template')->setVendorId($vendor->getCustomerId())->setTemplate('marketplace/vendors/badge.phtml')->toHtml();?>
Now you can access this vendor ID variable in badge.phtml file like this :
<?php echo $this->getVendorId();?>

Related

How can we fetch images from database to dashboard using CodeIgniter 3

Image path is getting stored in the database and file is getting uploaded in the upload path but the image is not displaying in the tabular format.
Here is the code for the view:
<tbody>
<?php
$query = $this->db->query("SELECT * FROM banner_mgmt LIMIT 1");
// $url = base_url().
foreach ($query->result() as $row)
{
echo "<tr>";
echo "<td>$row->id</td>";
echo "<td>$row->banner_name</td>";
echo "<td>".'<img src="base_url().$row->banner_image" style="height:150px; width:150px;" alt="not found">'."</td>";
echo "<td>$row->banner_image</td>";
echo "</tr>";
}
?>
</tbody>
Assuming that base_url().$row->banner_image does actually result in a correct path/image name...
You need to check your string concatenation.
What you have... (overly complicated)
echo "<td>".'<img src="base_url().$row->banner_image" style="height:150px; width:150px;" alt="not found">'."</td>";
What you should have...
echo '<td><img src ="'.base_url().$row->banner_image.'" style="height:150px; width:150px;" alt="not found"></td>';
You need to think about how you want the string to turn out, which helps you determine when and where to use ', " and . properly.
Here I am wrapping the string using ' (single quotes), which allows me to use " (double quotes) in the HTML properties without much effort.
Read up on how to use base_url() in the Codeigniter user guide...
So you could have
echo '<td><img src ="'.base_url($row->banner_image).'" style="height:150px; width:150px;" alt="not found"></td>';
You could even use " (double quotes) which evaluate php but you will need to escape any 'internal' double quotes you want to display.
echo "<td><img src =\"base_url($row->banner_image)\" style=\"height:150px; width:150px;\" alt=\"not found\"></td>";
So, you need to read the answer at What is the difference between single-quoted and double-quoted strings in PHP?

How To Echo If Variable = something?

#echo off
set/p=password
if %password%=random echo password correct
How Do I Echo It?
I Keep Getting An Error
Basically the syntay for if is:
if %variable%==content echo blabla
But you should write
if "%variable%"=="content" ....
to prevent a syntax error if the input is empty.

Bash - How to read content of file into variable, the file was read from key->value property file?

I have one key->value property file (my.prop) with such a content:
ROOT_PATH = /opt/user1/
REL_PATH = data/folder1/
CONF_FILENAME = my.conf
In my bash script I simply read this file, like this:
#!/bin/bash
PROP_FILE='my.prop'
ROOT_PATH =''
REL_PATH=''
CONF_FILENAME=''
while read -r key eq value; do
case $key in
"ROOT_PATH")
ROOT_PATH=${value}
;;
case $key in
"REL_PATH")
REL_PATH=${value}
;;
case $key in
"CONF_FILENAME")
CONF_FILENAME=${value}
;;
esac
done < $PROP_FILE
After that I would like to form the path to my.conf file and read its content to some variable, like this:
CONF_FULL_PATH=$ROOT_PATH$REL_PATH$CONF_FILENAME
CONF_FILE_CONTENT=`cat ${CONF_FULL_PATH}`
If I print out CONF_FULL_PATH variable it will have some trash inside (parts of all three sub paths).
And at this lineCONF_FILE_CONTENT=`cat ${CONF_FULL_PATH}` I will have this error message - : No such file or directoryta/folder1/
So, my question is, how could I properly form the path to my.conf file and put its content to some specific variable? I already tried source command as a replacement for while loop. Also to build a proper path string I've used this statements:
$(dirname $ROOT_PATH)/$(dirname REL_PATH)/$(basename $CONF_FILENAME) but this looks odd for my point of view.
Any help would be great!
If you remove the spaces from your my.prop file, you can use source (or .) to read the variables inside it. This will make it much easier.
my.prop:
ROOT_PATH=/opt/user1/
REL_PATH=data/folder1/
CONF_FILENAME=my.conf
Then you can use these directly in your script:
#!/bin/bash
. my.prop
CONF_FULL_PATH="${ROOT_PATH}${REL_PATH}${CONF_FILENAME}"
CONF_FILE_CONTENT=$(cat "$CONF_FULL_PATH")

How to use magento Mage.php file path in wordpress plugin "mage enabler"?

I am facing a small problem.I need the absolute path of Mage.php file in app folder.
I am using /pinktaff.u1163.cartikahosting.com/app/Mage.php in wordpress plugin "mage enabler"
but it is showing invalid..Can anyyou please help me out.
More than likely /pinktaff.u1163.cartikahosting.com is not the full path to your document root
In magento create a blank php file in the site root and add the code below
<?php echo $_SERVER['DOCUMENT_ROOT']; ? >
See http://www.seomad.com/SEOBlog/find-out-the-root-path-on-your-server-in-php.html
Or
dirname(__FILE__)
see http://php.net/manual/en/function.dirname.php
You could also test to see if the path is correct by doing
<?php
$filename = '/pinktaff.u1163.cartikahosting.com/app/Mage.php';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>

Create variables for unknown amount of arguments?

Working on an rsync script and the portion below is in a for loop. What I want to achieve is assign a variable to every arguement after 3. Just confused if I need to create another loop for that or not:
#1: name
name=$1
#2: ip
ip=$2
#3: user
user=$3
#4+: folder exlusion
#any lines higher than 3 will be created as exlcude folders
ex[ARG_NUMBER]=
Make an array like this:
ex=("${#:4}")
There might be a cleaner way, but something like this should work:
function foo() {
name=$1
ip=$2
user=$3
rest=${#:4}
echo "User " $user
echo "Rest " $rest
}

Resources