语言和开发规则: Difference between revisions

Jump to navigation Jump to search
No edit summary
Tag: 2017 source edit
Line 352: Line 352:


==基本迁移规则==
==基本迁移规则==
结构迁移脚本是install/mysql/migration/a.b.c-x.y.z.sql类型的文件。在从n到n+1的迁移文件中,只有在从n+1版本迁移到n+2版本时,才销毁n+1中不再使用的表(drop table)。这是为了在版本期间始终保留不推荐使用的表,以便在迁移错误的情况下修复情况。
结构迁移脚本是 '''install/mysql/migration/a.b.c-x.y.z.sql''' 类型的文件。在从n到n+1的迁移文件中,只有在从n+1版本迁移到n+2版本时,才会销毁在n+1中不再使用的表(drop table)。这是为了在版本升级期间始终保留过时的表,以便在发生升级错误的情况下能回退到原版本。


==Mysql 特点==
==Mysql/MariaDB 特性==


*Tables must be declared with format InnoDB.
*表必须使用 InnoDB 格式声明


This format supports foreign keys and their restrictions, and transactions integrity is also supported. This guarantees that Dolibarr events keep all data with correct values between tables even when transaction modify different tables.
实际上,此格式支持外键、附加到外键的任何约束以及使数据在表之间具有一致性所需的事务完整性概念。


*Dolibarr MUST work even if Mysql option '''strict''' is active.
这保证了 Dolibarr 操作在表之间保存了正确的数据,即使事务修改了不同的表也是如此。


To activate it (required when developing on Dolibarr), add the following line into the config file of your Mysql server (my.cnf or my.ini)
*即使 Mysql 的 '''strict''' 选项被激活,Dolibarr也必须能正常工作
 
要启用它(强烈建议在Dolibarr开发中使用),请在MySQL服务器配置文件(my.cnf 或 my.ini)中添加以下行:
{{MySqlStrictMode}}
{{MySqlStrictMode}}


==PostgreSQL specificities==
==PostgreSQL 特性==
Only Mysql SQL files must be maintained.
只需要维护 MySQL 的文件。其他数据库的文件由数据库的Dolibarr驱动程序“动态”转换。
Those files are converted "on the fly" by the database Dolibarr driver.
 
有一个例外,就是 SQL "UPDATE FROM":


There is an exception
MySQL 语法:
The SQL "UPDATE FROM":


MySQL Syntax:
<syntaxhighlight lang="sql">
<syntaxhighlight lang="sql">
UPDATE table_taget as target, table_source as source SET fieldtarget=source.fieldsource
UPDATE table_taget as target, table_source as source SET fieldtarget=source.fieldsource
Line 378: Line 379:
</syntaxhighlight>
</syntaxhighlight>


PgSQL Syntax:
PgSQL 语法:
 
<syntaxhighlight lang="sql">
<syntaxhighlight lang="sql">
UPDATE table_taget as target SET fieldtarget=source.fieldsource
UPDATE table_taget as target SET fieldtarget=source.fieldsource
Line 384: Line 386:
</syntaxhighlight>
</syntaxhighlight>


