【问题标题】:Insert images into the menu list将图像插入菜单列表
【发布时间】:2011-07-12 05:16:12
【问题描述】:

我正在尝试在第三个菜单列表中的每一个上使用图像/徽标填充我的菜单项,请参见下面的示例。

我一直在使用 Silverstripe 来填充菜单项,下面是我到目前为止没有图像的代码。有人可以指出我如何在第三级菜单上插入图像/徽标的正确方向吗?

  // initialise plugins
  jQuery(function(){
     jQuery('ul.sf-menu').superfish();
  });

  </script>

  <ul class="sf-menu">
  <% control Menu(1) %>
     <li>
        <a href="#a">$MenuTitle</a>
         <% if Children %>
           <ul><% control Children %>
              <li>
                 <a href="#aa">$MenuTitle</a>

                  <% if Children %>
           <ul><% control Children %>
              <li>
                 <a href="#aa">$MenuTitle</a>
              </li>
              <% end_control %>

              </ul><% end_if %>
              </li>
              <% end_control %>

              </ul><% end_if %>

     <!--<li>
        <a href="#">menu item</a>
     </li>-->

        </li> <!--current-->
  <% end_control %><!--   <li>
        <a href="#">menu item</a>
     </li>   -->
  </ul> <!--sf-menu-->

非常感谢。 S:)

UPDATE 下面是我的 Page.php,我已将 $Image.SetSize(20,20) $MenuTitle 插入到我的第三级菜单中。但是,每次我尝试通过 CMS 插入图像时,CMS 中都会出现错误。对不起,我是新手,任何帮助将不胜感激。

<?php
class Page extends SiteTree {

public static $db = array(
);

public static $has_one = array(
        'MenuImage' => 'Image'
);

function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab("Root.Content.Images", new ImageField('MenuImage','Menu image'));

    return $fields;
}
}
     class Page_Controller extends ContentController {


public static $allowed_actions = array (
);

public function init() {
    parent::init();

    // Note: you should use SS template require tags inside your templates 
    // instead of putting Requirements calls here.  However these are 
    // included so that our older themes still work
    Requirements::themedCSS('layout'); 
    Requirements::themedCSS('typography'); 
    Requirements::themedCSS('form'); 
}
}

这是错误信息。

[用户错误] 无法运行查询:SELECT * FROM "Page" WHERE "ID" = 15 表 'ss_show.page' 不存在 POST /Show/admin/EditForm/field/MenuImage/EditFileForm

C:\wamp\www\Show\sapphire\core\model\MySQLDatabase.php 中的第 525 行

【问题讨论】:

  • 如何在菜单中获取图像请帮助我调整相同的菜单结构......
  • 嗨,Anudeep,我在 2.5 年前问过这个问题,抱歉我不记得当时我是怎么做的。但是,如果您使用的是 Silverstripe,请阅读我上面的更新(我认为我就是这样做的),它可能会给您一些指导。我建议您打开一个新问题来确定您的问题,有人可能会进一步帮助您。

标签: content-management-system silverstripe


【解决方案1】:

假设您的页面对象上有一个图像,您可以通过执行以下操作在模板中呈现它:

$MyImage.SetWidth(50) $MenuTitle

"$MyImage.SetWidth(50)" 将输出一个图片标签,图片大小调整为 50 像素宽。请参阅SilverStripe image reference 了解更多信息。

【讨论】:

  • 嗨 Shane,非常感谢您的提示。我已经设法在 Silverstripe 中插入了一个图像选项卡,但是每次我尝试上传图像时,上面的错误都会出现在 CMS 中。我在上面的更新下附加了我的 Page.php。我是新手,所以您的任何帮助将不胜感激。
【解决方案2】:

如果您还没有菜单图像,请按照官方文档进行操作:http://doc.silverstripe.org/sapphire/en/tutorials/2-extending-a-basic-site

【讨论】:

  • 嗨,Xeraa,感谢您的链接。我今天早上一直在关注教程,每次在 CMS 中更新图像时都会出错。请看更新,你能帮我吗?谢谢。
【解决方案3】:

我在某人的帮助下想通了。以防万一其他人处于同样的情况,那是因为我没有重建我的数据库。访问 mysite.com/dev/build 以重建数据库。更新中的上述代码在此之后有效。谢谢大家! :)

【讨论】:

  • 恭喜修复!确保接受您的答案,以便其他人可以从您的解决方案中学习。干杯~
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-24
  • 2020-12-06
相关资源
最近更新 更多