Magento - 在href中添加注册URL [英] Magento - Adding Register URL inside a href

查看:121
本文介绍了Magento - 在href中添加注册URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我是PHP的新手,我来自设计背景,但我现在正试图弄清楚一些PHP。

Hey I am very new to PHP, I come from a design background, but I am now trying to figure out some of the PHP myself.

我有一个if else语句的问题,我希望用户注册查看产品价格(登录用户可以查看价格,但其他用户会看到'请注册'模糊)。但我无法弄清楚如何让寄存器URL在一个href标签内回显。

I have a problem with a if else statement where I would like users to register to view product prices (Logged in users can view prices, but other users are presented with a 'please register' blurb). But I can't figure out how to get the register URL to echo inside the a href tag.

这是我的代码:

<?php if (Mage::getSingleton('customer/session')->isLoggedIn()) {
echo $this->getPriceHtml($_product, true);} else { echo '<a href="#">Please register to view prices</a>';}
?>


<?php echo Mage::helper('persistent')->getCreateAccountUrl($this->getCreateAccountUrl()) ?>

底部的代码用于调用注册URL。我无法弄清楚如何正确地将注册URL代码放入一个href标签中,而不会产生某种错误。任何人都可以帮忙吗?

The code on the bottom is used to call the register URL. I can't figure out how to properly place the register URL code into the a href tags without it generating some sort of error. Can anyone help?

推荐答案

<?php 
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
    echo $this->getPriceHtml($_product, true);
 } 
 else { 
    echo '<a href="'.Mage::helper('persistent')->getCreateAccountUrl($this->getCreateAccountUrl()).'">Please register to view prices</a>';
 } 

?>

试试这段代码。基本上你想要将字符串连接在一起。 Mage :: helper ...返回一个字符串。因此,将该结果与包含html链接的静态字符串结合起来。

Try this code. Basically you want to join strings together. Mage::helper... returns a string. So join that result with the static string which includes your html for a link.

对于这个问题有点深刻,但实际上我不会使用echo来显示任何html。尽可能使用php来显示动态内容。例如

Bit to deep for this question but really I would not use echo to display any html. Where possible just use php to display dynamic content. e.g.

<?php 
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
    echo $this->getPriceHtml($_product, true);
 } 
 else {  ?>
    <a href="<?php echo Mage::helper('persistent')->getCreateAccountUrl($this->getCreateAccountUrl());?>">Please register to view prices</a>
 <?php } ?>

这篇关于Magento - 在href中添加注册URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