讓 Google Compute Engine 可以用終端機 SSH 登入

Written by Simon Asika on

目前Google Compute Engine 只能支援用 Web SSH 或者用 SSH Key 的模式登入。如果有需要採用簡單的帳號密碼登入方法,需要修改一下主機設定。

以下以 Ubuntu 作為示範。


[Joomla] Create Mulit-Language Mainmenu in Helix3

Written by Simon Asika on

Modify templates/{YOUR TEMPLATE}/features/menu.php file:

Origin:

class Helix3FeatureMenu {

    private $helix3;

    public function __construct($helix3){
        $this->helix3 = $helix3;
        $this->position = 'menu';
    }

    public function renderFeature() {

        $menu_type = $this->helix3->getParam('menu_type');

        ob_start();

        if($menu_type == 'mega_offcanvas') { ?>
            <div class='sp-megamenu-wrapper'>
                <a id="offcanvas-toggler" href="#"><i class="fa fa-bars"></i></a>
                <?php $this->helix3->loadMegaMenu('hidden-sm hidden-xs'); ?>
            </div>
        <?php } else if ($menu_type == 'mega') { ?>
            <div class='sp-megamenu-wrapper'>
                <a id="offcanvas-toggler" class="visible-sm visible-xs" href="#"><i class="fa fa-bars"></i></a>
                <?php $this->helix3->loadMegaMenu('hidden-sm hidden-xs'); ?>
            </div>
        <?php } else { ?>
            <a id="offcanvas-toggler" href="#"><i class="fa fa-bars"></i></a>
        <?php }

        return ob_get_clean();
    }
}

The modified:

class Helix3FeatureMenu {

    private $helix3;

    public function __construct($helix3){
        $this->helix3 = $helix3;
        $this->position = 'menu';
    }

    public function renderFeature() {

        $menu_type = $this->helix3->getParam('menu_type');

        $name = '';

        if (JLanguageMultilang::isEnabled())
        {
            $lang = JFactory::getLanguage()->getTag();

            // Please replace to your multi-language menutype name
            $name = 'mainmenu-' . strtolower($lang);
        }

        ob_start();

        if($menu_type == 'mega_offcanvas') { ?>
            <div class='sp-megamenu-wrapper'>
                <a id="offcanvas-toggler" href="#"><i class="fa fa-bars"></i></a>
                <?php $this->helix3->loadMegaMenu('hidden-sm hidden-xs', $name); ?>
            </div>
        <?php } else if ($menu_type == 'mega') { ?>
            <div class='sp-megamenu-wrapper'>
                <a id="offcanvas-toggler" class="visible-sm visible-xs" href="#"><i class="fa fa-bars"></i></a>
                <?php $this->helix3->loadMegaMenu('hidden-sm hidden-xs', $name); ?>
            </div>
        <?php } else { ?>
            <a id="offcanvas-toggler" href="#"><i class="fa fa-bars"></i></a>
        <?php }

        return ob_get_clean();
    }
}

Now Helix3 menu will auto load for different languages.


PHP Composite 模式簡易範例

Written by Simon Asika on

img

本篇文章用非常簡單的範例來示範一個採用 Composite 模式組織的聚合物件,通常這些聚合物件與被聚合的物件都有一樣的行為,只是聚合物件的行為是跟遍歷所有被聚合的物件執行相同的行為。


Ubuntu 中 PHP Session 過期時間無法自訂的問題

Written by Simon Asika on

file

有自己在 Ubuntu 或 Debian 系統上開發 PHP 的人應該會發現,自己寫的會員登入 Remember Me 好像都無法作用。明明 Session 與 Cookie 時間都設的非常長了,卻還是會自動過期。


Use Blade Template Engine Outside of Laravel

Written by Simon Asika on

file

Blade is a powerful php template engine which created by Laravel. There is an integration method to use it outside Laravel.

We use Windwalker Renderer

Usage

Add this to composer.json require block:

{
    "require": {
        "windwalker/renderer": "2.*",
        "illuminate/view": "5.*"
    }
}

And run composer update.

Then we can use this code to render *.blade.php files:

use Windwalker\Renderer\BladeRenderer;

$paths = array('/your/tmpl/path');

$renderer = new BladeRenderer($paths, array('cache_path' => __DIR__ . '/cache'));

$renderer->render('foo.bar', $data); // Will render foo/bar.blade.php

Windwalker Renderer also supports Twig and Mustache:

use Windwalker\Renderer\TwigRenderer;

$renderer = new TwigRenderer($paths);

$renderer->render('foo', $data);

Full documentation please see Windwalker Renderer


2016-11-11 updated

I wrote a Blade compatible template engine called Edge, you can write blade syntax without any Laravel dependencies. Just try it.


HHVM 中執行 composer 或 curl 出現 SlowTimer 的解決方法

Written by Simon Asika on

當我們在 HHVM 的環境下執行curl操作時(例如 composer),很容易出現這樣的錯誤訊息:

SlowTimer [5001ms] at curl: https://packagist.org/p/provider-active$2f0252314dbbe5cb68caf8e0fa2209a2a654aab9628231c6ba4d72b06f66e9d5.json

在 Ubuntu 14 上安裝 HHVM

Written by Simon Asika on

file

參考 Prebuilt packages on Ubuntu 14.04

wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -
echo deb http://dl.hhvm.com/ubuntu trusty main | sudo tee /etc/apt/sources.list.d/hhvm.list
sudo apt-get update
sudo apt-get install hhvm

神奇的 CSS 垂直置中

Written by Simon Asika on


Database Type: Oracle, MySQL, PostgreSQL, MS SQL, SQL 92, Common

Written by Simon Asika on

file


PHP Exceptions 種類與使用情境說明

Written by Simon Asika on

file

更新為 PHP 7 以後的版本

PHP 的 Exceptions 提供我們一個方便的方法處理錯誤,不過許多人並不是完全知道每一種不同的Exception代表什麼意思,以及如何使用。有鑑於中文資料實在太少了,我在這邊做一點講解,讓大家可以更流暢的使用不同的 Exception 物件。

在看這篇文章之前,妳可能需要先具備基礎的 Exception 與 try catch 知識。

  • http://blog.xuite.net/ghostjackyo/WorkTest/37743727-PHP+Try+Catch
  • http://jaceju.net/2010-04-23-handle-php-error-and-exception/
  • http://www.w3school.com.cn/php/php_exception.asp

Control Tools

WS-logo