MODX is one of CMSs (content management system) that I have been using for a long time to maintain my shogi site. Market penetration of this CMS is said to be 0.1%. As of this writing, 43% of of Web sites uses WordPress and no other CMS reach even 10% of market share. (source, w3techs.com . I actually think MODX penetration is much greater than this number, MODX does not leave big footprint to show it’s identity in front of web crawlers. -Many sites I know powered by MODX, including mine – were identified as non-CMS site by w3tech’s tool.— Nevertheless, there is no doubt WordPress dominates the CMS market)
Although both uses same language (PHP) for powering the site, MODX gives much more flexibility in site design but you need to be proficient with HTML and CSS (and JavaScript). In another word, MODX is a tool while WordPress is a product.
What I liked about MODX over WordPress at the time was a separation of PHP code and HTML. This was a long time ago so the situation might have changed on WordPress, but I have been happy with MODX since.
At the time, I also looked at Drupal and Joomra . All of them forces you to follow their interpretation of what website should be. MODX has no opinion on how you want to create Web site. You have a total freedom.
On the other hand, if the only thing you want to do with your site is blogging, there is no better solution than using WordPress.
I digressed. Back to the subject!
With a wealth of plug-ins available, your rarely need to code in PHP. When you do though, MODX separates a PHP coding part from HTML with a thing called Snippets. A snippet is then inserted in to HTML with a use of tag.
[[aSnippet]]
You can edit a snippet within MODX backend’s editor. With a plugin like ‘ACE’ there is a nominal amount of syntax checking to the PHP code. Unfortunately, I am being spoiled with convenience of IDE such as PHPStorm,
MODX backend, Snippet editor with ACE plugin
So there is a desire to be able to write a snippet code using PHPStorm and get benefits of auto-completion and methods hinting, strict error checking and warning.
Unfortunately, there is no plugin in PHPStorm for MODX or MODX plugn for PHPStorm.
When I google “MODX with PHPStorm”, there are several hits, Although none of them gave me a direct answer on what I wanted to do, I was able to put enough facts together and came up with a solution. The solution that was just waiting for me to assemble few known facts, that I have used all of them separately in the past!
1. Fact that PHPstorm can create a project using existing remote site contents, so that PHPStorm can pull all file setup from MODX site.
PHPStorm->File->New Project from Existing Files
2. Fact that PHPstorm can then start syncing file contents of my local project files to server files.
File sync options available in PHPStorm
Ok, but Snippet is stored in Database. the code is not in the file, but then,
3. Fact, MODX snippet code can be from a static file, meaning I can create a PHP file and feed it as a snippet to MODX by turning on “is Static” option and point to the file location
Is Static option is turned on for Snippet. Snippet is now fed from “static file”
Result: When I combine those 3 factors, I can create a snippet with a comfort of PHPStorm IDE environment.
Snippet now editable in PHPStormSnippet output on browser page, powered through MODX
What do I gain? Full context support and code hinting, as PHPStorm analyzes whole MODX site and figures out all variables and object and its methods being used inside MODX. I have to give credit to MODX development team for fully documenting source files. Thank you!
PHPstorm explains what getOption method isPHPStorm autocomplete support in action.
You can also open the corresponding file by pointing to method and do control-b to drill down on function.
I edit a file in PHPStorm, and you either 1) turn on auto-sync between your local files and server files or 2) manually upload changed file to server. Then I can run and test the snippet with MODX backend immediately.
So all of the sudden, I feel like invincible. It will be very hard for me to make coding error. (Ok, logic error still possible)
Once Snippet development is done, you may switch off the ‘is static’ option and keep the snippet inside database, remove the php file from the system.
One thing that is kind of annoying is that by default, PHPstorm thinks $modx variable is undefined. The default setting on PHPStorm’s inspections on undefined variable is somewhat on conservative side. It will not even acknowledge variables from included file!. To mitigate this, you need to put a check on “Search for variable’s definition outside the current file”
// This is function factory
$create_multiplier = function($y){
return function($x) use ($y) {
return $x * $y;
};
};
//use the function factory to create three functions.
$double = $create_multiplier(2);
$triple = $create_multiplier(3);
$quadruple = $create_multiplier(4);
というような書き方をするテクニック。肝心な部分の記述は一回で済むためコードの管理も簡単になる。
上のコードは返すコードのなかで、$xを認識させるため、 use ( $x )というクローズをいれているが、PHP7.4 からPHPでもアローファンクションが使えるようになり、これだとuse というkeyword無しで、外側で設定されている変数を認識するようになる。ので、
$create_multiplier = function($y){ return fn($x)=>$x*$y;};
//use function factory to create three functions.
$double = $create_multiplier(2);
$triple = $create_multiplier(3);
$quadruple = $create_multiplier(4);
11:54:25 [error] 3452#0: *528 FastCGI sent in stderr: "PHP message: PHP Warning: require_once(/usr/local/ispconfig/interface/lib/config.inc.php): failed to open stream: Permission denied in /usr/local/ispconfig/interface/web/index.php on line 31
PHP message: PHP Fatal error: require_once(): Failed opening required '../lib/config.inc.php' (include_path='.:/usr/share/php:/usr/share/pear') in /usr/local/ispconfig/interface/web/index.php on line 31" while reading response header from upstream,云々
Content Management System (CMS)を使うのが当たり前のようになっている昨今、 Apacheサーバーにはデータベースサービス(例えばmysql)とこのデータベースとウェッブページをつなぐツール(例えばPHP)が必要だ。 最初から何も実装されていなければ、lamp(linux Apache mysql php)などという便利なパッケージもあるが、すくなくともapacheサーバーは実装されているのでlamplをインストールするわけにもいかない。
Server side Scripting, Client side Scripting, それぞれ得手不得手があるので同じページに両方使うことも普通に行われます。
Server side scripting はサーバーがPHPやASP.netなどの環境をサポートしている必要があります。 有料のプロバイダーはほとんどの場合PHPをサポートしていますが、 無料サービスのホストの中にはサポートしていないこともあり、 そのようなHostを使っているときには、プロバイダーが用意したページ作成ソフトで画面を作るか、 HTML,CSS, JavaScriptの三種の神器のみでページ作成に取り組むことになります。
そこで FFFE at the beginning of Text file でググってみたら、 Wikipedia 上の Byte Order markという記述にたどりついた。NotepadなどのWindowsのエディターはデフォルトでこれがくっつくんだそうな。 説明はそちらにゆずるとして、 PHPで不具合が出ますよ、と、どんぴしゃのことがしっかり書いてある。 これで半日つぶしたぞ!
in my case, it was the Byte order Mark that was appended to the beggining of the PHP file. For detail discussion, see Wikipdia entry “byte order Mark” It even talks about this particular PHP error.