內容簡介
這個外掛建立的主要原因是因為 WordPress 沒有現成的中央註冊系統,可以儲存像是變數值、物件、陣列等等,可以在全域空間中取用。這個外掛基本上嘗試減少變數等等的重複宣告。它與 Magento 註冊表 "Mage_Registry" 相似,但是是輕量版。
這個外掛也可作為 GET 和 POST 請求參數處理器。好處是,您不需要檢查 isset($_GET['myparam']) 或 isset($_POST['myparam'])。如果參數未設置,它將在第二個參數設定預設值。預設值是 false。
輕鬆處理 Session 資料。使用動態方法輕鬆儲存、檢查存在性、取得和取消它。
希望這能對您有所幫助。
使用非常容易、整潔和直接:
即時註冊動態方法:
`registry()->setDynamicMethodName('this is my value');`
`registry()->setMyName('My Name is Rubin Shrestha');`
驗證方法是否存在並 echo:
`if(registry()->hasDynamicMethodName()) echo 'Has ' . registry()->getDynamicMethodName();`
取消動態方法:
`registry()->unsDynamicMethodName();`
之後,如果回應 registry()->getDynamicMethodName(),它將返回 null。
對於 GET 和 POST 請求處理器,使用以下方式:
對於 $_GET,只需呼叫 registry()->request()->getParam('param_key', [預設值,如果沒有則保持為空,將返回 false]);`
要檢查頁面類型是否為 $_POST 使用 if(registry()->request()->isPost()) { // 在這裡做你的事 }
對於 $_POST,只需呼叫 `registry()->request()->getPost('param_key', [預設值,如果沒有則保持為空,將返回 false]);
您也可以執行 registry()->request()->getParams() 和 registry()->request()->getPosts();
您也可以添加 request 物件範圍變數,`registry()->request()->setVariableName('this is my value');。以 registry()->request()->getVariableName() 取得值。
Session 處理:
像這樣輕鬆處理 session 中的資料 `registry()->session()->setDynamicMethodName('this is my value')`,並且透過 `registry()->session()->getDynamicMethodName()` 檢索它。取消 `registry()->session()->unsDynamicMethodName()`。
外掛標籤
開發者團隊
原文外掛簡介
The main reason for building this plugin is because wordpress doesn’t readily have a central registry system where things can be stored such as variable values, objects, arrays. Which can be retrieved from a global space. This plugin basically tries to lessen the repeating declarations of variables and etc. It is something quite similar to Magento registry “Mage_Registry”, but very light version.
This plugin can also be used as GET and POST request parameters handler. The benefit is, you don’t have to check isset($_GET[‘myparam’]) or isset($_POST[‘myparam’]). If the param is not set, it will return a default value you supplied in second param. By default, the default value is false.
Handle the session data as easy as never before. Save to session, check existance, get, unset it easily using dynamic methods.
Hope this could be of some use.
Usage is very easy, neat and straight forward:
Register a dynamic method on the fly:
registry()->setDynamicMethodName(‘this is my value’);
registry()->setMyName(‘My Name is Rubin Shrestha’);
Validate existance of your method and echo:
if( registry()->hasDynamicMethodName() ) echo ‘Has ‘ . registry()->getDynamicMethodName();
Unset the dynamic method:
registry()->unsDynamicMethodName(); after this, if you echo registry()->getDynamicMethodName() it will return null;
For GET and POST request handler use it like this:
For $_GET, you can simply call registry()->request()->getParam(‘param_key’, [default value if any, else blank, will return false]);
To check if the page type is $_POST use if( registry()->request()->isPost() ) { //do your stuffs here }
For $_POST, you can simply call registry()->request()->getPost(‘param_key’, [default value if any, else blank; will return false]);
You can also do registry()->request()->getParams() and registry()->request()->getPosts();
You can also add request object scope variable, registry()->request()->setVariableName(‘this is my value’);. Get the value by registry()->request()->getVariableName();
Session handler:
Handle the data in session as easy as registry()->session()->setDynamicMethodName(‘this is my value’); and get it as registry()->session()->getDynamicMethodName(); Unset it registry()->session()->unsDynamicMethodName();
