我是 zend 框架的新手。我正在尝试学习 zf create db-table tblename,zf create model tblname,zf create model tblnameMapper。
添加 user.php(表单)
<?php
class Application_Form_Adduser extends Zend_Form
{
public function init()
{
$this->setMethod('post');
$username = $this->createElement('text','username');
$username->setLabel('Username:')
->setAttrib('size',10);
$password=$this->createElement('text','password');
$password->setLabel('Password')
->setAttrib('size',10);
$reg=$this->createElement('submit','submit');
$reg->setLabel('save');
$this->addElements(array(
$username,
$password,
$reg
));
return $this;
}
添加用户视图:
<?php
echo 'Add user';
echo "<br />" .$this->a;
echo $this->form;
?>
管理员控制器:
<?php
class AdminController extends Zend_Controller_Action
{
public function adduserAction(){
$form = new Application_Form_Auth();
$this->view->form = $form;
$this->view->assign('a','Entere new user:');
if($this->getRequest()->isPost()){
$formData = $this->_request->getPost();
$uname=$formData['username'];
$pass=$formData['password'];
$msg=$uname." added to database successfully";
$this->view->assign('a',$msg);
$db= Zend_Db_Table_Abstract::getDefaultAdapter();
$query="INSERT INTO `user` ( `id` , `uname` , `password` )
VALUES ('', '{$uname}', '{$pass}');";
$db->query($query);
}}
我想用上面的代码实现 db-table。我是 zend 框架的新手,我花了一些时间阅读程序员指南但徒劳无功。从手册中获取东西非常困难。所以请有人一步一步解释过程实施相同的。谢谢提前。