Trabalhando com JSON no CakePHP 1.2

 Gostei da forma como o Juan Basso trabalha para renderizar objetos JSON através do CakePHP. Ficou bem limpa e da conta do recado. Segue o link do post falando sobre isso: http://blog.cakephp-brasil.org/2008/09/11/trabalhando-com-json-no-cakephp-12/

Trabalhando com JSON no CakePHP 1.2

Com o crescimento do uso de AJAX, da maioria dos frameworks de JavaScript (jQuery, Prototype, mooTools, YUI, ExtJS, …) e de uma dúvida no Groups do Google (Action que renderize apenas o layout, sem necessidade de uma view), resolvi escrever um post falando sobre como usar JSON no CakePHP de forma automática para retorno dos dados, sem precisar gerar um arquivo de view para cada action e que não fere o MVC.
A Solução

Para solucionar o caso, achei que o melhor jeito seria criando uma classe de View nova. A classe View do CakePHP ela sempre procura um arquivo de view, além do template. Com a nova classe, seria feita a renderização ali mesmo, sem a necessidade de novos arquivos.

Web Development Resources - Aptana Studio

At the risk of showing my age, it's been nearly 28 years since I wrote my first line of code. Way back in the heady days of ZX Basic on my trusty old ZX Spectrum. Back then to get anything usefull done it was Z80 assembly language or nothing.

Over the years I've used a lot of programming languages and a lot of IDE's, from Hisoft Basic on my Atari ST, through to Delphi and Visual Studio.

Nowadays, I tend to work extensively with both the .NET framework using Visual Studio 2008 and PHP using Aptana Studio.

Quicktips: Finding all the actions in your controller

Hi All,

Thought I'd share a quick tip today for how to automatically detect all the action names within a given controller.

This follows on from my last quicktip, describing how to detect all the controllers in your application and is usefull from witin navigation code or admin back ends.

$actions = get_class_methods($this);

This returns an array where each element is the name of a method within the current controller.

Filtering your results

You can make this more usefull by filtering the actions, for example to remove all the inherited actions from app_controller use:

CakePHP ACL Database Setup: ARO / ACO structure?

I'm struggling to implement ACL in CakePHP. After reading the documentation in the cake manual as well as several other tutorials, blog posts etc, I found Aran Johnson's excellent tutorial which has helped fill in many of the gaps. His examples seem to conflict with others I've seen though in a few places - specifically in the ARO tree structure he uses.

In his examples his user groups are set up as a cascading tree, with the most general user type being at the top of the tree, and its children branching off for each more restricted access type. Elsewhere I've usually seen each user type as a child of the same generic user type.

How do you set up your AROs and ACOs in CakePHP? Any and all tips appreciated!

CakePHP WhoIs Component

Here's one for all you aspiring web hosting ressellers out there, a fast and flexible whois class all wrapped up as a CakePHP component.

The component makes use of the excellent phpWhoIs class which you will need to download, unzip and place in APP/vendors/phpwhois in order for the component to work.

Click here to download phpWhoIs

phpWhoIs - a brief description

This package contains a Whois (RFC954) library for PHP. It allows
a PHP program to create a Whois object, and obtain the output of
a whois query with the Lookup function.

The response is an array containing, at least, an element 'rawdata',
containing the raw output from the whois request.

Browsers

I went to see w3school statistics browsers… However, employment trend emerges. As this is still statistics, that is close to the "Rules on Water" does not look at absolute figures, but on the relative changes… 2004, IE = 76.2% 2005, IE = 68.9% Fx 23.6% In 2006 IE = 60.6% Fx 29.9% In 2007 IE = 57% Fx 36.3% 2008, IE = 50.6% Fx 43.7% Even if there plus minus 5-10% in accuracy. The trend, nevertheless, to the person. And yet here, I think Google Chrome will make serious amendments to the statistics. According to statistics LiveInternet for September 1-7 at GC 0.6%, for 8-14 September (but today only 9 - e!) - 0.8%

[業務][PHP][CakePHP]

WindowsXPの開発環境で動いたCakePHPアプリをCentOS4のホスティング環境へ持っていった際につまづく。Webアプリは開発環境と同様に動くもの、シェル機能を使おうとすると/APP/app_model.phpのなんでもないと思われる箇所でparse errorが出る。 さんざん悩んで分かった原因は、シェル機能実行時にホスティング環境にもともとインストールされたPHP4が使われたため、PHP4でサポートされていないpublcのキーワードでparse errorが出ていただけだった。/CAKE ...

Database switching in CakePHP

Thought I would share a quick tip today for managing database connections and debug information betwen your local development machine and production server.

Personally I tend to have a version running on my local development machine and on my web server and keep them in synch using the excellent Aptana Studio IDE and the following mean that I can do this without worrying about overwriting my database settings whenever I synchronise.

For starters replace the DATABASE_CONFIG class in APP/config/database.php with the code below, substituting your database login details where applicable:

Easy forms with CakePHP

