Role Based Access Control System (CakePHP plug-in)

March 9th, 2010

280701

Recently I have made a RBAC(Role Based Access Control) System using CakePHP, and it is an easy plug-in which you can use to plug into your existing project or you can use to start a brand new project from.

I have put it up at CodeCanyon ( http://codecanyon.net/item/base-role-based-access-controlcakephp-plugin/89182 ). If you want to support me, please purchase it at CodeCanyon.

Happy Baking!

admin General Cakephp , ,

CakePHP common errors part 1

February 17th, 2010

If you are a LAMP developers, you may have encountered this error before.

I have encountered these many times, so I decided to put this into my blog, in case I struggle with finding the bug later.

This error happens to when I use a variable  in my View without initializing it in my Controller.

I believe there are other causes to this error, if you have met any situations like this, do let me know, so I could put it up.

Happy Baking!

error

admin CakePHP, General Cakephp

A online-shop portal (isFun2Shop)

January 7th, 2010

Recently I have done a personal project which is to build and run a web application.

Basically The web application is a online-shop portal , its live url is www.isfun2shop.com.

Right now it is running on Chinese version only.

It’s idea is to allow online-shop owners open a online shop and sell its products .As it is a web portal , it has an admin panel for each registered member to manage their online-shop.

Technology used here are of cause Cakephp + Jquery , as they are what I am focusing these days.

If you are Chinese reader, do give a try and feedbacks are always welcome.

admin Projects

Xmenu Version 2.0

November 27th, 2009

Latest version 2.0  of  Xmenu is finally out.

Check it out at    http://www.the-di-lab.com/?p=87

Fix:

1.Working in IE browser now

Add On:

1.Added “effect”  option to the xmenu, now its expanding animation is customizable.

I would like to thank Martin and Venu for their valuable advices and bug report

admin JQuery

Jquery Plugin: Xmenu

September 19th, 2009
Xmenu(Xml Menu) is a jquery plugin which contructs a expanding and collapsed menu based on a xml file.

There are several benefits by doing this.

Firstly It gives a very clean code, all we need to do is to put <div> in
html, and that is all for your html.

Secondly, it makes life much easier for backend script. Just imagine, if you need to gives different menu options according to user role, all your backend script needs to do is to form different xml .Xmenu takes care of the UI part.

Thirdly, Xmenu is built tightly with CSS. which means you can easily change its look and feel just by editing its CSS.

To start with Xmenu, please first take a look at the xml format. and then read its options table.

And then you can start Basic Example, Css Example, Animation Example.

This is a ongoing plugin, the current version is 2.0. I will be adding more and more features.

Your support is appreciated.Please leave any enquiries or doubts.

Download v1.0

Download v2.0

XML Format:

Please Download This Xml for your referrence.

Version 1.0 Options Table

Options Required Possiable Value Remarks
url true links.xml This is url path pointing to your xml file. Xml file is loaded through ajax.
open false “single”,

“all”.

Default:

“all”

When the value is set to be “single”, Xmenu will only leave one menu option open.Which means expanding menu option A will collapse all other menu options.

When the value is set to be “all”, each menu option’s expanding and collapsed state is seperated, they don’t affect each others.

int false “all”,

menu option index(”0″,”1″).

Default:

“all”

This option will set the default expanding menu option and set all other menu options collapsed.And note the index is “0″ based.

When the value is set to be “all”, it will keep every menu option expanded when xmenu is initialized.

effect
(available
version 2.0 above)
false “slide”

“fade”

Default:

“slide”

“slide” option gives menu sliding effect while expanding whereas “fade” option gives menu fading effect while expanding

Basic Samples

version sample codes
1.0 Demo <div id=”menu”></div>

$(document).ready(function() {
$(’#menu’).xmenu({url:”links.xml”});
});

1.0 Demo <div id=”menu2″></div>

$(document).ready(function() {
$(’#menu2′).xmenu({url:”links.xml”,open:”single”,init:”0″});
});

CSS Samples

css_pic

version sample codes
1.0 Demo .xmenu-item a:hover{

margin-left:20px;

}

$(document).ready(function() {

$(’#menu’).xmenu({url:”links.xml”});

});

<div id=”menu”></div>

You can customize various effects by editing xmenu css style according to it css structure.

Animation Sample

2.0 Demo <div id=”menu”></div>

$(document).ready(function() {
$(’#menu’).xmenu({url:”links.xml”,open:”all”,init:”0″,effect:”fade”});
});

admin JQuery , , , , , , ,

Javascript FileReader

September 6th, 2009

When I was doing one of my projects , I needed a javascript function to read from a file and print it line by line.

However, it is not possible in Javascript to read from local file system.

Thus, I made a work around, which is to read from a file by PHP, and then append a line break symbol at the end of each line.

And finally, I have this javascript “class” to read from “file” line by line.

It works similar to BufferedReader in Java.

Here is the function:



String.prototype.trim = function () {
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

//line breaker %lb%
function FileReader(file) {
var lineBreaker ="%lb%";
this.fileString = file.trim();

var cursor = 0;
var recorder = new Array();

//public methods
this.close = function () {
cursor = 0;
recorder = null;
fileString ="";
}

this.readLine = function () {
var value = null;

if(cursor == 0 ){
process();
}

if(cursor<recorder.length) {
value = getLine();
cursor++;
}
alert(value);
return value;
}

//private methods
var process = function () {
recorder = fileString.split(lineBreaker);
}

var getLine = function() {
return recorder[cursor];
}

}

To use this “class”, firstly you can pass a file which is a String (formatted by backend language with a defined line break):


var fileObj = FileReader(file);

And when you call fileObj.readLine() , it will return a line of content.

Please notice that , you have to append a line break symbol(eg. %lb% ), you can also change the line break symbol ,but make

sure you change it in Javascript class.

admin General Javascript , , ,

i18n and l10n in cakephp

August 18th, 2009

In order to add I18n and l10n into Jqcms, I have been searching internet to implement this feature.

And this is my final solution of I18n and l10n in cakephp .

Please note my current cakephp version is 1.2.1 .

1.Create your locale file.
The file path is app/locale/eng/LC_MESSAGES/default.po.
You could create your customized locale file such as  app/locale/fre/LC_MESSAGES/default.po.
app/locale/rus/LC_MESSAGES/default.po.

whereas, default.po is the actually locale file which contains the content.
It is recommanded to use po edit to edit this locale file due to its encoding.
However, when I used notepad to edit it, it works still fine.
The content of the file looks like this:

</code></code></code>

msgid   "add"
msgstr "Add Content"

<code>

msgid is the id of the string , msgstr is the string content. You could create as many pairs as you need.

2.Initialize your locale

To tell cakephp which locale you want to use, or change current locale file. I did this in my controller:

</code>
$this->Session->write('Config.language','en');
<code>

However, I found out that doing this is fine too

</code>
Configure::write('Config.language','rus');
<code>

3.View your locale String

After two simple steps above, now you can make use of it by doing :

</code>
__("add")
<code>

Please note it is a double underscore __ instead of single underscore _

If you wish to use po editor create or edit your locale file, refer to

http://www.bunchacode.com/programming/internationalization-and-localization-in-cakephp/

Thanks for reading.

Please comment if you have any problem or I have made any mistakes.

admin General Cakephp , , ,

Cakephp Session issue

August 11th, 2009

These days I encountered a very weird issue when I was doing JqCMS.

Basically I have a login function to set a session value, after that in app_controller, I have a method to check the session variable to prevent users who are not login.

The problem happens when user has already loggin, and the session value is lost when user clicks on certain links.

And at the end, I found the issue is caused by Ajax , so when it is an ajax call,it will kill the current session.

The solution is to set certain values in Core.php:

Configure::write(’Session.checkAgent’, false);
Configure::write(’Security.level’, ‘medium’);

And I believe this is not the only solution.

I found this solution in

http://blog.alexjeffery.org/2008/03/27/cakephp-session-lost-when-using-applets-or-flash/

PS: It will be good enough to just

Set         Configure::write(’Security.level’, ‘medium’);
Leave    Configure::write(’Session.checkAgent’, true);

admin General Cakephp , , , , ,

Cakephp Uploader Component

July 27th, 2009

Download this component at http://www.the-di-lab.com/download/uploader.rar

To use this component, simply include it in your controller .
var $components = array(’Uploader’);

And there are two main methods is provided by this component.
One is upload($dir,$file,$delCurrent) and another is removeFolder($f).

In upload method.
you pass the directory where you want to store the file to $dir,
and pass file object to $file, and specify $delCurrent to true or false.
$delCurrent determines if you want to delete current file in $dir directory.

In removeFolder method.
It will simply remove directory $f,including all objects in $f direcoty.

Please leave me comments if you need any help.

admin General Cakephp , ,

JqCMS

June 13th, 2009

After playing around with Jqgrid, I decided to make a CMS framework which is using Jqgrid as the main data table and Cakephp as the backend framework.

I have just started this project , lots of things will be added later.

Check the project page at http://www.the-di-lab.com/?page_id=47

Stay tuned .

admin Projects ,

Get Adobe Flash playerPlugin by wpburn.com wordpress themes