我目前正在创建一个 joomla 菜单模块,但我遇到了一些问题..
我正在尝试将子菜单项分成 3 列,目前我正在使用:
$counter = 0;
if($item->level == 2):
$counter += count($item);
endif;
if($item->level == 1):
$counter = 0;
endif;
if($counter%3 == 0 && $item->level == 2){
echo '</ul><ul class="col-lg-3">';
}
但这只是将它们分成 3 组
这是整个 default.php:
<?php
// No direct access
defined('_JEXEC') or die;
// Note. It is important to remove spaces between elements.
$counter = 0;
?>
<ul class="nav navbar-nav <?php echo $class_sfx; ?> nav-mega"<?php
$tag = '';
if ($params->get('tag_id') != null)
{
$tag = $params->get('tag_id') . '';
echo ' id="' . $tag . '"';
}
?>>
<?php
foreach ($list as $i => &$item) {
if($item->level == 2):
$counter += count($item);
endif;
if($item->level == 1):
$counter = 0;
endif;
$class = 'item-' . $item->id;
if ($item->id == $active_id) {
$class .= ' current';
}
if (in_array($item->id, $path)){
$class .= ' active';
}elseif ($item->type == 'alias'){
$aliasToId = $item->params->get('aliasoptions');
if (count($path) > 0 && $aliasToId == $path[count($path) - 1]) {
$class .= ' active';
}elseif (in_array($aliasToId, $path)){
$class .= ' alias-parent-active';
}
}
if ($item->deeper){
$class .= ' deeper dropdown';
}
if ($item->parent){
$class .= ' parent';
}
if (!empty($class)){
$class = ' class="' . trim($class) . '"';
}
echo '<li' . $class . '>';
// Render the menu item.
switch ($item->type){
case 'separator':
case 'url':
case 'component':
require JModuleHelper::getLayoutPath('mod_blogmenu', 'default_' . $item->type);
break;
default:
require JModuleHelper::getLayoutPath('mod_blogmenu', 'default_url');
break;
}
// The next item is deeper.
if($counter%3 == 0 && $item->level == 2){
echo '</ul><ul class="col-lg-3">';
}
if ($item->deeper){
echo '<div class="dropdown-menu mega-dropdown">';
echo '<div class="mega-image col-lg-3 thumbnail visible-md visible-lg"><img src="'.$item->menu_image.'" /></div>';
echo '<ul class="col-lg-3">';
}
// The next item is shallower.
elseif ($item->shallower){
echo str_repeat('</ul><div class="mega-caption"></div></div>', $item->level_diff);
}
// The next item is on the same level.
else {
//echo '</li>';
}
}
?>
</ul>
抱歉了很多代码;我仍在努力学习 PHP 并努力理解 Joomla 的做事方式,这对我来说并不容易。
最佳答案
在循环遍历所有菜单项之前,计算每个菜单项的所有子菜单项。 (免责声明:我不了解 Joomla 菜单,但我希望 $item->parent->id 引用父项的 id。)
$submenuItemsTotals = array();
foreach ($list as $i => &$item) {
if ($item->level == 2) {
if (!isset($submenuItemsTotal[$item->parent->id])) {
$submenuItemsTotal[$item->parent->id] = 1;
} else {
$submenuItemsTotal[$item->parent->id]++;
}
}
}
$itemsPerColumn = array();
foreach ($submenuItemsTotals as $parentId => $submenuItemsTotal) {
$itemsPerColumn[$parentId] = ceil($submenuItemsTotal / 3);
}
// Here comes your existing code with a small change
foreach ($list as $i => &$item) {
[your code....]
// The next item is deeper.
if($item->level == 2 && ($counter % $itemsPerColumn[$item->parent->id]) == 0){
echo '</ul><ul class="col-lg-3">';
}
[your code....]
}
关于PHP 将 ul 平均分成 3 列 Joomla 菜单模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19011542/
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
我有一个包含模块的模型。我想在模块中覆盖模型的访问器方法。例如:classBlah这显然行不通。有什么想法可以实现吗? 最佳答案 您的代码看起来是正确的。我们正在毫无困难地使用这个确切的模式。如果我没记错的话,Rails使用#method_missing作为属性setter,因此您的模块将优先,阻止ActiveRecord的setter。如果您正在使用ActiveSupport::Concern(参见thisblogpost),那么您的实例方法需要进入一个特殊的模块:classBlah
我刚刚被困在这个问题上一段时间了。以这个基地为例:moduleTopclassTestendmoduleFooendend稍后,我可以通过这样做在Foo中定义扩展Test的类:moduleTopmoduleFooclassSomeTest但是,如果我尝试通过使用::指定模块来最小化缩进:moduleTop::FooclassFailure这失败了:NameError:uninitializedconstantTop::Foo::Test这是一个错误,还是仅仅是Ruby解析变量名的方式的逻辑结果? 最佳答案 Isthisabug,or
我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c
我的假设是moduleAmoduleBendend和moduleA::Bend是一样的。我能够从thisblog找到解决方案,thisSOthread和andthisSOthread.为什么以及什么时候应该更喜欢紧凑语法A::B而不是另一个,因为它显然有一个缺点?我有一种直觉,它可能与性能有关,因为在更多命名空间中查找常量需要更多计算。但是我无法通过对普通类进行基准测试来验证这一点。 最佳答案 这两种写作方法经常被混淆。首先要说的是,据我所知,没有可衡量的性能差异。(在下面的书面示例中不断查找)最明显的区别,可能也是最著名的,是你的
我一直致力于让我们的Rails2.3.8应用程序在JRuby下正确运行。一切正常,直到我启用config.threadsafe!以实现JRuby提供的并发性。这导致lib/中的模块和类不再自动加载。使用config.threadsafe!启用:$rubyscript/runner-eproduction'pSim::Sim200Provisioner'/Users/amchale/.rvm/gems/jruby-1.5.1@web-services/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:105:in`co
我有一个Controller,我想为这个Controller创建一个助手,我可以在不包含它的情况下使用它。我尝试像这样创建一个与Controller同名的助手classCars::EnginesController我创建的助手是moduleCars::EnginesHelperdefcheck_fuellogger.debug("chekingfuel")endend我得到的错误是undefinedlocalvariableormethod`check_fuel'for#有没有我遗漏的约定? 最佳答案 如果你真的想在Controll
我有一个模块stat存在于目录结构中:lib/stat_creator/stat/在lib/stat_creator/stat.rb中,我在lib/stat_creator/stat/目录中有我需要的文件,以及:moduleStatCreatormoduleStatendend当我使用该模块时,我将这些类称为StatCreator::Stat::Foo.new现在我想要一个存在于应用程序中的根Stat类。我在app/models中制作了我的Stat类,并在routes.rb中进行了设置。但是,如果我转到Rails控制台并尝试在应用程序/模型中使用Stat类,例如:Stat.by_use
这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Testingmodulesinrspec目前我正在使用rspec成功测试我的模块,如下所示:require'spec_helper'moduleServicesmoduleAppServicedescribeAppServicedodescribe"authenticate"doit"shouldauthenticatetheuser"dopending"authenticatetheuser"endendendendend我的模块位于应用程序/服务/services.rb应用程序/服务/app_servi