标题: 我在1.03版本里运行的index.php
  本主题由 haohappy 于 2008-1-2 22:31 设置高亮 
mmocom
注册会员
Rank: 2



UID 58
精华 6
积分 70
帖子 21
翻译 0
原创 1
阅读权限 20
注册 2007-6-6
状态 离线
发表于 2008-1-2 17:33  资料  短消息  加为好友  添加 mmocom 为MSN好友 通过MSN和 mmocom 交谈
我在1.03版本里运行的index.php



PHP代码如下:

<?php
error_reporting
(E_ALL|E_STRICT);
date_default_timezone_set('Asia/Shanghai');
$ds DIRECTORY_SEPARATOR;//目录分隔符号
$ps PATH_SEPARATOR;//路径分隔符号

define('ABS_ROOT_PATH'realpath(dirname(__FILE__)));
define('REL_ROOT_PATH'substr($_SERVER['PHP_SELF'], strpos($_SERVER['PHP_SELF'],'/index.php')));

set_include_path('.'.PATH_SEPARATOR.'./library'.PATH_SEPARATOR.'./application/models/'.PATH_SEPARATOR.get_include_path());

require_once 
'Zend/Loader.php';

//自动加载类
Zend_Loader::registerAutoload();

//数据库配置
$dbParams = new Zend_Config_Ini('./config/config.ini','SysDB');
$db Zend_Db::factory($dbParams->adapter,$dbParams->toArray());
$db->query("set names {$dbParams->charset};");
Zend_Db_Table::setDefaultAdapter($db);
Zend_Registry::set('sysdb',$db);

//SMARTY配置
$smartyParams = new Zend_Config_Ini('./config/config.ini''SysTpl');
$smarty = new Custom_View_Smarty($smartyParams->toArray());
Zend_Registry::set('systpl',$smarty);

//全局定义
$sysinfoParams = new Zend_Config_Ini('./config/config.ini','SysGlobalInfo');
Zend_Registry::set('sysinfo',$sysinfoParams->toArray());

//初始控制器
$router = new Zend_Controller_Router_Rewrite();
$frontController Zend_Controller_Front::getInstance();
$frontController->setRouter($router);
$frontController->setControllerDirectory(array(
    
'default' => './application/controllers',

));
$frontController->throwExceptions(true);
$frontController->setParam('noViewRenderer',true); 
$frontController->setBaseUrl(REL_ROOT_PATH);

try{
    
$frontController->dispatch();
}catch(
Zend_Controller_Dispatcher_Exception $e){
    echo 
nl2br($e->__toString());
}
unset(
$db);
unset(
$smarty);
?>


config.ini

[SysDB]
adapter                 =         pdo_mysql
host                 =         localhost
username         =         root
password         =       
dbname                 =         mmocom
charset                 =         utf8
prefix           =


[SysGlobalInfo]
test = true


[SysTpl]
left_delimiter                =        "{"
right_delimiter                =        "}"
template_dir                =        "./www/templates"
compile_dir                =        "./www/templates_c"

IndexController.php

PHP代码如下:

<?php
class IndexController extends Zend_Controller_Action
{
    public function 
preDispatch()
    {

    }
    
    public function 
init()
    {
        
$this->db Zend_Registry::get('sysdb');
        
$this->tpl Zend_Registry::get('systpl');
        
$this->globalinfo Zend_Registry::get('sysinfo');        
    }

    public function 
indexAction()
    {
        
$this->tpl->display('index.html');
    }
    
    public function 
testAction()
    {
        echo 
"test";
        echo 
__FILE__;
    
    }
    
    public function 
__call($method$args)    
    {        
        if (
'Action' == substr($method, -6)) 
        {       
//            return $this->_forward('index');    
            
echo 'Invalid method "' $method '" called';
            exit; 
        }
        throw new 
Exception('Invalid method "' $method '" called');    
    }
    
    public function 
noRouterAction()
    {
//        $this->_redirect('/');
    
}


}
?>


大家的意见是我努力的动力

[ 本帖最后由 mmocom 于 2008-1-2 17:45 编辑 ]



 附件: 您所在的用户组无法下载或查看附件
顶部
haohappy
超级版主
Rank: 8Rank: 8
PHPEye站长


UID 2
精华 11
积分 110
帖子 280
翻译 6
原创 1
阅读权限 150
注册 2007-5-2
状态 离线
发表于 2008-1-2 22:30  资料  短消息  加为好友  添加 haohappy 为MSN好友 通过MSN和 haohappy 交谈
不错,对新手很有用,加入精华





互助共享,共同成长。
顶部
cosnis
新手上路
Rank: 1



UID 670
精华 0
积分 0
帖子 8
翻译 0
原创 0
阅读权限 10
注册 2007-12-21
状态 离线
发表于 2008-1-5 15:07  资料  短消息  加为好友 
? models ? module?


我觉得ZF的 autoload 不是很爽


autoload( 'class' );
autoload( 'class' );
autoload( 'class' );
autoload( 'class' );
的用....

我的autoload
function __autoload( $class )
{
        if( is_array( $class ) ) { foreach( $class as $val ) { Zend_Loader::loadClass( $val ); } }
        else { Zend_Loader::loadClass( $class ); }
}

另外  为什么 我的 public function noRouterAction()
不起作用  请求一个空的 controller 的时候是报错.....

不喜欢 echo nl2br($e->__toString());

用 zend_debug::dump(); 嘿嘿

[ 本帖最后由 cosnis 于 2008-1-5 15:37 编辑 ]





小菜一只.....
顶部
断桥残雪
新手上路
Rank: 1



UID 542
精华 0
积分 0
帖子 3
翻译 0
原创 0
阅读权限 10
注册 2007-11-9
状态 离线
发表于 2008-1-9 22:41  资料  短消息  加为好友 
如何设置数据表前缀呢?

顶部
huangam
新手上路
Rank: 1



UID 424
精华 0
积分 0
帖子 8
翻译 0
原创 0
阅读权限 10
注册 2007-10-10
状态 离线
发表于 2008-1-10 18:45  资料  短消息  加为好友 
回复 #3 cosnis 的帖子

/////另外  为什么 我的 public function noRouterAction()

我是这个也不起作用

顶部
Cykit
新手上路
Rank: 1



UID 729
精华 0
积分 0
帖子 15
翻译 0
原创 0
阅读权限 10
注册 2008-1-14
状态 离线
发表于 2008-1-14 22:01  资料  短消息  加为好友 
似乎是 noRouteAction , Route 不是 Router

顶部
frogsky
新手上路
Rank: 1



UID 767
精华 0
积分 0
帖子 2
翻译 0
原创 0
阅读权限 10
注册 2008-1-24
来自 深圳
状态 离线
发表于 2008-1-24 19:26  资料  短消息  加为好友  添加 frogsky 为MSN好友 通过MSN和 frogsky 交谈
对新手有帮助o(∩_∩)o...。。。

顶部
yeahdwb
新手上路
Rank: 1



UID 834
精华 0
积分 0
帖子 1
翻译 0
原创 0
阅读权限 10
注册 2008-2-23
状态 离线
发表于 2008-2-23 17:50  资料  短消息  加为好友 
找了两天了,终于看到了想看到的东西了 谢谢楼主

顶部
 


PHPEye开源社区


当前时区 GMT+8, 现在时间是 2008-11-21 22:04

    Powered by Discuz! 5.5.0  © 2001-2007 Comsenz Inc.
Processed in 0.030392 second(s), 7 queries , Gzip enabled

清除 Cookies - 联系我们 - PHPEye开源社区 - Archiver