因为公司经常有PHP的外包项目做,客户指定使用PHP来开发,而我是Java组的,没做过PHP项目,心生好奇,趁今晚有空来摸摸PHP。
装了PHPeclipe和xampp,google到
PHP手册。
一起就绪,学起PHP来,发现PHPeclipse的代码提示做的很不错。
可是慢慢看手册,我慢慢发现,都说PHP开发小型项目快,但是页面里嵌入一坨一坨的逻辑代码,非常不爽啊。
在看到MySql函数这章时,我已经完全受不了了!
<?php
// 连接,选择数据库
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('my_database') or die('Could not select database');
// 执行 SQL 查询
$query = 'SELECT * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// 用 HTML 显示结果
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
// 释放结果集
mysql_free_result($result);
// 关闭连接
mysql_close($link);
?>
数据库连接->查询->就在页面本地显示结果,加上古怪的语法、关键字和函数名,完全没有MVC的概念,简直连JSP都不如!
看来5年前板桥对PHP的批斗是万分正确的。
太无奈了!
我继续google,得到一份
CakePHP Manual,以前没细看Cake,只了解它是Rails的盗版。
看看
Cake Blog Tutorial上手吧。
结果PHPeclipse竟然不支持thtml文件的语法高亮、代码和标签提示!
郁闷之中,抱着忍者无敌的精神一行一行代码的敲,细细体会CakePHP开发是有多Rapid。
posts_controller.php:
<?php
class PostsController extends AppController
{
var $name = 'Posts';
function index()
{
$this->set('posts', $this->Post->findAll());
}
function view($id = null)
{
$this->Post->id = $id;
$this->set('post', $this->Post->read());
}
function add()
{
if (!empty($this->data))
{
if ($this->Post->save($this->data))
{
$this->flash('Your post has been saved.','/posts');
}
}
}
function edit($id = null)
{
if (empty($this->data))
{
$this->Post->id = $id;
$this->data = $this->Post->read();
}
else
{
if ($this->Post->save($this->data['Post']))
{
$this->flash('Your post has been updated.','/posts');
}
}
}
function delete($id)
{
$this->Post->del($id);
$this->flash('The post with id: '.$id.' has been deleted.', '/posts');
}
}
?>
index.thtml:
<h1>Blog posts</h1>
<p><?php echo $html->link("Add Post", "/posts/add");?></p>
<table>
<tr>
<th>Id</th>
<th>Title</th>
<th>Created</th>
</tr>
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post['Post']['id']; ?></td>
<td>
<?php echo $html->link($post['Post']['title'],"/posts/view/".$post['Post']['id']); ?></td>
<?php echo $html->link('Delete', "/posts/delete/{$post['Post']['id']}", null, 'Are you sure')?>
<?php echo $html->link('Edit', "/posts/edit/".$post['Post']['id']);?>
</td>
<td><?php echo $post['Post']['created']; ?></td>
</tr>
<?php endforeach; ?>
</table>
哇,这代码太华丽了!太精湛了!
$this->Post->、
<?php..?>、
echo和
$post['Post']['xx']写到手软,真服了,什么烂语法啊!
CakePHP的作者你们辛苦了,为了赶Rails的时髦让你们以及使用Cake的广大软件作坊的同仁们敲烂无数键盘,硬件商要感谢你们!
你们是伟大的功臣!来自火星的英雄!
PHP、CakePHP,地球不适合你们。
分享到:
相关推荐
打包下载,里面有CakePHP的框架源码,下载后可直接使用,版本是1.1的,稳定版;CakePHP的分页组件源码;CakePHP的中文及英文教程,CHM格式;CakePHP的中文打印版教程,WORD格式,下载后可直接打印,方便的;CakePHP...
There are two main ways to get a fresh copy of CakePHP. You can either download an archive copy (zip/tar.gz/tar.bz2) from the main website, or check out the code from the git repository. To download ...
CakePHP 一个开源PHP web 开发框架,PHPMVC结构框架,易与开发,是PHP技术人员的开发好的选择之一!
CakePHP php框架简介 CakePHP是一个用PHP编写的开源Web应用框架,不过其模型是用Ruby on Rails设计的。作为PHP世界的Rails,CakePHP采纳了RoR的许多优秀特性,成熟度较高。在cakephp.org站点的Sites in the wild...
CakePHP php框架简介 CakePHP是一个用PHP编写的开源Web应用框架,不过其模型是用Ruby on Rails设计的。作为PHP世界的Rails,CakePHP采纳了RoR的许多优秀特性,成熟度较高。在cakephp.org站点的Sites in the wild...
CakePHP是一个用PHP编写的开源Web应用框架,不过其模型是用Ruby on Rails设计的。作为PHP世界的Rails,CakePHP采纳了RoR的许多优秀特性,成熟度较高。在cakephp.org站点的Sites in the wild页面可以看到当前使用...
php mvc框架,php mvc框架,php mvc框架php mvc框架php mvc框架,php mvc框架
打包下载,里面有CakePHP的框架源码,下载后可直接使用,版本是1.1的,稳定版;CakePHP的分页组件源码;CakePHP的中文及英文教程,CHM格式;CakePHP的中文打印版教程,WORD格式,下载后可直接打印,方便的;CakePHP...
解压密码在:http://www.pin5i.com/showtopic-building-php-applications-with-symfony-cakephp-zend-framework.html
CakePHP是一个用PHP编写的开源Web应用框架,不过其模型是用Ruby on Rails设计的。作为PHP世界的Rails,CakePHP采纳了RoR的许多优秀特性,成熟度较高。在cakephp.org站点的Sites in the wild页面可以看到当前使用...
Lead you from a basic setup of CakePHP to building a couple applications that will highlight CakePHPs functionality and capabilities without delving too deeply into the PHP language, but rather what...
cakephp 框架 cakephp 框架 cakephp 框架 cakephp 框架 cakephp 框架
CakePHP是一个用PHP编写的开源Web应用框架,不过其模型是用Ruby on Rails设计的。作为PHP世界的Rails,CakePHP采纳了RoR的许多优秀特性,成熟度较高。在cakephp.org站点的Sites in the wild页面可以看到当前使用...
CakePHP-PHP框架 难道的框架分析。
CakePHP 3.4 开发手册文档 CakePHP Cookbook Documentation Release 3.4
cakephp分页,cakephp框架的分页的方法的文档,是cakephp框架的内容。
Accelerate your development of PHP applications using the popular CakePHP web application development framework and unit testing. This short book shows you how to carry out test-driven development ...
CakePHP最新稳定版,PHP中的较精炼的Rails框架
一些cakephp3.0 的使用总结
CakePHP是一个用PHP编写的开源Web应用框架,不过其模型是用Ruby on Rails设计的。作为PHP世界的Rails,CakePHP采纳了RoR的许多优秀特性,成熟度较高。