2014年1月26日 星期日

[Resolved] Smarty: Uncaught exception: SmartyException with message Call of unknown method config_load

Tried to load the configuration file but not succeed..

Fatal error: Uncaught exception SmartyException with message Call of unknown method config_load in X:\XXX\smarty\sysplugins\smarty_internal_templatebase.php:806 Stack trace: #0
Smarty_Internal_TemplateBase->__call('config_load', Array)#
Smarty->config_load(...) #2
require_once(...) #3 {main} thrown in
X:\XXX\smarty\sysplugins\smarty_internal_templatebase.php on line 806


Solution
The error was caused by the template cache, remove it and try again.

[Resolved] Smarty Fatal error: Call to undefined function config_load(): fail to load configuration file

In Smarty3, tried to load the configuration file in php but not success.. it returns the error message of
Call to undefined function config_load()

The PHP code is as below:
$smarty = new Smarty ();
$smarty->config_load("test.conf");


Solution:
The load configuration function should be configLoad, instead of config_load.

$smarty = new Smarty ();
$smarty->configLoad("test.conf");


2014年1月20日 星期一

[Small Tips] Useful server variable in PHP

$_SERVER['HTTP_HOST'];
-> returns xxx.com

$_SERVER["REQUEST_URI"];
->returns xxx.php


$_SERVER['HTTP_REFERER'] 
-> returns previous page

$_SERVER['REMOTE_ADDR'];
-> returns 192.x.x.x

2014年1月18日 星期六

jquery: get sibling

Search from google for the jquery on how to get sibling

You cannot write:

  • next("a"), because next() only tries to match the very next element. It will hit the <br> element and match nothing.
  • closest("a") , because closest() walks up the ancestor chain, starting with the element itself, and therefore will miss the <a> elements.

You can write:

  • next().next(), as Arend suggests. That's probably the fastest solution, but it makes the <br>elements mandatory.
  • nextAll("a"), but that can return multiple elements (and will do so with your markup sample). Chaining into first() would prevent it, but nextAll() still would have to iterate over all the next siblings, which can make it slow depending on the complexity of the markup inside your <div> elements.
  • nextUntil("a").last().next(), which only iterates over the next siblings until it finds a link, then returns the immediate next sibling of the last element matched. It might be faster thannextAll(), again, depending on your markup.
     Ref:  http://stackoverflow.com/questions/6237673/cleanest-way-to-get-a-sibling-in-jquery

2014年1月9日 星期四

Compress your web content in apache DEFLATE, gzip

 This article teaches you how to compress your web page in your apache


1.Enable the deflate module
LoadModule deflate_module modules/mod_deflate.so

2. Add the following configuration to httpd.conf
 
<Location />
    # Insert filter
    SetOutputFilter DEFLATE

    # Netscape 4.x has some problems...
    BrowserMatch ^Mozilla/4         gzip-only-text/html

    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4\.0[678] no-gzip

    # MSIE masquerades as Netscape, but it is fine
    BrowserMatch \bMSIE             !no-gzip !gzip-only-text/html
    # Don't compress images
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary

    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary
</Location>


3. Restart the apache
httpd -k restart

4. Done