啊快來幫幫忙呀

來源:互聯網
上載者:User
求助啊,快來幫幫忙呀。
最近在學習MVC開發模式。現在遇到個問題,就是自動載入類的問題。比如說我建一個控制器,AdminAction.php.然後我想讓他繼承同目錄下的FirstAction.php.而且我想直接Class AdminAction extends FirstAction.不想先Include ‘FirstAction.php'.能不能用__autoload來實現啊。為甚ThinkPHP裡面就是可以直接建立一個Action就直接寫繼承他的基類Action而不用引入啊。求大神幫忙開導下 MVC??類繼承?自動載入

分享到:


------解決方案--------------------
// PHP5 Used __autoload function 
$obj_A = new clsA(); // in "cls" directory!
$obj_B = new clsB(); // in "cls/cls" directory!
function __autoload($className){
if(strtolowwer($className) == "clsb"){
require_once "cls/cls/$className.php";
}else{
include_once "cls/$className.php";
}
}
?>

------解決方案--------------------
// ./myClass.php
class myClass {
public function __construct() {
echo "myClass init'ed successfuly!!!";
}
}
?>

// ./index.php
// we've writen this code where we need
function __autoload($classname) {
$filename = "./". $classname .".php";
include_once($filename);
}

// we've called a class ***
$obj = new myClass();
?>

------解決方案--------------------
一般好像是在使用多個類才這樣使
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.