小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

AMP開發(fā)技術(shù)文檔

 NaturalWill 2014-03-21
AMP開發(fā)技術(shù)文檔

AMP系統(tǒng)目錄結(jié)構(gòu) ------------------------------------------------------------------

Amysql) 系統(tǒng)目錄

      | Amysql.php

      | Config.php

Controller) 控制器文件目錄

Model) 數(shù)據(jù)模型文件目錄

View) 視圖模板文件目錄

      | AmysqlNotice.php

Class) 對象類文件目錄

 index.php




AMP運行流程 ---------------------------------------------------------------------------

為了更好的掌握應(yīng)用AMP,我們先來簡單了解下AMP運行流程。

01) index.php ? 載入配置文件、系統(tǒng)文件進入系統(tǒng)層(A層)。實例化主進程Amysql、實例化進程AmysqlProcess ? 分析用戶請求控制器與方法并執(zhí)行。

02) 執(zhí)行用戶控制器方法進行邏輯處理層(C層)同時初始化視圖模板層(V層),此時用戶控制器(C層)繼承于系統(tǒng)AmysqlController,擁有系統(tǒng)載入數(shù)據(jù)模型、引入新類、模板數(shù)據(jù)處理等方法。

03) (C層)中可載入用戶自定義數(shù)據(jù)模型(M層),此時用戶數(shù)據(jù)模型(M層)同樣繼承于系統(tǒng)AmysqlModel,擁有Mysql讀寫等操作方法。(無數(shù)據(jù)請求可略此過程)

04) (C層)賦值于模板(V層)。

05) (V層)顯示完成。

A ? C ? M ? V 很簡單,這就是MVC,似乎ACMV更好理解。






簡單應(yīng)用AMP -----------------------------------------------------------------------

01) 首先需要簡單配置下系統(tǒng)文件,進入Amysql系統(tǒng)目錄。打開配置文件Config.php。

文件當(dāng)中有注釋各參數(shù)的使用用途,其中可配置Url模式、過濾、調(diào)試、編碼、名稱與其數(shù)據(jù)庫默認連接等基本信息(無Mysql應(yīng)用話可無需配置Mysql信息)

02) 簡單配置完成后下一步創(chuàng)建控制器文件。進入Controller文件目錄創(chuàng)建控制器文件index.php寫入以下代碼:(提示:系統(tǒng)默認運行的控制器為index、默認的執(zhí)行方法為IndexAction,同時要注意控制器的class名稱需與文件名稱保持一致。)


            <?php
            
class index extends AmysqlController
            
{
                function 
IndexAction()
                {
                    echo 
'Hello World';
                }

                function 
HelloAMP()
                {
                    echo 
'Hello AMP';
                }
            }
            
?>
            

03) 打開http://localhost/AMP/ 就可看到瀏覽器輸出Hello World信息。
打開http://localhost/AMP/index.php/index/HelloAMP 或http://localhost/AMP/index.php?c=index&a=HelloAMP 就可看到Hello AMP。至此您已完成了偉大Hello World例子。






AMP輕松上手,控制器與模型方法 -----------------------------------------------------------------------

控制器常用的一些方法。


            <?php
            
class index extends AmysqlController
            
{
                function 
IndexAction()
                {
                    
$this -> name $name;         // 簡單賦值 
                    
$this -> _DBSet($Config);    // 如有設(shè)置此項同時可進行多個mysql連接。 $Config : 配置
                    
$this -> _array($array);    // 數(shù)組多模板變量賦值 $array : 數(shù)據(jù)

                    
$this -> _echo($data);    // 數(shù)據(jù)調(diào)試
                    
$this -> _view($file);    // 模板顯示

                     // 加載自定義類文件 $file 文件名, $ClassName 類名(可選,默認為文件名)
                    
$this -> _class($file$ClassName); 

                     
// 加載模型文件 $file 文件名, $ClassName 類名(可選,默認為文件名)
                    
$this -> _model($file$ClassName);

                    
// 獲得相關(guān)文件數(shù)據(jù)(模板目錄) $file 文件名
                    
$this -> _file($file);
                    
                }
            }
            
?>
            

模型常用的一些方法。


            <?php
            
class datas extends AmysqlModel
            
{
                function 
databases()
                {
                    
$this -> _query($sql);    // 執(zhí)行Sql

                    // 更新數(shù)據(jù) $table表名,$data數(shù)據(jù)array('field' => 'value'), $where條件Sql
                    
$this -> _update($table$data$where '');    

                    
// 插入數(shù)據(jù) $table表名,$data數(shù)據(jù)array('field' => 'value')
                    
$this -> _insert($table$data);

                    
$this -> _row($sql);    // 取得一行數(shù)據(jù)
                    
$this -> _all($sql);    // 取得所有數(shù)據(jù)
                    
$this -> _sum($sql);    // 取得數(shù)據(jù)總數(shù)
                
}
            }
            
?>
            





AMP應(yīng)用實例 --------------------------------------------------------------------

下面通過一實例,介紹Mysql數(shù)據(jù)調(diào)用、引用新class、模板數(shù)據(jù)賦值、調(diào)試等方法。

