MVC PHP应用程序的结构

我目前正在使用MVC技术开发一个php应用程序。 我在没有考虑有用的目录结构的情况下启动它。

我打算现在将应用程序部署到apache2服务器。 这就是它现在的样子。

</ p>

我在服务器上有一个httpdocs文件夹,可以从网上访问。 如果我将所有文件复制到此目录中,则可能无法访问某些文件。 public </ code>文件夹包含必须可访问的文件。 (我可能需要将index.php放在那里)</ p>

我的问题是:这种应用程序的首选布局是什么? 我应该将除 public </ code>之外的所有文件夹放在 httpdocs </ code>的父文件夹中吗?</ p>

感谢您的建议!</ p>
</ DIV>

展开原文

原文

I am currently developing a php application using MVC techniques. I started it without thinking about a useful directory structure.
I'm planning to deploy the application to a apache2 server now. This is how it looks right now.
My current layout

I have a httpdocs folder on the server which is accessible from the web. If I copy all files into this directory some files might be accessible that shouldn't. The public folder contains the files that have to be accessible. (I might need to put my index.php there)

My question is: What is the preferred layout for such an application? Should I put all folders except public in the parent folder of httpdocs?

Thanks for your advices!

3个回答



http://httpd.apache.org/docs/2.1/vhosts/examples.html </ p>

你可以看看那里。 设置虚拟主机总是很好,所以你不要混合你的应用程序。 您只需授予对公共文件夹的访问权限。</ p>

 &lt; VirtualHost *:80&gt; 
DocumentRoot / var / www / mvc_app / public
ServerName www.example.com

&lt;目录/ var / www / mvc_app / public&gt;
选项索引FollowSymLinks MultiViews
AllowOverride无
订单允许,拒绝
允许所有
&lt; /目录&gt;

&lt; / VirtualHost&gt;
</ code> </ pre>
</ div>

展开原文

原文

http://httpd.apache.org/docs/2.1/vhosts/examples.html

You can have a look there. Setting up a virtual host is always nice so you don't mix your application. And you just give access to your public folder.

<VirtualHost *:80>
DocumentRoot /var/www/mvc_app/public
ServerName www.example.com

<Directory /var/www/mvc_app/public>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

</VirtualHost>



最简单的解决方案与CakePHP的工作类似,并在中包含 index.php </ code> > public </ code>目录,然后只有 .htaccess </ code>文件,将所有请求映射到 index.php </ code>文件。</ p>

因此,在您的根目录中,您将具有以下内容:</ p>

  RewriteEngine on 
RewriteRule ^(。+)/ public / index.php / $ 1 [L,NC]
< / code> </ pre>

然后类似地在 public </ code>目录中:</ p>

  RewriteEngine on 
RewriteRule ^(。 +)index.php / $ 1 [L,NC]
</ code> </ pre>

您的PHP脚本仍可以正常访问其他脚本,因为它们可以处理文件 系统,而不是说,HTTP。</ p>
</ div>

展开原文

原文

The simplest solution would be similar to what CakePHP does, and have your index.php in your public directory and then just have .htaccess files that map all requests to that index.php file.

So in your root directory you would have something like:

RewriteEngine on
RewriteRule ^(.+) /public/index.php/$1 [L,NC]

And then similarly in your public directory:

RewriteEngine on
RewriteRule ^(.+) index.php/$1 [L,NC]

Your PHP scripts would then still be able to access other scripts as normal, as they work on the file system and not via say, HTTP.



将公共目录用作httpdocs。 Web根目录指向公共,如下所示:</ p>

 &lt; VirtualHost *:80&gt; 
DocumentRoot / path / to / public
ServerName www.domain.com
... \ \ n&lt; / VirtualHost&gt;
</ code> </ pre>

如果您无法访问apache配置,则可以使用“httpdocs”作为公共目录。 您将所有内容从public移动到httpdocs,并将应用程序的其余部分保留在httpdocs之外。 只要知道资产的路径(“mydomain.com/javascripts/foo.js”),公共目录的名称就不重要了。</ p>
</ div>

展开原文

原文

Use the public directory as httpdocs. Web root points to public like this:

<VirtualHost *:80>
DocumentRoot /path/to/public
ServerName www.domain.com
...
</VirtualHost>

If you don't have access to the apache configuration you could just use "httpdocs" as the public directory. You move everything from public to httpdocs and keep the rest of the application outside httpdocs. The name of the public directory should not matter as long you know the path to assets ("mydomain.com/javascripts/foo.js") .

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