 |
จะเรียก php function ภายใน class อย่างไรคะ ผ่าน Url |
|
 |
|
|
 |
 |
|
มีไม๊ใครสักคน ......
|
 |
 |
 |
 |
Date :
2015-08-14 00:05:29 |
By :
Saw-Series |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เรียกใช้โดยตรงไม่ได้ครับ ต้องเรียกผ่าน PHP อีกตัว
Code (PHP)
<?php
//KitchenController.php
Class Controller extends ConnectDb
Code (PHP)
<?php
//active.php
include "KitchenController.php";
$ctrl=new Controller();
$ctrl->fncUpdateType() ;
เป็นแค่ตัวอย่างพอสังเขปนะครับ แต่เนื่องจาก คลาสนี้มันมีการ extends จาก คลาสแม่ ConnectDb อีกที
ดังนั้น ต้อง include คลาสแม่ ก่อน ไม่งั้นมัน error ครับ
ส่วนวิธีการเรียกใช้ คงต้องอ่านคู่มือ ของ shell-soft ดูแล้วล่ะครับ
|
 |
 |
 |
 |
Date :
2015-08-14 01:04:25 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้เข้าใจแล้วค่ะ แต่เวลาจะเรียกผ่าน link จะทำอย่างไรคะ
Code (PHP)
$db = new Controller(DB_HOST,DB_USER,DB_PASS,DB_NAME);
//ตรงนี้
<a href="http://localhost/shellsoft/KitchenController?test.php?">test</a>
$db->strTable = "shell_queue";
$db->Orderby = "QueNo";
$queryQue = $db->fncSelectQueue();
while($table = mysql_fetch_array($queryQue)){
?>
<div class="col-xs-7 col-lg-5">
<h2><?php echo $table[QueTable]; ?></h2>
<table class="table">
<tr>
<th>รหัส</th>
<th>รายการ</th>
<th>จำนวน</th>
<th>สถานะ</th>
<th></th>
<th></th>
</tr>
<?php
$db->strTable = "shell_kitchen";
$db->strCondition = "KitchTable = '".$table[QueTable]."'";
$queryMenu = $db->fncSelectMenu();
while($menu = mysql_fetch_array($queryMenu)){
?>
<tr>
<td><?php echo $menu[KitchFoodID]; ?></td>
<td><?php echo $menu[KitchName]; ?></td>
<td><?php echo $menu[KitchQuan]; ?></td>
<td style="width: 10px;">
<span id="sType_<?php echo $menu[KitchFoodID] ?>"><?php echo $menu[KitchType]; ?></span>
</td>
<td>
<input type="submit" value="Cook" onclick="fncSetStatus('<?php echo $menu[KitchFoodID] ?>','Cooking..');">
</td>
<td>
<input type="submit" value="Finish" onclick="fncSetStatus('<?php echo $menu[KitchFoodID] ?>','Finish');">
</td>
</tr>
<?php
}
?>
</table>
Code (PHP)
class ConnectDb {
public function __construct($host,$user,$pass,$db_name)
{
$Connect = mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_query("SET NAMES utf8");
mysql_select_db($db_name);
}
}
|
ประวัติการแก้ไข 2015-08-14 02:36:14 2015-08-14 02:38:13
 |
 |
 |
 |
Date :
2015-08-14 02:30:08 |
By :
Saw-Series |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วถ้าจะเก็บตรง
Code (PHP)
if(isset($_REQUEST['test_call'])){
$this->test();
exit;
}
ไว้ภายใน class controller ซึ่งเก็บไว้อีกไฟล์ แต่เรียกผ่านทางหน้า view จะเรียกอย่างไรคะ
|
 |
 |
 |
 |
Date :
2015-08-14 11:38:01 |
By :
Saw-Series |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งง เรียกผ่าน หน้าวิว
ส่งเป็น parameter จาก controller ให้ views ง่ายกว่าไหมครับ
จัดการใน controller ให้เรียบร้อย แล้วส่งให้ views แสดงข้อมูล
แม้วิวมันจะทำงานกับ code PHP ได้แต่ก็มีข้อจำกัดในการเรียกใช้
หลายคำสั่งทำไม่ได้นะครับ ทำใน controller อยากได้อะไร ก็ load มาใช้งาน
ปล. หรือจะสร้างเป็น model
|
ประวัติการแก้ไข 2015-08-14 12:02:39
 |
 |
 |
 |
Date :
2015-08-14 12:01:48 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือ สรุปแล้วมันไม่มีวิธีที่จะเรียก function ใน class ผ่าน url ได้ในทันที โดยไม่ผ่าน php ตัวอื่นเลยใช่ป่ะค่ะ
|
 |
 |
 |
 |
Date :
2015-08-14 12:26:46 |
By :
Saw-Series |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับ
|
 |
 |
 |
 |
Date :
2015-08-14 14:11:54 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันต้องเรียกใช้ class ก่อน
ถึงจะนำไปใช้ได้
แบบนี้หรือป่าว?
|
 |
 |
 |
 |
Date :
2015-08-14 14:22:44 |
By :
CasanovaKung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้ายังงั้น วิธีนี้ ก็ยังไม่ใช่วิธีที่สุดที่จะเอามาใช้ทำงานใช่ป่าวคะเนี่ย = =
|
 |
 |
 |
 |
Date :
2015-08-14 16:45:09 |
By :
Saw-Series |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำ file process ขึ้นมาตัวนึง เช่น
เช่น process.php
Code (PHP)
require_once("KitchenController.php");
if(isset($_GET[fncUpdateType])){
$int_kit=new Controller();
$int_kit->fncUpdateType();
}
ตัว jquery ก็ post ไปที่
$.post("http://localhost/[path ที่เก็บ]/process.php?fncUpdateType",{.......
แต่ต้อง ระวังเรื่อง security ด้วย จะใช้ session หรือ จะ post ไปทุกค่าเลยก็ได้
|
 |
 |
 |
 |
Date :
2015-08-14 20:23:46 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะ กะลังลองศึกษาแล้วทำแบบ MVC ดูอยู่ค่ะ เคยใช้แต่ code ตอนนี้ลองเอามาทำเองบ้าง อิอิ
|
 |
 |
 |
 |
Date :
2015-08-14 23:25:33 |
By :
Saw-Series |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|