01) 數(shù)據(jù)模型文件創(chuàng)建,新class文件創(chuàng)建,準(zhǔn)備數(shù)據(jù)于控制器調(diào)用。

創(chuàng)建模型 Model/index.php 文件。

    <?php
    
class datas extends AmysqlModel
    
{
        function 
databases()
        {
            
$sql "SHOW DATABASES";
            Return 
$this -> _all($sql);    // _all方法取得所有數(shù)據(jù)返回
        
}
    }
    
?>

創(chuàng)建模型 Model/tables.php 文件。

    <?php
    
class tables extends AmysqlModel
    
{
        function 
GetTables()
        {
            
$sql "SHOW TABLES";
            Return 
$this -> _row($sql);    // _row方法取得一行數(shù)據(jù)返回
        
}
    }
    
?>

創(chuàng)建新對象 Class/NewClass.php 文件。

    <?php
    
class NewClass 
    
{
        public 
$name 'NewClass';
        function 
GetName()
        {
            Return 
$this -> name;    
        }
    }
    
?>


02) 控制器創(chuàng)建

創(chuàng)建 Controller/index.php 文件。

    <?php

        
class index extends AmysqlController
        
{
            function 
IndexAction()
            {
                 
// 1) 模板如何賦值
                
$this -> content 'Hello World';                                    // 單一賦值模板$content變量方式
                
$this -> MyName 'Amysql (AMP)';
                
$this -> ArrayData = array('Website' => 'http://''ProductType' => 'PHP MVC');
                
$this -> _array(array('NameA' => 'A''NameB' => 'B'));    // _array方法數(shù)組賦值模板變量$NameA、$NameB

                // 2) 如何連接Mysql查詢數(shù)據(jù) 
                
$IndexModel $this -> _model('index''datas');            // 載入步驟1)創(chuàng)建的index模型文件datas模型對象
                
$this -> databases $IndexModel -> databases();        // 執(zhí)行模型的databases方法取得數(shù)據(jù)直接賦值模板

                // 2.1) 可同時創(chuàng)建新Mysql連接
                
$this -> _DBSet(array('DBname' => 'information_schema''ConnectTag' => 'NewContent'));        
                
// 鏈接新數(shù)據(jù)庫 設(shè)置新的Mysql連接信息

                
$tables $this -> _model('tables');                    // 載入步驟1)創(chuàng)建的tables模型文件的tables模型對象
                
$this -> tables $tables -> GetTables();            // 執(zhí)行模型的GetTables方法取得數(shù)據(jù)直接賦值模板

                // 3) 如何引入新Class對象
                
$EchoName $this -> _class('NewClass') -> GetName();    
                
// 載入步驟1)創(chuàng)建NewClass類文件的NewClass對象并執(zhí)行GetName方法

                // 4) 信息調(diào)試
                
$this -> _echo($EchoName);                            // 信息輸出在網(wǎng)頁源代碼最底部

                
$this -> _view('index');                                    // 調(diào)用模板輸出
            
}
        }
    
?>


03) 模板文件創(chuàng)建

創(chuàng)建 View/index.php 文件。

    <? // 添加以下模板代碼:

    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www./TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
html xmlns="http://www./1999/xhtml">
    <
html>
    <
head>
    <
title><?php echo $content;?></title>
    </HEAD>

    <BODY>
    <p><?php echo $MyName;?></p>
    <p><?php echo $content;?></p>
    <p>NameA : <?php echo $NameA;?></p>
    <p>NameB : <?php echo $NameB;?></p>

    <pre>
    <?php
        print_r
($ArrayData);
        
print_r($databases);
        
print_r($tables);
    
?>
    </pre>
    </BODY>
    </HTML>

04) 到這里已完成了,打開http://localhost/AMP/ 就可看到瀏覽器輸出模板各變量數(shù)據(jù)信息。






最后您還需簡單了解一下這些參數(shù) -----------------------------------------------------------------------

系統(tǒng)一些目錄參數(shù)與系統(tǒng)各模塊對象關(guān)系


            <?php
            
class index extends AmysqlController
            
{
                function 
IndexAction()
                {
                    echo  
_Host '<br />';                // 主機網(wǎng)址
                    
echo  _Http '<br />';                // 網(wǎng)站根目錄網(wǎng)址,常用。
                    
                    
echo  _ROOT '<br />';                // 網(wǎng)站根目錄
                    
echo  _Amysql '<br />';            // 系統(tǒng)目錄
                    
echo  _Controller '<br />';        // 控制器目錄
                    
echo  _Model '<br />';            // 模型目錄
                    
echo  _Class '<br />';            // 對象類目錄
                    
echo  _View '<br />';            // 視圖模板目錄

                    /*********************
                     * 深入底層 > 系統(tǒng)各模塊關(guān)聯(lián)調(diào)用
                     * 靈活掌握應(yīng)用,請查看$Amysql各對象關(guān)系。
                     */
                    
global $Amysql;
                    echo 
'<pre>';
                    
print_r($Amysql);
                    echo 
'</pre>';
                }
            }
            
?>
            

End -----------------------------------------------------------------------

到這里AMP的應(yīng)用介紹文檔就結(jié)束了,感謝選擇AMP框架,

如有使用有任何疑問請點這里反饋。

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多