Last night i was thinking about the fact that in some cases i can’t use bake to re-bake my views to contain a new field for example. CakePHP also wants you to not write the same code twice, but what about the views. Every time you add a field to your model, you either need to re-bake your views, or update both the edit and add template files. You could use $form->inputs(); but the helper creates form fields for database fields you probably want to keep hidden (_count fields for example).
I can think of two solutions for this problem, namely.
1. Go the partial way (like rails uses it). Basically you make an element with all the form fields you want to display and use the $this->renderElement in the view to display the form fields.
2. Define public fields in your controller and use those. An example below:
post has the following fields:
id, title, content, created, comments_count.

CakePHP Workshop Review

I spent last weekend in Raleigh, NC attending a CakePHP workshop. At work we’re beginning to standardize on the CakePHP framework in order to minimize our development cycle while still ensuring reasonably strong application architecture in the presence of time constraints. I haven’t had much time to play in the weeds of this effort, so the workshop looked like it could be a decent way to get introduced to CakePHP.

It was. And it wasn’t.

ModelBaker: A desktop application for building CakePHP applications

Today I received an email informing me of a new Twitter follower called widgetpress . So I clicked on the users Twitter profile to check 'em out - as I usually do - and saw this post, which happened to be the users only post at the time:
Just released ModelBaker this week and going to private beta this weekend.

Named scope in CakePHP

Some time ago I wrote how to improve Cake controllers’ callback system basing on a solution from Ruby on Rails. Today I am going to port another cool feature of Rails to CakePHP - named scope.

Check this Rails example first if you don’t know what the named scope is:

Typical dialogue with the client

Customer: Hello. I am here for you e-mail sent, with a list of sites which I like. Look. Me: (I looked). Why do you sent me html? Why could not link? Customer: What is the difference? Me: There are. Okay. (Open html-file search for a direct link to the site. Open site) Customer: I decided that I did not write it like that do not like. I better explain in words. So will be faster. Me: Do you think that I remember it all? Customer: Are you inscribe. Me: 8-O (curtain)

Full CakePHP 1.2 App Part 12

OK so finally the full CakePHP application is coming to a close and this article is just going to wrap up a few loose ends. I've noticed a few errors and layout issues that I'm going to fix and hopefully by the end of the article the app will be fully complete.

Like all applications you could probably keep going forever adding new features, tweaking code and cleaning things up but th...

Um “pouco” sobre testes

No grupo de CakePHP, Cesar Fuentes criou um tópico sobre testes no CakePHP, pedindo sobre o assunto. Vejam a resposta de José Pedrini (autorizado pelo autor para disponibilizar o conteúdo):

 

Vou falar um “pouco” sobre o que eu sei, mas eu recomendo que todos procurem na internet e estudem, pois o assunto é interessante. 

A primeira vantagem de se escrever teste é trivial. Ao invés de ficar fazendo testes manualmente, você escreve programas que testam automaticamente. Testes automatizados criam uma malha protetora, garantindo que seu código faça aquilo que você pensa que ele tem que fazer. Automatizar testes ajudam você testar aquela  aplicação de 5000 linhas em pequeno tempo de execução. 

Validation CheatSheet 1.1

Acabo de hacer una chuleta (cheatsheet) sobre el tema de la validación en CakePHP. Puedes descargarla si crees que te puede resultar útil. Está basada en la página del manual correspondienteLa deberías poder encontrar en mi carpeta pública de iDisk. (hasta que encuentre un alojamiento mejor)29/8/2008: corregido el typo señalado por Kejk (Thanks)4/9/2008: corregido y aumentado el apartado de Custom Validation

Pipes.Yahoo 503 error

Recently I met to do a careful study yahoo pipes, as it turned out - something is broken, and pipes.yahoo do not work. Everywhere error 503. Even previously saved to open pipes is not possible. Judging by reports on the forum - a problem with the 7-8 morning. And I just encountered a problem that String.Translate module converts any field except the field content: encoded. And I just met to find out what the problem is - 503 :(Well then. Let's wait. Meanwhile, loans something more useful. For example CakePHP :)

CakePHP "The Workshop"

“The Workshop” Raleigh, North Carolina CakePHP A trip to Raleigh, North Carolina. I haven’t been to Raleigh now for 11 years. But I am excited to have this opportunity to meet with four of the main guys who have made the CakePHP framework. This framework is built for PHP and is a great framework from [...]

dateTime bugs

Strange error in the helpers who is responsible for form:echo $ form-> dateTime ( "Showtime", "DMY", 24, null, array ( "minYear" => 2008, "maxYear" => 2012, 'monthNames' => false, "interval" => 15) false);All right? Everything!However, in html see the following code:< name="data[Showtime][Showtime][day]" id="ShowtimeShowtimeDay">< value="01"> 1...< / select> -< name="data[Showtime][month]" id="ShowtimeMonth">< value="01"> 01Why do we have chosen day encoded twice Showtime? Other parameters are coded properly. If only not forget that in order to set the interval mode 24 hours a day, should be a bit sub-source code (ticket already established).We are talking about CakePHP 1.2 RC2

Syndicate content