สงสัยเรื่องของการ Router

อ่านในคู่มือแล้วยังไม่ค่อยเข้าใจครับ... สรุปว่าคชสารสามารถใช้งาน Router ได้แบบไหนครับ พอดีทดลองทำตามแล้วยังไม่ได้

สมมติว่าต้องการเรียก method ที่ชื่อ get ผ่านทาง url ต้องพิมพ์ยังไงครับ? ขอกรณีต้องส่งพารามิเตอร์ด้วยนะครับ
(ที่ลองคือ http://localhost/...llers/index.php/get)

namespace Index\Index;

class Controller extends \Kotchasan\Controller
{

public function Index(Request $request)
{
echo "This is index";
}

public function get($user_id)
{
echo "This is get";
}
}
Kenji 03 ก.ย. 2559 2 1,562
0SHAREFacebookLINE it!

https://github.com/...hasan/Router.php#L27
// index.php/module/model/folder/_dir/_method
'/^[a-z0-9]+\.php\/([a-z]+)\/(model)(\/([\/a-z0-9_]+)\/([a-z0-9_]+))?$/i' => array('module', '_mvc', '', '_dir', '_method'),

คชสารอนุญาติให้เรียกตรงๆได้เฉพาะ model ครับ เพื่อเป็นการป้องกันการเรียกโดยไม่ตั้งใจ เช่น
index.php/index/model/module/save จะหมายถึงเรียกไปที่
\Index\Module\Model::save()
ในกรณีที่เรียกตรงๆ จะเรียกผ่าน
https://github.com/...hasan/Router.php#L29
// index/model/_dir
'/([a-z]+)\/(model|controller|view)\/([a-z0-9_]+)/i' => array('module', '_mvc', '_dir'),

ซึ่งคชสารจะอนุญาติให้เรียกไปยัง method index ได้เท่านั้น
index.php/index/controller/index จะหมายถึงเรียกไปที่
\Index\Index\Controller::index()
ในกรณีที่จำเป็นจริงๆ สามารถ override Router ได้ ตัวอย่างคือ GCMS ครับ
#1

ในกรณีที่ต้องการรับค่าด้วย เมธอดที่ถูกเรียกจะมี parameter ติดมาด้วย 1 ตัวคือ $request ครับ
public function save(Request $request) {
// $id = isset($_POST['id']) ? (int)$_POST['id'] : 0;
$id = $request->post('id')->toInt();
}

http://doc.kotchasan.com/...an.Http.Request.html มี method post(), get(), request() ...
http://doc.kotchasan.com/...hasan.InputItem.html มี method toInt(), toString(), url(), topic() ....
ตัวอย่าง https://github.com/...pdateprofile.php#L38
#2
ความคิดเห็น
ไฟล์อัปโหลด ชนิด jpg, jpeg, png ขนาดไฟล์ไม่เกิน 1024