Mình cài Zend Framework trong thư mục : /var/www/ (tức là : /var/www/Zend )
Các bước thực hiện :
1. Tạo file UserController.php , file này đặt theo đường dẫn sau nha : /var/www/Zend/application/controller , nội dung file như sau :
<?php
class UserController extends Zend_Controller_Action{
public function indexAction(){
$form=new Form_User;
if($this->_request->isPost()){
$name=$this->_request->getPost('name');
echo "Ten cua ban la :";
echo $name;
echo "</br>";
echo "Email cua ban la :";
$email=$this->_request->getPost('email');
echo $email;
echo "</br>";
echo "Gioi tinh cua ban la :";
$gender=$this->_request->getPost('gender');
echo $gender;
echo "</br>";
echo "Quoc gia cua ban la :";
$country=$this->_request->getPost('country');
echo $country;
echo "</br>";
echo " cm gia cua ban la :";
$note=$this->_request->getPost('note');
echo $note;
echo "</br>";
}
$this->view->form=$form;
}
}
2. Tạo file User.php , file này đặt trong thư mục : /var/www/Zend/application/forms , nội dung file như sau :
<?php
class Form_User extends Zend_Form{
public function init()
{
$this->setAction('')->setMethod('post');
$name=$this->createElement("text","name",array(
//"label" => "Full Name",
"size" => "30",
));
$email=$this->createElement("text","email",array(
//"label" => "Email",
"size" => "30",
));
$gender=$this->createElement("radio","gender",array(
//"label" => "Gender",
"multioptions"=> array(
"1" => "Male",
"2" => "Female",
),
));
$country=$this->createElement("select","country",array(
//"label" => "Country",
"multioptions"=> array(
"1" => "VietNam",
"2" => "Cambodia",
"3" => "Thai Lan",
)
));
$note=$this->createElement("textarea","note",array(
//"label" => "Note",
"cols" => "30",
"rows" => "5",
));
$submit=$this->createElement("submit","submit");
$this->setDecorators(array(
array('viewScript',
array('viewScript'=>'Form_Register.phtml'),
)));
$name->removeDecorator('HtmlTag')
->removeDecorator('Label');
$email->removeDecorator('HtmlTag')
->removeDecorator('Label');
$gender->removeDecorator('HtmlTag')
->removeDecorator('Label');
$country->removeDecorator('HtmlTag')
->removeDecorator('Label');
$note->removeDecorator('HtmlTag')
->removeDecorator('Label');
$submit->removeDecorator('DtDdWrapper');
$this->addElements(array($name,$email,$gender,$country,$note,$submit));
}
}
<?php
echo $this->form;
?>
0 nhận xét:
Đăng nhận xét
Vui lòng viết Tiếng Việt có dấu !