I hope the students learned just a little though. There might more to come if budget permits! haha! The roadshow is accepting sponsors and volunteer speakers so don’t be shy to contact PHPUGPH or Jeffrey Seracarpio at jseracar@phpugph.com if you are willing to help this advocacy. For schools, you can also contact Sir Jeff.
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.
Download this component and copy to your components folder. Create cake_dir/app/config/permissions.ini
The content for permissions.ini is as follows
[ ControllerName]
actionName = group_id,group_id
[ PluginName.ControllerName]
actionName = group_id,group_id
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:
; Group ID 1 = Admin
; Group ID 2 = Member
[ Accounts]
index =
add = 1
edit = 1 ,2
delete = 1 ,2
[ ShoppingCart.Orders]
index =
report = 1
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.
I use bake to start any project of mine and therefore doesn’t mean that using it produces a complete app unless you only want a CRUD application. This tutorial is intended for beginners in cakephp. It is still recommended that you look at the blog tutorial in cakephp manual because it has a more complete introduction for the framework. Take note that I am using the Cakephp 1.2.0.7692 RC3 in demonstrating this little project because it is the latest release as of this writing. What to do and what do we need to begin?
To start off, we need a project. I opted a mini-library application which consists of
Books Authors Book reviews by users
Read the rest of this entry »
Tags: applications , bake
In cakephp, adding relationships is easy. We just have to declare the hasOne, belongsTo, hasMany and the famous HABTM relationship to do all the dirty work of joining tables. But declaring them all at once could lead to a slow page. In version 1.1, what we do is utilize the bindModel() and unbindModel() . We do not declare all associations in the Model class yet. This was a good solution. I was looking for this option in version 1.2 and I found the Containable Behavior. Studying containable was a little rough before but there are documents now that are really helpful. Read the rest of this entry »
Tags: containable , optimization
From now on, I’ll always use Model->create() before saving new data. I’ve been using Model->create() for a series Model->save() calls (like in a loop) to initialize the model class for saving new information. But when I only need to do a single call to save(), I no longer call create() assuming that I’m starting with a new set of information. I was always able to get away with it until I had this bug that annoyed me for a few hours. Long story short, I learned something: not only when doing multiple calls to Model->save() , you should also call Model->create() before saving if a previous call to Model->read() was made. Or better yet, always call Model->create() whenever you are about to save new data . There are cases the previous calls to save and read made are not that obvious, like in the beforeFilter() callbacks of the controller (or the parent::beforeFilter(), like in my case).
If you used the star rating plugin of jQuery in cakePHP, you might experienced that the hover effects are not working properly. This is because one of the class name used to identify the buttons uses the radio button name. This will be a problem in cakephp because we use brackets in names.
<input type = "radio" name = "data[Model][field]" class = "star" / >
In order to fix that, we need to remove them. Here is quick fix. Open file jquery.rating.js : from (line 97):
// grouping:
var n = this .name ;
to:
// grouping:
var real_name = this .name ;
var n = real_name.replace ( /[^A-Za-z0-9_\-]/g , '-' ) ; // remove unwanted characters
from (line 108):
$.rating .groups [ n] .valueElem = $( '<input type="hidden" name="' + n + '" value=""' + ( settings.readOnly ? ' disabled="disabled"' : '' ) + '>' ) ;
to:
$.rating .groups [ n] .valueElem = $( '<input type="hidden" name="' + real_name + '" value=""' + ( settings.readOnly ? ' disabled="disabled"' : '' ) + '>' ) ;
I have reported this in the bugtracker and I hope it will be included in the next release.
Tags: bug fixes , jQuery , star rating
Hello again, Yesterday, i stumbled upon this problem on how am i suppose to create an image with a link on it. I needed to know it because of my goal. I wanted to use images as my buttons to navigate the admin pages. So without further ado, here’s how: 1. We will use HTML Helpers Image and Link, and we shall combine this 2. 2. For Image, Syntax: $html->image(string $path , array $htmlAttributes , boolean $return = false); Example: $html->image(’/img/images/cancel.png’, array(’class’ => ’save_button’)); 3. For Link, Syntax: $html->link(string $title, string $url, array $htmlAttributes, string $confirmMessage = false, boolean $escapeTitle = true, boolean $return = false ); Example: $html->link(’SAVE’, ‘/registers’, array(), false, false, false); 4. So to make an image clickable, <?php echo $html->link($html->image(’/img/images/cancel.png’,array(’class’ => ’save_button’)), ‘/registers’, array(), false, false, false); ?> That’s it. I hope this will help you in the future.
I had some free time today and decided to redesign the blog. I just recently upgraded my browser to Firefox 3 since I heard it already became stable. The previous design was broken in FF3 and aside from that I have been longing to adjust the width and font size of this blog for readability. On top of that, PrometSource , previously known us Promet Solutions, new website is UP . We recently faced a transition in the company to better serve our clients. We are always looking for best possible ways for our readers to enjoy their stay. If you think we can make it look better, please feel free to add your comments below.
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.
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.