首先建立数据库cake,除上诉字段数据库与上例一
分类:美高梅网上注册平台

这里声明一点,上例中不小心把数据库表中lastupd字段错打成lastudp,本例子予以更正。

首先建立数据库cake_ext,并执行如下sql文:

除上诉字段数据库与上例一致。

CREATETABLE`companies`NOTNULLauto_increment, `company`varcharNOTNULL, `price`decimalNOTNULL, `change`decimalNOTNULL, `lastudp`dateNOTNULL, PRIMARYKEYENGINE=MyISAMAUTO_INCREMENT=8DEFAULTCHARSET=utf8; ------------------------------ --Records ------------------------------ INSERTINTO`companies`VALUES('1','3mCo','71.72','0.02','2008-10-21'); INSERTINTO`companies`VALUES('2','AlcoaInc','29.01','0.42','2008-10-20'); INSERTINTO`companies`VALUES('3','AT&TInc.','31.61','-0.48','2008-10-21'); INSERTINTO`companies`VALUES('4','BoeingCo.','75.43','0.53','2008-10-13'); INSERTINTO`companies`VALUES('5','UnitedTechnologiesCorporation','63.26','0.55','2008-10-09'); INSERTINTO`companies`VALUES('6','IntelCorporation','19.88','0.31','2008-10-15'); INSERTINTO`companies`VALUES('7','ExxonMobilCorp','68.10','-0.43','2008-10-17');

工程仍沿用上例,如下图:

如下图所示建立工程:

代码依次为:

数据库配置文件如下:

database.php:与上例一致。

classDATABASE_CONFIG { var$default=array('driver'=>'mysql', 'connect'=>'mysql_connect', 'host'=>'localhost', 'login'=>'root', 'password'=>'root', 'database'=>'cake_ext', 'prefix'=>''); var$test=array('driver'=>'mysql', 'connect'=>'mysql_connect', 'host'=>'localhost', 'login'=>'root', 'password'=>'root', 'database'=>'cake_ext', 'prefix'=>''); }

companies_controller.php:

companies_controller.php:

classCompaniesControllerextendsAppController { var$name='Companies'; functionindex() { $this->set('companies',$this->Company->findAll; } functionview { $this->Company->id=$id; $this->set('company',$this->Company->read; } functionadd() { if(!emptyempty { if($this->Company->save { $this->flash('Yourposthasbeensaved.','/companies'); } } } functionedit { if(emptyempty { $this->Company->id=$id; $this->data=$this->Company->read(); } else { if($this->Company->save($this->data['Company'])) { $this->flash('Yourposthasbeenupdated.','/companies'); } } } functiondelete { $this->Company->del; $this->flash('Thepostwithid:'.$id.'hasbeendeleted.','/companies'); } } ?>

classCompaniesControllerextendsAppController { var$name='Companies'; functionindex() { $this->set('companies',$this->Company->findAll; } functionview { $this->Company->id=$id; $this->set('company',$this->Company->read; } } ?>

本文由美高梅网上注册平台发布于美高梅网上注册平台,转载请注明出处:首先建立数据库cake,除上诉字段数据库与上例一

上一篇:函数说明 下一篇:没有了
猜你喜欢
热门排行
精彩图文