php点点通
,欢迎大家一起探讨php教程!
Loading
您所在的位置:首页 > 数据库 > 正文

PHP、CakePHP哪凉快哪呆着去

作者: 来源: 日期:2016-10-31 10:26:35 人气:55 加入收藏 评论:0 标签:cakephp

,我已经完全受不了了! 

<?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,地球不适合你们。


    本文网址:http://www.phpddt.com/2016category/db/149.html
    读完这篇文章后,您心情如何?
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    更多>>网友评论
    发表评论