Archive for the ‘cakePHP websites’ Category

INI Based Permission Component


Warning: fopen(/ini.php) [function.fopen]: failed to open stream: Permission denied in /home/promet/public_html/cakephp/wp-content/plugins/devformatter/devgeshi.php on line 103

Warning: fopen(/ini.php) [function.fopen]: failed to open stream: Permission denied in /home/promet/public_html/cakephp/wp-content/plugins/devformatter/devgeshi.php on line 103

Warning: fopen(/ini.php) [function.fopen]: failed to open stream: Permission denied in /home/promet/public_html/cakephp/wp-content/plugins/devformatter/devgeshi.php on line 103

Warning: fopen(/ini.php) [function.fopen]: failed to open stream: Permission denied in /home/promet/public_html/cakephp/wp-content/plugins/devformatter/devgeshi.php on line 103

Yet another permission component was created this week but this time, it’s simplier and written in a text file. In one of our project, one of the follow-up requirement was to allow users of certain groups upgrade into a better status. The project was already in production and I was using ACL with Auth component to do my authentication. Unfortunately, this is one of ACLs weakness.

Changing a users group does not change the ARO parent (effectively making it useless/impossible to change groups). I tried fixing this home-brew style, but since there’s no setParent in 1.2′s db_acl, it’s far harder than it should be.

That was reported back in 2007 and there was still no solution found in the net. It is also not an option for me to go through the above suggestion in fixing the problem so the the other solution is to find another one or create one. I chose the latter.

Why create a new one?

The other solutions that I found still needs some configuration in the controllers. Since I already have a ton of files, I don’t want to go through all of them to add a line or two. I need ACLs way of doing it all in the background. Also, I am already using Auth component and I want to keep it.

Why did I choose a text file over a database?

My intention is to make the application faster since load time is really getting slower. Since the application isn’t that big, I only have less than 200 lines for the permissions, so a database is just overkill. Even if I use a database, I might cache it anyway so it saves me extra query.

The component

So Permission Component was created. Below is the instruction on how to install it.

  1. Download this component and copy to your components folder.
  2. Create cake_dir/app/config/permissions.ini

The content for permissions.ini is as follows

1

2
[ControllerName]
3
actionName = group_id,group_id
4
 
5
[PluginName.ControllerName]
6
actionName = group_id,group_id
7

The ControllerName should be the controller name itself (in camel-case format).

The actionName is also the action name itself (in camel-case format).

The PluginName is the plugin name itself (in camel-case format).

The group_id is the one written in your Auth component. Your Auth component should have a group_id value because this is what our Permission component will look for. It could be a number or set of characters.

Example:

01

02
; Group ID 1 = Admin
03
; Group ID 2 = Member
04
[Accounts]
05
index =
06
add = 1
07
edit = 1,2
08
delete = 1,2
09
 
10
[ShoppingCart.Orders]
11
index =
12
report = 1
13

Assigning no group id in an actionName will simply ignore it.

Reminder

Use at your own risk. If you found a bug, please post them at the comment form.

Setting Frontpage in CakePHP

Hello again readers,

I have another topic for newbies like me. I know this will help you. And this is very, very easy and it’s a common thing to do when developing websites. It’s establishing a homepage. Here’s how and this won’t take long.

1. Code your desired design. This does not require you to complete the entire html tags. Just the contents inside <body></body> would be fine.

2. Then save it as home.ctp and upload to app/views/pages.

And that’s it. You can now check your new homepage design.

Setting Your Page Layout in CakePHP

I am not a pro in CakePHP, and in fact, i am just a beginner who wanted to explore it. When I was on my way to creating my goal, I stumbled upon a problem on how to change and then set the new page layout to be used. Honestly, the problem didn’t took me long to solve. I was lucky to have read the manual on the official site. So to cut the long story short, here is the list of steps which I did to come up with my new and first page layout on my CakePHP inspired website and you might consider following this little manual, too.

1. First, design the layout that you wanted to implement and use. Assuming we have the simple code below as your desired page layout.
<html>
<head>
<title></title>
</head>
<body>

</body>
</html>

2. After having established the base, let us now put the code that will show the title of your page. We will use $title_for_layout to do the job. So your head section will now look like this:
<head>
<title><?php echo $title_for_layout?></title>
</head>

3. Next inline would be displaying the contents. We will use $content_for_layout. It will tell CakePHP where to place the code for your views. Our code now will look like this one.
<html>
<head>
<title><?php echo $title_for_layout?></title>
</head>
<body>
<?php echo $content_for_layout ?>
</body>
</html>

4. Then save it as app/views/layouts/default.ctp.

Next topic would be creating and using multitle layouts for single website. Please feel free to share your views which you think can help us beginners make a step higher on CakePHP.

cakePHP websites

The kitchen has NOT closed – we have just been busy baking! We have embraced cakePHP as our standard template for heavy custom development.

Here is a site I’d like to showcase: www.isupportthismessage.com It’s almost ready for prime time. There has been a soft launch and while it is in production we are still working on some improvements to it. We used the cakePHP framework for this video social networking site. All the functionality here has been created without reusing any existing code.