如何在zend框架控制器中包含文件? [英] how to include file in zend framework controller?

查看:30
本文介绍了如何在zend框架控制器中包含文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我是 Zend 框架的新手..

hello I am newbie in zend framework ..

我想知道如何在zend框架控制器中包含文件

I want to know how to includes files in zend framework Controller

我在 zend 框架控制器中使用 action

I am using action in zend framework controller like that

public function anyAction()
{
   require("../mailchimp/anyfile.php");
}

我可以做些什么来包含这些文件,这意味着保存所有这些文件的正确位置

what I can do to include this files, means where is the right place to kept all this files

推荐答案

这是 library 目录的典型用途.您可以将自己的功能以及任何 3rd 方代码放入其中.有些人甚至将 ZF 库放在那里,但我倾向于将 ZF 保留在服务器上的其他位置,并将其添加到 php.ini 中的 include_path.

This is what the library directory is typically used for. You can put your own functions in there as well as any 3rd party code. Some even put the ZF library in there, but I tend to keep ZF elsewhere on the server and add it to the include_path in php.ini.

使用 library 文件夹中的 mailchimp 文件,您可以像这样包含它们:

With the mailchimp files in your library folder, you can include them like this:

require_once APPLICATION_PATH . '/../library/mailchimp/MCAPI.class.php';

如果您将 library 添加到您的路径中,那么您可以将其缩短为:

If you add library to your path, then you could shorten it to just:

require_once 'mailchimp/MCAPI.class.php';

您可以通过将 includePaths.library = APPLICATION_PATH "/../library" 添加到您的 application.ini 文件来将库添加到您的路径中.请注意可能的性能损失可能需要在您的 include_path 中添加其他位置.

You can add library to your path by adding includePaths.library = APPLICATION_PATH "/../library" to your application.ini file. Just be aware of the possible performance penalty you may take by adding additional locations to your include_path.

要显示您存储在 public/images 中的图像,您可以在视图/布局中使用此调用:

To display an image that you have stored in public/images, you would use this call from your view/layout:

<img src="<?php echo $this->baseUrl('images/file.jpg') ?>" alt="file.jpg" />

如果您的 Zend 应用程序不在域的根目录中,这将负责确定您的基本 URL 是什么.请参阅 BaseUrl 视图助手 了解更多信息.

This takes care of figuring out what your base URL is in the event that your Zend Application is not in the root directory of your domain. See the BaseUrl View Helper for more info.

这篇关于如何在zend框架控制器中包含文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