Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Joomla 2.5 中创建了一个产品组件,客户希望所有产品都显示在现有菜单项产品的子菜单中,这必须通过产品组件自动完成。
产品的创建是通过 Joomla 的后端通过自定义组件视图、控制器和模型来完成的。
给定产品的 id 和名称(用于菜单显示标题),我可以轻松地创建菜单项,我的问题在于在将全新产品添加到数据库时获取产品 id。控制器或模型中是否有可以重载的方法?可以使用我错过的某种模型方法以某种方式获得此 id 吗?
干杯,松鸡
通过重载 JController 的 save 方法并在最后做修复
$db = &JFactory::getDBO(); parent::save($key, $urlVar); $id = $db->insertid(); if ($id == 0) { $id = JRequest::getInt('id', 0); }
然后将检索到的 id 传递给模型中定义的方法,并让该方法执行必要的操作。将其留在这里以供我自己和其他可能偶然发现它的人参考。