search
HomeBackend DevelopmentPHP TutorialSummary research on commonly used classes in joomla2.5, summary of joomla2.5 classes_PHP tutorial

Summary study of commonly used classes in joomla2.5, summary of joomla2.5 classes

The previous article only studied the JImage class. Today we will continue with other commonly used joomla built-in classes. Personally, I started with the commonly used classes. It is written from the perspective of using PHP itself. If PHP’s own functions are more convenient to use than Joomla’s built-in classes, I will not filter it out. If you really want to use it, check it out yourself. Personally, I feel that no matter how excellent the method is, if PHP’s own functions It can also be solved easily with functions, so it is best to use PHP built-in functions. The first thing to learn PHP is to learn the built-in functions well. Okay, let’s explain in detail the commonly used classes and methods.

1. Document class, used as the main operation on the head of the current page element.

Summary research on commonly used classes in joomla2.5, summary of joomla2.5 classes_PHP tutorial
<span>$document</span> = JFactory::<span>getDocument();
</span><span>$document</span>->addScript('1.js');<span>//</span><span>添加js文件</span>
<span>$document</span>->addScriptDeclaration('alert(1)');<span>//</span><span>添加js代码</span>
<span>$document</span>->addStyleDeclaration(); <span>//</span><span>css</span>
<span>$document</span>->addStyleSheet('1.css'<span>);
</span><span>$document</span>->setMetaData('description','关键字');<span>//</span><span>设置描述或关键字</span>
<span>$document</span>->setCharset('utf-8'<span>);
</span><span>$document</span>->setTitle('标题');
Summary research on commonly used classes in joomla2.5, summary of joomla2.5 classes_PHP tutorial

2. File operation requires importing jimport('joomla.filesystem.file');

Summary research on commonly used classes in joomla2.5, summary of joomla2.5 classes_PHP tutorial
<span>$j</span> = <span>new</span><span> JFile();
getExt(</span><span>$file</span>) <span>//</span><span>获取扩展名不含.</span>
getName(<span>$file</span>) <span>//</span><span>获得文件名</span>
exists(<span>$file</span>) <span>//</span><span>文件是否存在</span>
delete(<span>$file</span>) <span>//</span><span>删除文件</span>
<span>copy</span>(<span>$old</span>,<span>$new</span>) <span>//</span><span>复制</span>
upload(<span>$src</span>) <span>//</span><span>上传</span>
write(<span>$file</span>) <span>//</span><span>写文件</span>
read(<span>$file</span>)  <span>//</span><span>读文件</span>
move(<span>$old</span>,<span>$new</span>) <span>//</span><span>移动文件</span>
Summary research on commonly used classes in joomla2.5, summary of joomla2.5 classes_PHP tutorial

These methods are useful in file reading and writing, image file uploading, etc.

3. Folder operation, jimport('joomla.filesystem.folder'); Generally when we import, we import all files and folders, and we often use it

Summary research on commonly used classes in joomla2.5, summary of joomla2.5 classes_PHP tutorial
JFolder::create(<span>$path</span>,777) <span>//</span><span>创建文件夹,支持多层</span>
JFolder::delete(<span>$path</span>)  <span>//</span><span>删除文件夹,可以包含文件</span>
JFolder::exists(<span>$path</span>)  <span>//</span><span>检测文件夹是否存在</span>
JFolder::<span>copy</span>(<span>$pathold</span>,<span>$pathnew</span>) <span>//</span><span>复制文件夹</span>
JFolder::files(<span>$path</span>) <span>//</span><span>列出文件夹下面文件的数组</span>
JFolder::folders(<span>$path</span>) <span>//</span><span>列出文件夹下面文件夹的数组</span>
Summary research on commonly used classes in joomla2.5, summary of joomla2.5 classes_PHP tutorial

Let me talk about it here:: It is a static method, and there are many classes that support static methods;

4. Icon generation class, used to generate small icons in the background. One of the commonly used saves is one.

Summary research on commonly used classes in joomla2.5, summary of joomla2.5 classes_PHP tutorial
JToolBarHelper::title(JText::_('添加个人信息'), 'weblinks.png');<span>//</span><span>标题</span>
JToolBarHelper::addNew('info.add');<span>//</span><span>添加</span>
JToolBarHelper::apply('info.apply');<span>//</span><span>保存</span>
JToolBarHelper::save('info.save');<span>//</span><span>保存关闭</span>
JToolBarHelper::editList('info.edit');<span>//</span><span>编辑</span>
JToolBarHelper::cancel('info.cancel');<span>//</span><span>取消</span>
JToolBarHelper::deleteList('info.delete');<span>//</span><span>删除</span>
JToolBarHelper::trash('info.trash');<span>//</span><span>回收站</span>
JToolBarHelper::divider();<span>//</span><span>分割线</span>
JToolBarHelper::publish('weblinks.publish', 'JTOOLBAR_PUBLISH', <span>true</span>);<span>//</span><span>发布</span>
JToolBarHelper::unpublish('weblinks.unpublish', 'JTOOLBAR_UNPUBLISH', <span>true</span>);<span>//</span><span>取消发布</span>
JToolBarHelper::back();<span>//</span><span>返回</span>
JToolBarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS');<span>//</span><span>帮助</span>
Summary research on commonly used classes in joomla2.5, summary of joomla2.5 classes_PHP tutorial

5. Other commonly used methods

