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

分享

Zend Framework配置

 dlshanghai 2013-04-24

1.php開啟PDO

php.ini

①開啟extension=php_pdo.dll

②開啟extension=php_pdo_mysql.dll

去掉之前;

2.apache開啟rewrite模塊

httpd.conf

①開啟rewrite_module

LoadModule rewrite_module modules/mod_rewrite.so

②開啟.htaccess目錄識別AllowOverride None改成All

<Directory />

    Options FollowSymLinks

    AllowOverride None

    Order deny,allow

    Deny from all

    Satisfy all

</Directory>

None改為all

AllowOverride None改為All注意共有兩處

④重啟apache

3.zendframework下新建文件.htaccess

內(nèi)容為:

RewriteEngine on

RewriteRule .* index.php

php_flag magic_quotes_gpc off

php_flag register_globals off

4.zendframework下新建文件index.php

<?php

                error_reporting(E_ALL|E_STRICT); //在開啟錯誤報告

                date_default_timezone_set('Asia/Shanghai'); //配置地區(qū)

set_include_path('.' .PATH_SEPARATOR .'./library'.PATH_SEPARATOR .'./application/models/'.PATH_SEPARATOR . get_include_path());  //配置環(huán)境路徑

                //require_once 'Zend/Loader.php';

                //Zend_Loader::registerAutoload();//設(shè)置Zend Framework 自動載入類文件

                require_once "Zend/Loader/Autoloader.php";  //載入zend框架

                Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true); //靜態(tài)載入自動類文件

                $registry = Zend_Registry::getInstance(); //靜態(tài)獲得實例

                $view = new Zend_View(); //實例化zend 模板

                $view->setScriptPath('./application/views/scripts/');//設(shè)置模板顯示路徑

                $registry['view'] = $view;//注冊View

                //設(shè)置控制器

                $frontController =Zend_Controller_Front::getInstance();

                $frontController->setBaseUrl('/zendframework')//設(shè)置基本路徑

                                                                                ->setParam('noViewRenderer', true)

                                                                                ->setControllerDirectory('./application/controllers')

                                                                                ->throwExceptions(true)

                                                                                ->dispatch();

?>

5.zendframework\application\controllers

新建IndexController.php

內(nèi)容

<?php

class IndexController extends Zend_Controller_Action

{             

                function init() //__construct 代替初始化函數(shù)

    {

        $this->registry = Zend_Registry::getInstance();

        $this->view = $this->registry['view'];

        $this->view->baseUrl = $this->_request->getBaseUrl();

           

    }

/*

                 * Action(動作)!

                 */

                function indexAction()

    { echo "測試成功";}

}

6.瀏覽器中打開http://localhost/zendframework、http://localhost/zendframework/index、

http://localhost/zendframework/index/index均顯示測試成功。

否則查看apache配置中的AllowOverride None

7.通過視圖測試

打開zendframework\application\controllers\IndexController.php

修改

function indexAction()

    { echo "測試成功";}

改為

function indexAction()

{

$a="視圖測試";

$this->view->php=$a;

echo $this->view->render('index.phtml');//顯示模版

}

8.建立模板

zendframework\application\controllers\views\scripts

新建文件index.phtml與上面文件名對應

內(nèi)容

<?php

print_r($this->php);//此處的phpindexAction()中對應

?>

9.測試模板

瀏覽器中分別輸入http://localhost/zendframework/http://localhost/zendframework/index、

http://localhost/zendframework/index/index

測試結(jié)果應該一樣

10.建立自己的Action方法

打開zendframework\application\controllers\IndexController.php

在類IndexController

建立

function myAction(){//注意大小寫

echo "this is myAction";

}

11.測試

瀏覽器中輸入http://localhost/index/my

顯示結(jié)果this is myAction表示正確

小結(jié):

URL的第一個部份會映射到一個控制器,第二個部份則映射到控制器類中的Action(即控制器類內(nèi)部的一個方法)。

②類名包含多個單詞,每個單詞的第一個字母必須大寫,連續(xù)的大寫是不允許的

③函數(shù)名總是以小寫開頭,當函數(shù)名包含多個單詞,每個子的首字母必須大寫

④常量名的所有字母必須大寫。

