沃梦达 / 编程问答 / php问题 / 正文

如何向现有的 joomla 2.5 组件添加新视图(以及新的菜单项类型)?

How to add a new view (and also a new Menu Item Type) to existing joomla 2.5 components?(如何向现有的 joomla 2.5 组件添加新视图(以及新的菜单项类型)?)

本文介绍了如何向现有的 joomla 2.5 组件添加新视图(以及新的菜单项类型)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我想向内容组件添加一个新的 view,以及一个新的 Menu Item Type.

Maybe I want to add a new view, and also a new Menu Item Type to content component.

请问步骤是什么?

更新

问题(来自@ValentinDespa):

您想要扩展 com_content 功能或您想要覆盖查看或构建一个新组件来做某事?

You want to extend com_content functionality or you want to override a view or to build a new component that does something?

正如我所说,我想扩展 com_content 并向其添加一个新视图.现在有一些视图,例如Single ArticleCategory BlogCategory List.

As I said, I want to extend com_content and add a new view to it. There are some views like Single Article, Category Blog, and Category List right now.

我想添加另一个名为 Article Titles 的菜单项,这样只会显示标题,但带有一些参数(如列数).

I want to add another menu items called Article Titles, so titles only will be displayed but with some parameters (like columns count).

这是当前功能无法提供的需求.

It is a need that is not supplied by current features.

注意

伙计们,我的新视图应该是什么样的并不重要,请告诉我如何创建新视图.

Guys, it doesn't matter what my new view should be like, please tell me How to create a new view.

推荐答案

是的,您可以创建新视图.

Yes You can create a new view.

很简单,只需从您的 com_content 中复制任何视图(类别、博客).

Its simple just copy any of the view (category,blog) from your com_content.

文件结构应该和文件夹里面的一样.

The file structure should be like inside the folder.

Step 1

view.html.php
tmpl
   your layout names(default.php)
xml file.
Also remember to change the class name of the view.html.php

Step 2

Add a controller file (just make a copy of existing one category or blog)
Controller name must be your new view folder name.
Also remember to change the class name of the controller

step 3 

add a model file for your new view (same make copy of any existing)
remember to change the class name and file name should be view folder name.

然后您可以通过提供正确的网址来访问此视图.例如:www.example.com/index.php?option=com_content&view=yourviewname&layout=yourlayoutnames.

Then you can access this view by giving correct url. eg: www.example.com/index.php?option=com_content&view=yourviewname&layout=yourlayoutnames.

这里我提到视图文件夹名称必须是控制器和模型文件名,我们也可以用其他名称来实现,但是当你不擅长 joomla 时,它会给你带来问题.

Here I mentioned view folder name must be controller and model file name we can achieve with other name also but it will create problem for you when you are not good in joomla.

注意:要添加视图,您根本不需要安装组件,这根本不是一个好主意.

Note: For adding a view you don't need to install a component its not a good idea at all.

您也可以在一个视图中添加多个布局在您的 tmpl 文件夹内只需创建新文件.另外不要错过控制器和模型放入 com_contents/controller 和 com_contents/model 文件夹

Also You can add multiple layouts in a view inside your tmpl folder just create new files.Also don't miss the controller and model to put in com_contents/controller and com_contents/model folder

更多帮助看看这个

这篇关于如何向现有的 joomla 2.5 组件添加新视图(以及新的菜单项类型)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何向现有的 joomla 2.5 组件添加新视图(以及新的菜单项类型)?

基础教程推荐