There is no native SQL request "update from" in dolibarr core. But in your module you should do :
在dolibarr内核中没有本地化“update from”。但对于您的模块,您应该这样做:
 
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
if ($this->db->type=='pgsql') {
if ($this->db->type=='pgsql') {
Line 395: Line 398:
</syntaxhighlight>
</syntaxhighlight>


=HTML 规范=
=规范 HTML=
==语法规则==
==语法规则==


*HTML used must be HTML compliant and not XHTML. All attributes of HTML tags must be in lower case and quoted with ".
*使用的 HTML 必须符合 HTML 标准,而不是 XHTML。HTML标记中的所有属性都必须 '''小写''' ,并使用 '''双引号''' 括起来。
 
*href 链接必须是绝对路径,请使用函数 dol_buildpath() 从htdocs目录的相对路径(对于外部模块)或使用 DOL_URL_ROOT(对于核心代码)获取绝对路径。对于img标记,必须调用 img_picto() 。


*Links href must be absolute and use the function dol_buildpath() to get absolute path from a relative path and img tag must be build using function img_picto().
示例:


For example:
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
print '<a href="'.dol_buildpath('/mydir/mypage.php').'">'.img_picto('Texte alt','namepictopng','').'</a>';
print '<a href="'.dol_buildpath('/mydir/mypage.php').'">'.img_picto('Texte alt','namepictopng','').'</a>';
</syntaxhighlight>
</syntaxhighlight>


*HTML tables must have columns with no forced width, except for columns that contains data we know the length. For example, a column with a picto only can be forced to with="20px".
*HTML tables 必须具有没有强制宽度的列,但包含非可变长度信息的列除外。例如,带有 picto 的列可以强制为with=“20px”。


Otherwise, we must avoid forcing the column width. Reason is that, in most cases, the browser make a better works to define column width automatically than forced values, and it works whatever is the resolution.
在其他情况下,应避免强制列的宽度。原因是,在大多数情况下,浏览器在自动设置正确的列宽度方面比手动强制宽度做得更好。并且无论屏幕分辨率如何,它都可以正常工作。


*Javascript/ajax code and call to javascript files into php pages must be avoided. However, if you need to include javascript code, you must add a condition on "$conf->use_javascript_ajax"
*应避免在PHP页面中使用Javascript/ajax和Java脚本。但是,如果需要包含 javascript代码,则必须先对 "$conf->use_javascript_ajax" 进行条件判断:


<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
Line 419: Line 423:
</syntaxhighlight>
</syntaxhighlight>


*Popup windows must not be used, except for tooltips (and must have a condition as explained before).
*不应使用 Windows 弹出窗口,但工具提示除外(并且仍受上述条件的限制)。


*External scripts must be written in Perl if they can't be written in PHP. Usage of another language is not forbidden but must be argued before in the development mailing-list.
*外部脚本是用Perl编写的,如果它们不能用PHP编写的话,则不禁止使用其他语言,但必须事先在开发人员的邮件列表中讨论。


==外部模板框架?==
==外部模板框架?==
There is ton of frameworks to provide a templating language of an HTML page. The best and faster is just called "PHP", and because Dolibarr already depends on PHP, there is no need to introduce a dependency on a third language.
有大量的框架可以提供HTML页面的模板语言(smarty,twig,...)。我们所知道的最好和更快的只有被称为“PHP”的,并且由于Dolibarr已经依赖于PHP,因此没有必要引入对第三种语言的依赖来制作模板。
 
所有模板框架都只是预处理器,BEFORE PHP。它不可能比单用PHP更快。当我们说“速度提高是因为模板框架使用了缓存”时,你必须了解一个事实“框架花费的超时时间是由缓存减少的,而不是处理 PHP 文件的速度”。我们应该说“任何模板框架在 PHP 上都有重载,模板框架的缓存只是减少了使用这个框架的减慢效果”,而不是“速度提高了,与纯 PHP 相比总是降低的”。
 
最重要的是,通过做一个“'''.tpl.php'''”文件,完全可以拥有一个模板系统,该文件不包含任何逻辑代码,而只包含HTML和"echo"。我们得到相同的结果(但更快、更容易开发,因为它不需要在调用每个模板之前完成所有的 setXXX)。所有变量(由包含模板的代码所知的)都会自动被 PHP 模板页面所知。没有忘记集合的风险,减少了大量代码行,也节省了大量时间和开发错误。
 
此外,在以下一种情况下,保证代码和 HTML 输出之间 100% 的隔离是有趣的:当团队构建设计与团队构建逻辑代码完全不同时,如果您构建不太复杂的页面,并且不需要太多的 Ajax 功能(这需要知道代码是如何工作的)。


All templating frameworks are just preprocessor, BEFORE PHP. It can't be faster than PHP alone. When we say "speed is increased because templating framework use a cache", you must read in fact "the overtime spent by the framework is reduced by cache, not the speed of processing PHP file". We should say "any templating framework has an overload over PHP, the cache of framework, just reduce the slowing effect of having this framework", but not "the speed is increased, it is always decreased compared to pure PHP".
而且这种情况肯定不是Dolibarr的未来(团队经常会是一样的,Ajax会越来越多,事件,如果我希望不是太多,屏幕越来越依赖于动态或上下文事件,很难用一个简单的模板来做到这一点,而不将模板转换为具有高级代码的页面)。还要设计现在在 CSS 端而不是 PHP 端进行更多管理。


Above all, having a templating system is completely possible by doing a "'''.tpl.php'''" file that dos not contains any logic code, but only HTML and "echo". We get same result (but faster and easier to develop because it does not need to do all the setXXX before calling each template). All variables (known by code that include the template) are automaticaly known into a PHP template page. No risk to forget a set, and a lot of line of codes reduced, a lot of time and development errors are also saved.
过去,Dolibarr已经尝试过像smarty这样的模板系统。如果在纸上这个想法是好的,我们很快意识到发现错误变得令人头疼,编码成为寻宝,维护和开发做得太慢(与以前输出模板进入每个 PHP 文件的“视图”部分的情况相比),我们忘记了这个想法。实用主义造就了规则。


Also, keeping a 100% isolation between code and HTML output is interesting in only 1 situation: When teams building design is complety different than team building logic code, AND if you build not too sophisticated pages, AND with no need of too many Ajax features (this need to know how code works).
不使用外部模板系统还有很多其他原因,使用它们的所有参数也是使用 HTML/PHP 作为我们的模板系统的最佳参数。我们只是要求在'''控制器'''(PHP 页面的第一部分就在 /* Action */ 行之后)和'''视图'''(/* View */ 注释之后的第二部分)之间保持分离。
And this situation is surely not the Dolibarr future (team will often be same, Ajax will be more and more present, event if I hope not too much, and screens are more and more dependent of dynamic or contextual events, difficult to have this with onesimple template without transforming the template into a page with high level of code).


There is a ton of other reasons to not use an external templating system and all arguments to use them are also the best argument to use PHP as our templating system.
=规范 Dolibarr 和代码框架=


=Dolibarr 规范和代码框架=
==代码框架==
为了使代码标准化并加快Dolibarr中新组件的开发,可以在 '''htdocs/modulebuilder/templates''' 目录中找到。


==框架代码==
例如:
To standardize the code, and to speed up the development of new components in Dolibarr, you'll find 4 skeletons fully prepared in the directory '''dev/skeletons'''.


*1 that serves as an example of the module description: '''myModule.class.php'''
*模块描述示例  '''myModule.class.php'''
*1 that serves as an example of code for creating a new class: '''skeleton_class.class.php'''
*创建新类的代码示例  '''skeleton_class.class.php'''
*1 that serves as an example of code for creating a new page: '''skeleton_page.php'''
*创建新页面的代码示例  '''skeleton_page.php'''
*1 that serves as an example of code for creating a script for executing command lines: '''skeleton_script.php'''
*创建要在命令行上运行的脚本的代码示例 '''skeleton_script.php'''


Use it as an example.
Use it as an example.
714

edits

Navigation menu