代码之家  ›  专栏  ›  技术社区  ›  JF Dion

Zend框架默认MVC实现

  •  1
  • JF Dion  · 技术社区  · 15 年前

    我使用Zend框架已经有一段时间了。我有一个问题,因为开始后,阅读了许多文件,我想知道为什么所有的例子都没有提到它。

    我尝试用这种方式使用默认值(v 1.09)

    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
    

    以及默认index.php文件:

    // Define path to application directory
    defined('APPLICATION_PATH')
        || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
    
    // Define application environment
    defined('APPLICATION_ENV')
        || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
    
    // Ensure library/ is on include_path
    set_include_path(implode(PATH_SEPARATOR, array(
        realpath(APPLICATION_PATH . '/../library'),
        get_include_path(),
    )));
    
    /** Zend_Application */
    require_once 'Zend/Application.php';
    
    // Create application, bootstrap, and run
    $application = new Zend_Application(
        APPLICATION_ENV,
        APPLICATION_PATH . '/configs/application.ini'
    );
    
    
    $application->bootstrap()
                ->run();
    

    但到目前为止,我还不能使用单一的入口点,我不得不复制索引文件并给它相关控制器的名称。这样,我就可以正常加载页面,而不是出现500个服务器错误。

    谢谢

    我重新配置了服务器,以便通过虚拟主机而不是别名访问zend安装,这似乎是错误的。

    我的化名是:

    Alias /elul/ "c:\wamp\www\elul\trunk\elul\public/" 
    
    <Directory "c:\wamp\www\elul\trunk\elul\public/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
            Order allow,deny
        Allow from all
    </Directory>
    

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot "C:\wamp\www\examen_fle\trunk\examen_fle\public"
        ServerName examen.elul.local
        ErrorLog "logs/your_own-error.log"
        CustomLog "logs/your_own-access.log" common
        <directory "C:\wamp\www\examen_fle\trunk\examen_fle\public">
            Options Indexes FollowSymLinks
            AllowOverride all
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1
        </directory>
    </VirtualHost>
    

    因为它是本地运行的,所以我还必须在C:\ WINDOWS\system32\drivers\etc中编辑文件hosts以在文件中添加examan.elul.local

    127.0.0.1       examen.elul.local
    
    1 回复  |  直到 14 年前
        1
  •  1
  •   madpoet    15 年前

    如果您希望使用别名而不是虚拟主机,则可能需要使用 RewriteBase 或者您可以将基本url预先设置为frontcontroller:

    RewriteBase /elul/
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
    

    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ /elul/index.php [NC,L]
    

    也应该有用。。。不过我用这个:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule !\.(js|ico|gif|jpg|png|css)$ /project_name/index.php