Content management system 将图像插入菜单列表

Content management system 将图像插入菜单列表,content-management-system,silverstripe,Content Management System,Silverstripe,我试图在第三个菜单列表的每个菜单项上填充一个图像/徽标,请参见下面的示例 我一直在使用Silverstripe填充菜单项,下面是我迄今为止没有图像的代码。有人能告诉我如何在第三级菜单上插入图像/徽标的正确方向吗 //初始化插件 jQuery(函数(){ jQuery('ul.sf菜单').superfish(); }); 谢谢你。 S:) 更新下面是我的Page.php,我已经将$Image.SetSize(20,20)$menutile插入到我的第三级菜单中。然

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

我一直在使用Silverstripe填充菜单项,下面是我迄今为止没有图像的代码。有人能告诉我如何在第三级菜单上插入图像/徽标的正确方向吗

//初始化插件
jQuery(函数(){
jQuery('ul.sf菜单').superfish();
});

谢谢你。 S:)

更新下面是我的Page.php,我已经将$Image.SetSize(20,20)$menutile插入到我的第三级菜单中。然而,每次我试图通过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'); 
}
}

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

$MyImage.SetWidth(50)$MenuTitle


“$MyImage.SetWidth(50)”将输出一个图像标记,图像大小调整为50px宽。有关详细信息,请参阅。

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

$MyImage.SetWidth(50)$MenuTitle


“$MyImage.SetWidth(50)”将输出一个图像标记,图像大小调整为50px宽。有关更多信息,请参见。

如果您还没有菜单图像,请按照官方文档进行操作:

如果您还没有菜单图像,请按照官方文档进行操作:

我在soneone的帮助下解决了这个问题。万一其他人也遇到同样的情况,那是因为我没有重建数据库。请访问mysite.com/dev/build重建数据库。更新中的上述代码在此之后工作。谢谢大家!:)

我在索尼昂的帮助下找到了答案。万一其他人也遇到同样的情况,那是因为我没有重建数据库。请访问mysite.com/dev/build重建数据库。更新中的上述代码在此之后工作。谢谢大家!:)

嗨,Xeraa,谢谢你的链接。今天早上我一直在学习教程,每次在CMS中更新图像时都会出错。请看更新,你能帮我吗?谢谢。嗨,Xeraa,谢谢你的链接。今天早上我一直在学习教程,每次在CMS中更新图像时都会出错。请看更新,你能帮我吗?谢谢。嗨,谢恩,非常感谢你的提示。我已经设法在Silverstripe中插入了一个图像标签,但是每次我试图上传图像时,上面的错误就会在CMS中显示出来。我已经在上面的更新下附加了我的Page.php。我是新来的,非常感谢你的帮助。嗨,Shane,非常感谢你的提示。我已经设法在Silverstripe中插入了一个图像标签,但是每次我试图上传图像时,上面的错误就会在CMS中显示出来。我已经在上面的更新下附加了我的Page.php。我是新来的,所以你的任何帮助都将不胜感激。恭喜你!确保接受你的答案,以便其他人可以从你的解决方案中学习。干杯~祝贺你成功!确保接受你的答案,以便其他人可以从你的解决方案中学习。干杯~你如何能在菜单中获得图像请帮助我我正在尝试相同的菜单结构…嗨,Anudeep,我在2.5年前问过这个问题,对不起,我记不清当时是怎么做到的。不过,如果您正在使用Silverstripe(我想我就是这样做的),请阅读我上面的更新,它可能会给您一些指导。我建议你打开一个新问题来指出你的问题,也许有人可以进一步帮助你。你如何在菜单中获得图像请帮助我我尝试相同的菜单结构…嗨,Anudeep,我在2.5年前问过这个问题,对不起,我记不清当时是怎么做的。不过,如果您正在使用Silverstripe(我想我就是这样做的),请阅读我上面的更新,它可能会给您一些指导。我建议你打开一个新问题来指出你的问题,也许有人能进一步帮助你。
<?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'); 
}
}