久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

將 URL 路由轉(zhuǎn)換為函數(shù)參數(shù) php mvc

turn URL route into funciton arguments php mvc(將 URL 路由轉(zhuǎn)換為函數(shù)參數(shù) php mvc)
本文介紹了將 URL 路由轉(zhuǎn)換為函數(shù)參數(shù) php mvc的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在為 PHP 項(xiàng)目編寫自定義 MVC 框架,一切都很好,直到從 URL 路由獲取參數(shù)為止.我堅(jiān)持將 URL 路由的一部分動(dòng)態(tài)傳遞給函數(shù)參數(shù).我已經(jīng)有一個(gè)方法,它只是為了內(nèi)爆路由并使用數(shù)組作為函數(shù)參數(shù),但我真的很想知道如何像在 CodeIgnitor 或 CakePHP 中那樣做.

I'm writing a custom MVC framework for a PHP project and everything is great until it comes to getting arguments from the URL route. I'm stuck on passing parts of the URL route into a function argument dynamically. I already have a method which is just to implode the route and use the array for the function arguments but I would really like to know how to do it like in CodeIgnitor or CakePHP.

這就是我想要做的.網(wǎng)站網(wǎng)址將是...

Here's what i want to have done. The site url would be...

url: http://yoursite.com/profile/view/35/foo

在我的控制器中,我會(huì)...

and in my controller I would have...

<?php

Class profileController Extends baseController 
{

    public function view($ID, $blah)
    {
        echo $ID; //would show 35
        echo $blah; //would show foo
    }

}

?>

我真的很想知道這是如何完成的.非常感謝!

I would really like to know how this is done. Thanks a lot!

推薦答案

處理此問題的最簡單方法是使用 call_user_func_array() 函數(shù).您可以按如下方式使用它:

The easiest way to handle this is to use the call_user_func_array() function. You would use it as follows:

call_user_func_array(array($controller, $method), $params);

$controller 將是您已經(jīng)創(chuàng)建的控制器對象,而 $method 將是控制器的方法.然后 $params 是從 URI 收集的參數(shù)數(shù)組.您只需要取出 URI 的控制器/方法部分.

$controller would be the controller object you have already created, and $method would be the controller's method. Then $params is an array of the parameters collected from the URI. You would just need to take out the controller/method portion of the URI.

您也可以使用 Reflection 來做到這一點(diǎn),但這通常是比使用上述方法慢.

You could also do this using Reflection, but this typically is slower than using the above method.

這篇關(guān)于將 URL 路由轉(zhuǎn)換為函數(shù)參數(shù) php mvc的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動(dòng)作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應(yīng)用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發(fā)技術(shù)
Having a single entry point to a website. Bad? Good? Non-issue?(有一個(gè)網(wǎng)站的單一入口點(diǎn).壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務(wù)層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 中文字幕一区在线观看视频 | 亚洲精品黑人 | 亚洲黄色一级 | 亚洲精品免费视频 | www国产成人免费观看视频,深夜成人网 | 天天天天天操 | av在线免费观看网站 | 国产精品18hdxxxⅹ在线 | 婷婷久 | 一级黄a视频 | 亚洲 成人 av | 日韩av电影院 | 日本一区二区高清视频 | 日韩av免费在线电影 | 午夜精品一区二区三区在线视频 | 天堂一区二区三区 | av一区二区三区四区 | 国产成人精品在线 | 9久久 | 国产亚洲日本精品 | 天天综合天天 | 国产精品一区二区久久精品爱微奶 | 亚洲永久免费观看 | 成人a在线| 欧美一区二区三区在线 | 亚洲精品国产a久久久久久 中文字幕一区二区三区四区五区 | 天天操妹子 | 国产精品久久欧美久久一区 | 亚洲欧美一区二区三区在线 | 97免费在线观看视频 | 国产精品一区在线观看 | 国产精品一区久久久 | 欧美精品一区二区三区四区 在线 | 免费亚洲网站 | 亚洲精品久久久久中文字幕欢迎你 | 成人一级片在线观看 | 欧美最猛黑人xxxⅹ 粉嫩一区二区三区四区公司1 | 久久国产日韩 | 99成人| 爱草在线| 中文字幕在线观看第一页 |