Thứ Hai, 9 tháng 9, 2013

Thao tác với Form trong Zend Framework trên Linux

Posted by Unknown Thứ Hai, tháng 9 09, 2013, under | No comments

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));
    }
}

3. Tạo file Form_Register.phtml , file này đặt trong /var/www/Zend/application/views/scripts , nội dung file như sau :

<form action='<?php echo $this->element->getAction(); ?>'
method= '<?php echo $this->element->getMethod(); ?>'>
<p>Your Name:<br />
<?php echo $this->element->name; ?>
</p>
<p>Your Email:<br />
<?php echo $this->element->email; ?>
</p>
<p>Your Gender:<br />
<?php echo $this->element->gender; ?>
</p>
<p>Your Country:<br />
<?php echo $this->element->country; ?>
</p>
<p>Your Note:<br />
<?php echo $this->element->note; ?>
</p>
<p><?php echo $this->element->submit; ?>
</p>
</form>

4. Tìm file Bootstap.php trong thư mục : /var/www/Zend/application , thêm nội dung sau vào :

protected function _initAutoload(){ 
        $autoloader = new Zend_Application_Module_Autoloader(array( 
                    'namespace' => '', 
                    'basePath' => dirname(__FILE__),));

        return $autoloader; 
    }


5. Tạo file index.phtml ,file này nàm trong thư mục :/var/www/Zend/application/views/scripts/user , nội dung file :

<?php
echo $this->form;
?>


6. Demo : bạn mở trình duyệt lên và gõ vào: localhost/thư mục cài Zend Framework /user ,rồi enter xem kết quả .

7. Video demo :









Hiệu chỉnh layout Zend Framework trên Linux

Posted by Unknown Thứ Hai, tháng 9 09, 2013, under | No comments

Hướng dẫn chạy ứng dụng đầu tiên cho Zend Framework trên Linux

Posted by Unknown Thứ Hai, tháng 9 09, 2013, under | No comments

Hướng dẫn cài Zend Framework trên Linux Mint 15

Posted by Unknown Thứ Hai, tháng 9 09, 2013, under | No comments


HOW TO INSTALL ZEND FRAMEWORK IN LINUX MINT
you have installed:
-install websever
-install php
-install phpmysqladmin

1. install ZF:
sudo apt-get install zend-framework

2. Check version ZF:
zf show version

3. Move the cursor to folther webroot:
cd /var/www

4. Creating profect for ZF( my profect "Zend"):
zf create project Zend

5.  Move the cursor to folther "library" in profect :
cd /library

6. Copy library for zend :
sudo ln -s /usr/share/php/libzend-framework-php/Zend/

7. See tree Folther ZF:
tree 
(install tree: sudo apt-get install tree )

8. Change https://localhost/Zend -> http://Zend/

a. find host in folther " /etc ":
Del " 127.0.0.1  localhost"
add " 127.0.0.1  Server "

b. find default in folther "/etc/apache2/sites-available":
add code :

NameVirtualHost *:80
<VirtualHost *:80>
ServerName Server
DocumentRoot /var/www/Zend/public/>
<Directory /var/www/Zend/public>
                Options Indexes FollowSymLinks MultiViews
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

9. test : https://sever/       or  https://localhost/Zend/public/

10. Note :
a. restart apache2 : service apache2 restart
b. admin for folder/file : sudo -i -> password ->enter->cd /path/to/folder -> chown user.user folder/file

10. The end. ( visit :https://toantinit.blogspot.com )


Xem Nhiều

Bài đăng phổ biến

Lưu trữ blog

Blog Archive