 |
|
Var คือการประกาศตัวแปรที่ใช้กันใน Class ครับ อย่าง Class นึงจะมีฟังก์ชั่นอยู่ในนั้นหลายฟังก์ชั่นเลย
ก็สามารถเอามันมาใช้ได้ ทั้งหมด ทุกฟังก์ชั่นเลยเช่น
Code (PHP)
<?php
require_once(WEB_LIB_DIR . 'AdminAction.class.php');
class addcateAction extends AdminAction
{
var $Table1 = "_cate";
var $fieldNames = Array('cat_id', 'cat_title', 'cat_sort', 'cat_msg' );
function getDefaultView(&$controller, &$request, &$user)
{
$Table1 = PTB."".$this->Table1;
if(empty($_POST))
{
foreach($this->fieldNames as $field)
{
$_POST[$field] = '';
}
}
return VIEW_INPUT;
}
function Execute(&$controller, &$request, &$user)
{
$Table1 = PTB."".$this->Table1;
$fieldInsert = "";
$valueInsert = "";
$arr = array();
$i = 0;
$catTitle = $_POST['cat_title'];
$catMsg = $_POST['cat_msg'];
$arr = array($catTitle, $catMsg);
$fq = "INSERT INTO ".$Table1;
$fq .= "(cat_title,cat_msg) VALUES (?,?)";
$rs = $this->DB->Execute($fq, $arr);
$controller->redirect(WEBROOT_PATH . "/".mObject."/hcontent/".mAccess."/Index");
}
?>
เวลาเอาตัวแปรที่กำหนด Var ใน Class มาใช้ ให้ใส่ $this->ตัวแปร ด้วยอ่ะ
เราเอาตัวแปร Table1 มาใช้ได้ทั้ง GetDefault และ Execute เลย
หมายเหตุ PTB คือค่า define prefix ของชื่อตาราง
define("PTB","pp");
ดังนั้น
$Table1 = PTB."".$this->Table1;
ค่าของ $Table1 ก็จะเป็น "pp_cate" เป็นต้น
|
 |
 |
 |
 |
Date :
2009-06-05 23:47:24 |
By :
sirikulo |
|
 |
 |
 |
 |
|
|
 |