CakePHP 多个应用程序的共享核心

CakePHP Shared core for multiple apps(CakePHP 多个应用程序的共享核心)
本文介绍了CakePHP 多个应用程序的共享核心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在我的本地设置中,我有很多不同的 CakePHP 网站.我使用的是 Mac,因此文件夹结构类似于 ~/Users/cameron/Sites/sample-website,然后在每个网站中,我将拥有典型的 Cake 文件夹和 App 文件夹.

On my local setup I have a load of different CakePHP websites. I'm using a Mac so the folder structure is something like ~/Users/cameron/Sites/sample-website and then within each of these websites I will have the typical Cake folder and App folder.

我想做的是只有一个核心蛋糕文件夹,然后让所有网站都从那个蛋糕核心中提取出来,这样我就不会多次使用相同的东西.我一直在网上阅读一些教程:http://rickguyer.com/cakephp-一核多应用/

What I would like to do is have just a core cake folder and then have ALL the sites pull from that one cake core so I don't have the same stuff several times over. I have been reading some tutorials on the web: http://rickguyer.com/cakephp-one-core-many-apps/

所以我的蛋糕文件夹在这里:~/Users/cameron/Sites/cake-1.3/ 然后我的网站在这里:~/Users/cameron/Sites/sample-site/ 在这个文件夹中,我有常用的 app 文件夹和 htaccess 来告诉它在哪里可以找到 webroot 等.

So I have my cake folder here: ~/Users/cameron/Sites/cake-1.3/ and then my site here: ~/Users/cameron/Sites/sample-site/ and in this folder I have the usual app folder and htaccess to tell it where to find webroot etc.

现在我像教程一样编辑了 webroot 中的 index.php 文件,但只更改了一行,因为我没有像他那样将我的文件移到 App 文件夹之外.所以我唯一改变的像如下:

Now I have edited the index.php file inside webroot like the tutorial BUT have only changed one line because I haven't moved my files OUTSIDE of the App folder like he does. So the only like I have changed is as follows:

if (!defined('CAKE_CORE_INCLUDE_PATH'))
{
    define('CAKE_CORE_INCLUDE_PATH', '..'.DS.'..'.DS.'cake-1.3');
}

据我所知,正确查找两个目录并找到一个名为 cake-1.3 的文件夹,但它只是给出了错误 500?

As far as I can tell that is correctly looking two directories up and finding a folder called cake-1.3 however it just gives a error 500?

任何想法是什么问题?谢谢

Any ideas what the problem is? Thanks

即使这样做也不起作用???如果我回显:echo CAKE_CORE_INCLUDE_PATH; 给出 /Users/cameron/Sites/cake-1.3 并且如果我将其粘贴到地址栏中,它会加载蛋糕文件夹,因此它是绝对是正确的文件夹结构,只是它不喜欢在主 url 之外查看蛋糕?

Even doing this doesn't work??? Which If I echo: echo CAKE_CORE_INCLUDE_PATH; gives /Users/cameron/Sites/cake-1.3 and if I paste that in the address bar it loads up the cake folder so it's definitely the correct folder structure JUST it doesn't like looking at cake outside of the main url?

if (!defined('CAKE_CORE_INCLUDE_PATH'))
{
    define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3'); echo CAKE_CORE_INCLUDE_PATH;
}

推荐答案

你是对的:

define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3');

只需确保用户位于 root 中.换句话说,当您进入终端时,您可以通过键入以下内容进入该目录:cd/Users/cameron/Sites/cake-1.3

Just make sure that Users sits in root. In other words, when you go to terminal you can get to this directory by typing: cd /Users/cameron/Sites/cake-1.3

看起来您可能使用的是 MAC.如果是这样,您的链接是正确的.大多数情况下,我发现您已经完成了应用程序目录的复制粘贴,但它没有获得 .htaccess 文件.我会先检查那些.但这里有一份您应该验证的综合清单:

It looks like you may be on a MAC. If so, your linking is correct. Most of the time what I find is you have done a copy paste of the app directory and it does not get the .htaccess files. I would check those first. But here is a comprehensive list of what you should verify:

  1. 确保主机指向正确的目录(/Users/cameron/Sites/sample-site/)
  2. 验证 mod_rewrite 是否真的开启.
  3. 确认您已复制.htaccess在两个文件中/Users/cameron/Sites/sample-site//Users/cameron/Sites/sample-site/webroot目录.
  4. 确认/Users/cameron/Sites/cake-1.3/目录有一个名为的目录蛋糕在里面,里面有核心.
  1. Make sure the host is pointing to the correct directory (/Users/cameron/Sites/sample-site/)
  2. Verify mod_rewrite is in fact on.
  3. Verify you have copied the .htaccess file in both the /Users/cameron/Sites/sample-site/ and the /Users/cameron/Sites/sample-site/webroot directories.
  4. Confirm that the /Users/cameron/Sites/cake-1.3/ directory has a directory called cake in it that contains the core.

一旦这一切都得到确认,你就会像金子一样出色!

Once all of this is confirmed, you will be good as gold!

快乐编码!

更新:当 index.php 文件查找 cake core 时,它会在您指向的位置中查找另一个名为 cake 的目录.所以在你的情况下:

UPDATE: When the index.php file looks for the cake core, it will look for a directory inside the location you are pointing to for another directory called cake. So in your case:

define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3');

您必须在 /Users/cameron/Sites/cake-1.3 中拥有 cake 目录.您的目录结构将如下所示:

You must have the cake directory inside /Users/cameron/Sites/cake-1.3. Your directory structure will look like:

/Users/cameron/Sites/cake-1.3/cake
/Users/cameron/Sites/cake-1.3/cake/libs
/Users/cameron/Sites/cake-1.3/cake/config
/Users/cameron/Sites/cake-1.3/cake/console
etc.

CakePHP 3.0+在 CakePHP 3.0+ 中,这个配置从 webroot/index.php 移到 App/Config/paths.php

CakePHP 3.0+ In CakePHP 3.0+ this configuration is moved out of webroot/index.php to App/Config/paths.php

这篇关于CakePHP 多个应用程序的共享核心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Codeigniter htaccess to remove index.php and www(Codeigniter htaccess 删除 index.php 和 www)
htaccess mod_rewrite part of url to GET variable(htaccess mod_rewrite url 的一部分到 GET 变量)
Replacing a querystring parameter value using mod_rewrite(使用 mod_rewrite 替换查询字符串参数值)
.htaccess in subdirectory #39;overriding#39; parent htaccess(子目录“覆盖父 htaccess 中的 .htaccess)
How to rewrite SEO friendly url#39;s like stackoverflow(如何像stackoverflow一样重写SEO友好的url)
Is it okay to have a very long .htaccess file?(有一个很长的 .htaccess 文件可以吗?)