Joomla组件常备函数
- 如何获得Joomla框架的文档:
- $document =&$mainframe->getDocument();
- 如何获取URL Request的参数.
- JRequest::getVar(‘task’);
- JRequest::getVar(‘name’, ‘Joomla! 1.5.0′);
- 取得模版文件路径
- JApplicationHelper::getPath(‘front_html’, ‘com_name’)
- 设定网页的Title
- $document = &$mainframe->setPageTitle(“Example componenet”);
Joomla组件2(Joomla Component2)
1.简单的输出内容
让我们接着Joomla组件1,继续来扩充我们的Joomla Helloworld组件。
打开helloworld.php文件,输入一下内容:
<?php
// no direct access
defined(‘_JEXEC’) or die(‘Access to this file is prohibited’);
echo ‘Hello World!’;
?>
再来连接一下 http://localhost/joomla/index.php?option=com_helloworld,这次我们可以看到页面上出现Hello world。如何我们终于比前面进了一大步。
同时第一行的代码也防止非法用户直接放我门的Helloworld.php文件,此时浏览器中只会显示Access to this file is prohibited。你可以连接http://localhost/joomla/components/com_helloworld/helloworld.php来测试一下效果。:)
如果为了Joomla 1.0 或者Mambo撰写扩展,请使用_VALID_MOS代替 _JEXEC来判断用户是否直接访问。
2.接收Request的Get参数
接收Get参数,可以使用JRequest::getVar办法,函数经常使用两种格式:
- $task = JRequest::getVar(“task”);
这个例子用来获取URL task参数的值,如果无task的参数,函数会返回null。
- $name = JRequest::getVar(“name” , “Joomla test”);
这个例子用来获取URL name参数的值,如果无name的参数,函数和上个例子中不同,它会使用Joomla test作为默认值来代替null作为函数的返回值。
<?php
// no direct access
defined(‘_JEXEC’) or die(‘Access to this file is prohibited’);
// load the HTML View class
require_once (JApplicationHelper :: getPath(‘front_html’, com_helloworld’));
$task = JRequest::getVar(‘task’);
$name = JRequest::getVar(‘name’, ‘Joomla! 1.5.0′);
switch ($task) {
case ‘show’:
default:
hello_HTML::show($name);
break;
}
?>
Joomla的书籍
关于Joomla的书籍还不是太多。我主要在看这几本:
- Packt Publishing – Building Websites With Joomla Jan (2006)
这本书可能属于Joomla的权威著作,如果使用Joomla 1.0的版本,绝对需要去读一下,不过Joomla 1.5很多特性非常吸引人,如支持UTF-8,彻底解决了中文的问题。不过现在Joomla 1.5 还是RC2,所以为求稳定还是可以通过此书来架构Joomla 1.0的网站。
- Packt Publishing – Building Websites with Joomla 1.5 Beta1 (2007)
这本书是上本书的更新版本,不过正式版本还没出版,属于抢鲜版本。
不要以为是对1.0版本内容的部分更新,作者已经完完全全重写了这本书。从书名就可以知道主要针对的是Joomla 1.5的版本,不过由于撰写时参考的版本是1.5 Beta,所以有很多设定内容已经和实际的RC版本不同。
同时此书也增加了Template和Extension的章节,教你如何来扩展和定制你的个人网站。
最后还通过一个葡萄园的例子来手把手的交你如何建立Joomla 1.5的门户网站。
不过不足的是未能看到关于SEO内容的详细介绍,同时可能RC版的SEO 又比Beta改进过,现在对这一部份内容理解比较糊涂,经常连接的页面无法访问。
- Packt Publishing – Joomla Template Design Jun 2007
这本书出版的时间挺晚的,但内容确实教你如何修改Joomla 1.0的模版,讲的那个Dreamwaver Extensions已经无法使用.不过其中的一些概念流程还是不错,可以部分参考.如果想了解Joomla 1.5的模版定制可以参考"Building Websites with Joomla 1.5 Beta1",里面已经包含了模版定制的内容.
- Packt Publishing – Learning Joomla Extension Development May 2007
这本书就比较与时俱进,内容跳过Joomla 1.0,直接教你如何撰写1.5的Extension.由于是专门讲述Extension的,所以内容也比"Building Websites with Joomla 1.5 Beta1"具体.
如果有兴趣写Joomla 1.5 的extension,绝对值的一读.