CakeDC Blog

TIPS, INSIGHTS AND THE LATEST FROM THE EXPERTS BEHIND CAKEPHP

Felix Geisendörfer - Jquery and CakePHP

Felix started off by baking his application. While baking his controller he added in the Javascript Helper and RequestHandler Component. This will save adding them in later. Because the demo was based on Jquery the Ajax helper could not be used. However, Felix raised a very good issue of using a helper vs. writing Javascript. His opinion is that if you want to build a heavy AJAX application you should write all your javascript. If you just need a bit of AJAX sprinkled on you can use the helper. However, helpers are difficult to use in wide applications as they abstract one language into another which is tricky. Felix talked briefly about how he organizes his javascript. He likes to have specific javascript files for each controller/view placed in js/views as well as a few utility libraries. This allows his projects to reuse general js code as well as keep the Javascript separate for each view.

Adding jquery.form

Felix recommends using the form jquery plugin for working with forms. It allows you to easily add ajax behavior to your forms. After adding jquery.forms to the layout and creating his view js file. He was able to quickly make his form Ajax-ified. A question was asked about using JSON with Ajax in CakePHP. Felix then demonstrated how you could create a JSON Ajax view. By adding Router::parseExtensions('json'); Felix then created his json layout and his json view. Extension based views need to go into a directory that shares the name with the extension. By adding a 2nd and 4th parameter to $.get() you can force a json return. $.get('/cakefest/view/2.json', {}, function(response, status){ //handle response here }, 'json'); Is an example of how to do this. A question about pagination was asked. Felix's solution was to use a selector and attach an event to all your pagination buttons.   This concludes CakeFest Argentina. I had a really great time and would like to thank everyone who came out, and everyone who presented. I would also like to thank all of our sponsors, SaniSoft, Zeadoo, WidgetPress and the CakeDC. Lastly, thanks to Mariano and Claudio for orgnanizing and hosting the event.

Garret Woodworth - Advanced console

Since we got through bake on the last talk, we are going to look at some advanced usage of bake and other consoles. The interactive console was demonstrated. With the interactive console, you can examine the routes, interact with models. Following the console demonstration, Garrett demonstrated creation of a custom shell. Building on a previous example application, garret started building a shell to generate a menu. This covered creating methods in your shell, using in() and out() as well as how to access args and params. A demo of Cakebot was next. Cakebot is the IRC bot used in #cakephp, Cakebot was also written as a CakePHP shell.

Mariano Iglesias - Internationalizatio...

Why internationalize? You can attract a larger market by making content available in additional languages. When offering international content, you need to translate both the fixed and dynamic content in the database. In CakePHP you can facilitate translation with __() and __n(). In addition content stored in the database can be translated with TranslateBehavior. Multibyte characters exist in many languages, characters outside the traditional latin character set are represented with multibyte characters. This allows for the creation of additional characters and idiomatic expresssion. There is a PHP extentsion for using multibyte strings, it provides the mb_ functions. CakePHP also provides a MultiByte class which provides all the mb_ functions for PHP4 or PHP5 installations lacking them.

Using translation in CakePHP

By using __() we can create translatable strings in our applications. You can use placeholders as well in your translation strings. It is important to use place holders as parameters such as a name can move around in a sentance based on the language. Once you have added all the __() calls, you can use cake i18n extract -output app/locale. The generated file will be placed in app/locale/default.pot Mariano then gave an example and quick walkthrough of translation and i18n. He added translated elements to the views. Then extracted the strings with the shell and created translated values with poEdit.

Translating database content

Translate behavior helps to translate any database content. All translations in CakePHP are stored in one table. Translate behavior takes a number of fields when included on a model. This indicates which fields are going to be translated. Translated fields are not needed on the table schema. The translate behavior also allows you to specify a number of languages and language specific values or you can simply add one language. Later on another language can be added. The rest of Translate Behavior works seamlessly on find() and save(). When using elements with caching. You can use a key parameter when calling element() to ensure that different languages are cached separately. Mariano's talk brought the third day of CakeFest to an end. This has been an excellent conference so far and the last day promises to be great as well.

BOOK A 15 MINUTES FREE
CONSULTING WITH US:

Martin Radosta - Record level security...

Martin's presentation was based around a behavior that he wrote to provide access control using SQL. In designing a solution, martin came up with a few criteria. The solution must be generic, it only requires 4 fields on any table that will be using the behavior. It should perform quickly and not create a lot of extra queries. The solution he searched for also needed to provide a few features. It should provide permissions for read write and delete. Permissions are assigned by role, with users having many roles. This system is similar to ACL but different, in that it stores the permissions for each record. Martin's behavior uses a permission system similar to the unix file system, with a owner, group, world access. This was implemented as series of bit masks. Unlike the unix filesystems, these permissions are summed and stored as one field. The 4 fields mentioned earlier are user_id, role_id, group_id, and permissions. These four fields allow the behavior to work, both the roles and groups also use binary values to reduce the number of columns. The binary values for roles and groups are compared to those in the role and group id for records . In addition the requested permission is combined with group and role values and checked against the permissions field. Since binary values are used, roles can be combined and will always be unique. Permissions in a system like this permissions are done via a bitmask system. User values for group, and role are compared to record permissions. If the value of the bitmask meets the expectation, the record is returned. In addition to a controller, an element, action in Appcontroller and a model are used. Martin gave a quick demo of an application using his behavior. The permissions checks are all done in the SQL of the behavior. Another interesting part of the behavior is that in the behavior's afterFind() extra values are added to indicate whether or not a user can write or delete. This allows for your interface to display the correct icons. Which is a nice added bonus. I personally was really impressed with how his system was designed and how it worked. He demonstrated how his fine grained access control group. He even had a root user that was not bound by the permissions system. The permissionYou can find this project at Sourceforge the project is licensed under the MIT license.

Fabian Andres - CakePHP in big compani...

Why talk about large companies. Larger companies have large demands and often they involve money over the internet. Large companies require fast and efficient applications, which in turn requires efficient tools. This is where CakePHP steps in. Current solutions for large merchant solutions include Java, and .Net solutions. In addition to these solutions, there are alternatives in PHP, ruby, python. However, rapid development is difficult in some of the popular solutions. By using an alternate solution you can tap into a large pool of developers worldwide. CakePHP helps in this area as well, as with a large community allows you to find developers to fill specific roles. CakePHP offers connectors for many databases. CakePHP also offers easy to use and efficient caching methods which help improve performance. There are many CakePHP sites run by large companies including Mozilla, Sony, Diesel, TV mallorca. Fabian then showed many of the websites that were mentioned in the presentation. Following this presentation there was a good discussion on caching and performance, and how to deal with high traffic situations.

We Bake with CakePHP