对 CakePHP 初学者有用的文章

Posted on 30th March 2007 by Nio in CakePHP, 程序人生

Further endeavours into baking Cake(PHP)

For now I have got some tips for beginning Cake developers (like myself).

1. Use scaffolding and only scaffolding when you are designing your database structure. At the start of a project, first build all the necessary models, controllers and db tables. Link them using Cake's $hasMany/$belongsTo/$hasOne/etc. functions and check to see if all relations work properly (i.e. when viewing one thing, you get 'related [other things]'. Scaffolding will really help you out here, as you can instantly check everything (no need to rewrite any HTML, etc).

2. At the start of an application get your internal structure right. Like mentioned in #1, use scaffolding to get your database/model relation structure right. In the early stages it's a) easier and b) less time consuming to set everything right for final implementation. Consider Cake's MVC approach: you need to seperate data, business logic and presentation. First get your data and data structure right, then add business rules and logic and only at the end worry about presentation. The method is not the same as the MVC approach (which is only about code seperation). This is an engineering approach that takes on different parts of the project one-by-one, in a logical order.

3. Learn by experience. This by the way goes for any programming language learning and is generally the way I advice people to learn programming. The point is that programming isn't something you know, it's something you feel. It's a creative process! Building a program can be done in many different ways and quite often there isn't even a best way. You need consider your alternatives, choose and finally go with that choice. You will always encounter new problems as a developer and so you will always need to come up with creative solutions for those problems. The best way to learn to do this is by gathering experience. Create a small but challenging project for you to take on, take it on and come up with solutions for the problems you encounter. Search the web, talk to other developers on forums, but get your problems solved. CakePHP, due to it's extremely intuitive conventions, is perfect for this learning method. Finding the answer you are looking for in Cake is easy as for some reason you just know where to look.

AJAX 加载图片生成器

Posted on 24th March 2007 by Nio in AJAX, 程序人生

ajaxload.info 提供了一个在线生成 AJAX 的 load 图片的工具,非常不错,可以设置图形、前景色和背景色,然后生成出来一个动态的加载图片,以后就不用自己去做这种图了,哈哈。

使用 CSS+JavaScript 实现超酷菜单

Posted on 21st March 2007 by Nio in JavaScript, 程序人生

devthought 提供的 Fancy Menu 看着真的很不错,像使用 Flash 实现的效果。

命令行运行 PHP

Posted on 20th March 2007 by Nio in 程序人生

Command-line PHP? Yes, you can!

The benefits of CLI PHP

For many years now, I've been applying a dubious definition of what it means to be an engineer. By my reckoning, an engineer is someone who uses a tool for something other than its originally intended purpose. While that isn't always a good idea, when you get down to it all, invention and, indeed, most innovation come from using something in a way you hadn't necessarily thought to use it before.

Imagine my surprise, then, when the idea hit me to use my old friend PHP, which has always been so reliable on Web pages, as a command-line tool. I'm hardly the first person to do this, but the idea was certainly new to me.

Of course, just the fact that you can use PHP on the command line isn't necessarily the best reason for doing so. However, you might quickly find several pleasant surprises when you first begin to experiment with PHP in this way. To begin with, debugging existing scripts becomes far, far simpler than ever. Programs that consist primarily of output with very little logic are incredibly simple in PHP. Beyond that, you can use all your knowledge of PHP to make it accomplish tasks you would never have thought of it for before. In fact, there's really nothing stopping you from using PHP as your Swiss Army knife for almost any given programming project.

Intrigued? Well, let's get started and see what you can accomplish by using PHP on the command line.

记得很早之前,我也经常写一些 PHP 脚本,放在 Linux 服务器上运行,比如自动打包、加密之类的,使用起来非常方便,当然前提是你必须熟悉 PHP ;)

PHP 中的 XML 拉模式解析

Posted on 14th March 2007 by Nio in 程序人生

PHP 中的 XML 拉模式解析

PHP 5 引入了新的类 XMLReader,用于读取可扩展标记语言(Extensible Markup Language,XML)。与 SimpleXML 或文档对象模型(Document Object Model,DOM)不同,XMLReader 以流模式进行操作。即它从头到尾读取文档。在文档后面的内容编译完成之前,可以先处理已编译好的文档前面的内容,从而实现非常快速、非常高效、非常节省地使用内存。需要处理的文档越大,这个特点就越发重要。

与 Simple API for XML (SAX) 不同,XMLReader 是推解析器,而不是拉解析器。这意味着程序是可以控制的。您将告诉解析器何时获取下一个文档片段,而不是在解析器看到文档后告诉您所看到的内容。您将请求内容,而不是对内容进行反应。从另一个角度来考虑这个问题:XMLReader 是 Iterator 设计模式的实现,而不是 Observer 设计模式的实现。