Summary research on commonly used classes in joomla2.5, summary of joomla2.5 classes_PHP tutorial
JString::transcode('中国','utf-8','gb2312');<span>//</span><span>转换编码</span>
JUtility::getToken();<span>//</span><span>用户session ID 等价于JHtml::_('form.token');</span>
JUtility::isWinos();<span>//</span><span>是否win系统 是输出1</span>
JUtility::sendmail('logove#qq.com','yoby','logoove#foxmail.com','主题','这是内容');<span>//</span><span>发送邮件要配置的</span>
JUtility::gethash(<span>$var</span>);<span>//</span><span>32位随机字符</span>
JUtility::return_bytes('1k');<span>//</span><span>转换成字节数 支持g m k</span>
JRequest::getURI();<span>//</span><span>获得当前url</span>
    JRequest::getMethod ();<span>//</span><span>提交方式 POST 或GET</span>
    JRequest::getbool('i');<span>//</span><span>转换成布尔型</span>
    JRequest::getint('i');<span>//</span><span>取整</span>
    JRequest::getfloat('i');<span>//</span><span>转换成浮点数</span>
    JRequest::getString('i');<span>//</span><span>转成字符串</span>
    JRequest::getvar('var',<span>null</span>,'default','array');<span>//</span><span>通用,第二个是默认值,第三个是方法,有GET
    //POST FILES COOKIE ENV SERVER  最后一个是数据类型 有array int string float</span>
    JRequest::setVar('var',<span>$arr</span>);<span>//</span><span>设置,可以数组或字符</span>
    JURI::base();<span>//</span><span>包含administrator绝对路径 参数1是相对路径</span>
    JURI::root();<span>//</span><span>根目录,参数1是相对路径</span>
Summary research on commonly used classes in joomla2.5, summary of joomla2.5 classes_PHP tutorial

6. Arrays are commonly used, this is the most commonly used

Summary research on commonly used classes in joomla2.5, summary of joomla2.5 classes_PHP tutorial
JArrayHelper::arrayUnique(<span>$arr2</span>);<span>//</span><span>去掉重复元素</span>
    <span>$obj</span> = <span>new</span><span> stdClass();
    </span><span>$obj</span>->qq='280594236'<span>;
    JArrayHelper</span>::fromObject(<span>$obj</span>);<span>//</span><span>对象转换数组</span>
    JArrayHelper::getValue(<span>$arr</span>,1);<span>//</span><span>获得数组第二个值,也可以是下标</span>
    JArrayHelper::toObject(<span>$arr</span>);<span>//</span><span>转换对象</span>
    JArrayHelper::toString(<span>$arr</span>,'=',' ');<span>//</span><span>转成字符串,空格隔开,左边key=value</span>
    JArrayHelper :: toInteger(<span>$cid</span>);<span>//</span><span>转换变量为整形</span>
Summary research on commonly used classes in joomla2.5, summary of joomla2.5 classes_PHP tutorial

There are many other methods, such as database, xml, form generation, etc. These are all important, but there is too much content. I will talk about it later when I have the opportunity. Basically, these methods today are all commonly used. , if you need to know more, you need to study the API content yourself, or read the core code yourself. I have summarized it here, which can reduce your reading time. The comments at the back are very detailed. If you don’t understand, you can leave a message below. Joomla is A very excellent CMS, but it is not popular in China. Dedecms and discuz have more users. I will study it next time I have time. If you like CMS, don’t miss it.

(yoby original)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1137012.htmlTechArticleSummary and study of commonly used classes in joomla2.5, summary of joomla2.5 classes The previous article only studied the JImage class, continue today Other commonly used joomla built-in classes are written from a common perspective. If PHP itself functions...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the difference between absolute and idle session timeouts?What is the difference between absolute and idle session timeouts?May 03, 2025 am 12:21 AM

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

What steps would you take if sessions aren't working on your server?What steps would you take if sessions aren't working on your server?May 03, 2025 am 12:19 AM

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

What is the significance of the session_start() function?What is the significance of the session_start() function?May 03, 2025 am 12:18 AM

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

What is the importance of setting the httponly flag for session cookies?What is the importance of setting the httponly flag for session cookies?May 03, 2025 am 12:10 AM

Setting the httponly flag is crucial for session cookies because it can effectively prevent XSS attacks and protect user session information. Specifically, 1) the httponly flag prevents JavaScript from accessing cookies, 2) the flag can be set through setcookies and make_response in PHP and Flask, 3) Although it cannot be prevented from all attacks, it should be part of the overall security policy.

What problem do PHP sessions solve in web development?What problem do PHP sessions solve in web development?May 03, 2025 am 12:02 AM

PHPsessionssolvetheproblemofmaintainingstateacrossmultipleHTTPrequestsbystoringdataontheserverandassociatingitwithauniquesessionID.1)Theystoredataserver-side,typicallyinfilesordatabases,anduseasessionIDstoredinacookietoretrievedata.2)Sessionsenhances

What data can be stored in a PHP session?What data can be stored in a PHP session?May 02, 2025 am 12:17 AM

PHPsessionscanstorestrings,numbers,arrays,andobjects.1.Strings:textdatalikeusernames.2.Numbers:integersorfloatsforcounters.3.Arrays:listslikeshoppingcarts.4.Objects:complexstructuresthatareserialized.

How do you start a PHP session?How do you start a PHP session?May 02, 2025 am 12:16 AM

TostartaPHPsession,usesession_start()atthescript'sbeginning.1)Placeitbeforeanyoutputtosetthesessioncookie.2)Usesessionsforuserdatalikeloginstatusorshoppingcarts.3)RegeneratesessionIDstopreventfixationattacks.4)Considerusingadatabaseforsessionstoragei

What is session regeneration, and how does it improve security?What is session regeneration, and how does it improve security?May 02, 2025 am 12:15 AM

Session regeneration refers to generating a new session ID and invalidating the old ID when the user performs sensitive operations in case of session fixed attacks. The implementation steps include: 1. Detect sensitive operations, 2. Generate new session ID, 3. Destroy old session ID, 4. Update user-side session information.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)