⑤對于只包含有 PHP 代碼的文件,結(jié)束標志("?>")是不允許存在的,PHP自身不需要("?>", 這樣做, 可以防止它的末尾的被意外地注入相應。

5.數(shù)據(jù)庫操作

application文件夾下創(chuàng)建一個config文件夾

然后建立config.ini,不要加引號,注意下面不能加注釋

[general]

db.adapter=PDO_MYSQL

db.config.host=localhost

db.config.username=root

db.config.password=

db.config.dbname=zend

②配置文件引入到zendframework中在index.php

                //配置數(shù)據(jù)庫參數(shù),并連接數(shù)據(jù)庫

                $config=new Zend_Config_Ini('./application/config/config.ini',null, true);

Zend_Registry::set('config',$config);

                $dbAdapter=Zend_Db::factory($config->general->db->adapter,$config->general->db->config->toArray());

                $dbAdapter->query('SET NAMES UTF8');

                Zend_Db_Table::setDefaultAdapter($dbAdapter);

                Zend_Registry::set('dbAdapter',$dbAdapter);

③建模塊applications/models/,模塊名和類名一致

Message

模塊內(nèi)容<?php

class Message extends Zend_Db_Table

{

                protected $_name ="message";//表名

                protected $_primary = 'id';//主鍵

}

?>

④控制器

<?php

class IndexController extends Zend_Controller_Action

{

                function init()//初始化

    {

        $this->registry = Zend_Registry::getInstance();

        $this->view = $this->registry['view'];

        $this->view->baseUrl = $this->_request->getBaseUrl();

    }

                function indexAction()

    {

                $message=new message();//實例化數(shù)據(jù)庫類

        //獲取數(shù)據(jù)庫內(nèi)容

        $this->view->messages=$message->fetchAll()->toArray();//將查找到的數(shù)據(jù)轉(zhuǎn)換成數(shù)組存放到messages

                                echo $this->view->render('index.phtml');//顯示模版

    }

function addAction(){

                //如果是POST過來的值.就增加.否則就顯示增加頁面

                if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){

                                                $content=$this->_request->getPost('content');

                                                $title=$this->_request->getPost('title');

                                                $message=new Message();

                                                $data=array(

                                                                                'content'=>$content,

                                                                                'title'=>$title

                                                );

                                                $message->insert($data);

                                                unset($data);

                                                echo '您增加數(shù)據(jù)成功!請您<a href="'.$this->view->baseUrl.'/index/index/">返回</a>';

                }else{

                                echo $this->view->render('add.phtml');//顯示增加模版

                }

    }

}

views/scripts/index.phtml

<?php foreach($this->messages as $message): ?>

                   <tr>

                    <th><?php echo $message['id']; ?></th>

                                <td><?php echo $message['name']; ?></td>

                  </tr>

                  <?php endforeach; ?>

6.常用數(shù)據(jù)庫函數(shù)

☆☆fetchAll($sql):取回結(jié)果集中所有字段的值,作為連續(xù)數(shù)組返回

☆☆fetchRow($sql):只取回結(jié)果集的第一行

fetchAssoc($sql):取回結(jié)果集中所有字段的值,作為關(guān)聯(lián)數(shù)組返回

fetchCol($sql):取回所有結(jié)果行的第一個字段名

fetchOne($sql):只取回第一個字段值

fetchPairs($sql):取回一個相關(guān)數(shù)組,第一個字段值為碼 第二個字段為值

插入

insert( $arrParams )

    $arrParams:關(guān)聯(lián)數(shù)組, key是數(shù)據(jù)庫字段,鍵值是字段值

    return:lastInsertId返回插入的最后一行的id

更新修改

update( $arrParams,$strSqlWhere )

    $arrParams:關(guān)聯(lián)數(shù)組, key是數(shù)據(jù)庫字段,通過一個where條件從句來決定需要改變的行,返回被修改的行數(shù),自動加引號處理

    $strSqlWhere:條件

$table=new RoundTable();

$db=$table->getAdapter();

$set=array('color'=>'yellow');

$where=$db->quoteInto('first_name?',)

$table->update($set,$where);

刪除

delete( $strSqlWhere )

    $strSqlWhere:條件返回被刪除的行數(shù)

$where=$db->quoteInto('first_name?',);

$table->delete($where);

7.視圖循環(huán)和條件函數(shù),模板引擎中

foreach循環(huán)

foreach(循環(huán)條件):......endforeach;//不同處,沒有大括號而是冒號,且有end

if條件

if(條件):......endif;

if():....

else:

endif;

 

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

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多