简体   繁体   English

在SuiteCRM中包含PHP和JS文件

[英]Include PHP and JS files in SuiteCRM

I am using SuiteCRM 7.4.3 and need to include two files (a PHP file and a JS file) into the whole project instance. 我使用的是SuiteCRM 7.4.3,需要在整个项目实例中包含两个文件(一个PHP文件和一个JS文件)。 What are the best practices in this situation? 在这种情况下,最佳做法是什么? Where should I copy the source files and where do I include them? 我应该在哪里复制源文件以及在哪里包含它们?

SuiteCRM uses its own TimeDate class which from the look of it you will need to extend to create your own (this JalaliDate). SuiteCRM使用自己的TimeDate类,从外观上你需要扩展来创建自己的(这个JalaliDate)。 Honestly, I don't know how you could implement this without affecting the core SuiteCRM massively. 老实说,我不知道如何在不影响核心SuiteCRM的情况下实现这一点。

However, the files you will need to look at are include/TimeDate.php (which is the class Suite uses for all its time formatting). 但是,您需要查看的文件包括/ TimeDate.php(这是Suite用于所有时间格式化的类)。 We always recommend that you try to make everything upgrade safe ie everything is within custom folder - however, from the look of this it won't be. 我们总是建议您尝试使所有内容升级安全,即一切都在自定义文件夹中 - 但是,从它的外观来看它不会。

But, what I usually do when I include SDK of other applications I place it in custom/include/ and then whenever I need it I link it from there. 但是,当我将其他应用程序的SDK包含在custom / include /中时,我通常会这样做,然后每当我需要它时,我都会从那里链接它。

If you need to use a javascript file SuiteCRM, You can use create a custom view that spits out the "script tags". 如果您需要使用JavaScript文件SuiteCRM,您可以使用创建一个自定义视图来吐出“脚本标记”。

class CustomModuleViewSomething extends ViewEdit
{
    function display(){
        $this->ev->process();
        $scripts = array();
        $scripts[] = '<script src="javascript1.js"></script>';
        $scripts[] = '<script src="javascript2.js"></script>';
        $scripts[] = '<script src="javascript3.js"></script>';
        echo $this->ev->display($this->showTitle) . implode($scripts);
    }
}

I have a gist which depends on moment.js in order to process dates in JS. 我有一个依赖于moment.js的要点,以便在JS中处理日期。 this is useful when you need process dates on the client side dates. 当您需要在客户端日期处理日期时,这非常有用。

/**
 * returns js Date() from a date that is in the users format
 * @depends momentjs library
 * @param datestr
 * @returns {*|Date}
 */
function toDate(datestr) {
    var $format = "", $splitformat = ["","",""], $dbformat = ["","",""];
    // Get user preferences date format
    $format = cal_date_format
    $format = $format.toUpperCase();
    $format = $format.replace('%D', 'DD')
    $format = $format.replace('%M', 'MM')
    $format = $format.replace('%Y', 'YYYY')

    // return js date
    return moment(datestr, $format).toDate()
}

The better way to handle dates is to create an action in a customController: 处理日期的更好方法是在customController中创建一个动作:

class CustomModuleController extends SugarController {
    function action_save() {
        global $timedate;
        $field = "date_entered";
        $timedate->fromString($this->bean->$field);
        $this->bean->save(!empty($this->bean->notify_on_save));
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM