cakephp - 为什么在我将调试切换到 3 之前不会发生一些变化? [英] cakephp - why do some changes NOT happen until I switch debugging to 3?

查看:17
本文介绍了cakephp - 为什么在我将调试切换到 3 之前不会发生一些变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时我会在本地实施更改并且它们工作正常,我将它们复制到我的远程网络服务器并且更改被忽略.(代码相同.)

Sometime I will implement changes locally and they work fine, I copy them to my remote webserver and the changed are ignored. (The code is identical.)

我进入core.php,把debugging改成3,再检查一下……成功了!

I go into core.php, change debugging to 3, check again... it works!

我感觉这与缓存有关,但我不知道究竟要更改什么.

I have a feeling it's something to do with cache but I don't know what exactly to change.

推荐答案

CakePHP 在 /app/tmp/cache 中有一个缓存.目录结构如下:

CakePHP has a cache located in /app/tmp/cache. The directory structure looks like this:

# /app/tmp/cache
# /app/tmp/cache/models
# /app/tmp/cache/persistent
# /app/tmp/cache/views

通常遇到的主要问题是模型缓存.当调试关闭(即在生产中)并且您使 CakePHP 分派时,它会检查所有数据库表的模式并将它们存储在上述 models 文件夹中的平面文件中.如果您不删除此文件夹中的文件,CakePHP 会开始说模型/表/字段在您的数据库中明确存在时不存在.

The main issue usually experienced is with the model cache. When debug is off (ie. in production) and you cause CakePHP to dispatch, it introspects the schema of all your database tables and stores these in flat files in the models folder above. If you do not delete the files in this folder, CakePHP will start to say models/tables/fields don't exist when they clearly do in your database.

如果您在应用程序中启用视图缓存,当第一次渲染视图时,CakePHP 会将平面文件编译到 views 文件夹,以防止在下一次请求时再次渲染这些视图.

If you enable view caching in your application, when views are rendered for the first time CakePHP will compile flat files to the views folder to prevent having to render these views again on the next request.

在 CakePHP 的引导过程中,它必须先确定您在安装中使用的目录结构,然后才能访问重要文件(例​​如 database.php).因此,CakePHP 将生成缓存文件到 persistent 目录,其中包含每个重要目录和文件的绝对路径,您正在使用的任何插件,甚至您创建的任何本地化,以便它可以快速翻译您的无需重新解析 .pot 文件即可在语言之间应用.

During CakePHP's bootstrap process it has to determine the directory structure you are using in your installation before it can access important files (like database.php). As such, CakePHP will generate cache files to the persistent directory with the absolute paths to each and every important directory and file, any plugins you are using and even any localisations you have created so it can quickly translate your application between languages without reparsing .pot files.

所以,简单地说,每当您对生产中的应用程序进行代码更改时,您必须记住删除这些目录中的所有文件,或者将其添加为部署机制.但是,您不得删除任何目录.

So, simply put, you have to remember to delete all of the files in these directories whenever you make code changes to an application that is in production, or add this as part of your deployment mechanism. You must not delete any of the directories however.

将 debug 更改为 3 的原因对您有用是因为当调试模式打开时(在任何大于零的值)缓存被清除并在每次请求时重新生成,但是 - 虽然这有效 - 自动化并不容易.

The reason changing debug to 3 works for you is because when debug mode is turned on (at any value greater zero) the cache is cleared and regenerated on every request, but - while this works - it is not easy to automate.

有很多方法可以以编程方式执行此操作 - 包括 shell 命令CakePHP 插件Capistrano 配置、Ant 文件 - 但也可以手动进行.

There are a number of ways to do this programmatically - including shell commands, CakePHP plugins, Capistrano configs, Ant files - but one can also just do so manually.

这篇关于cakephp - 为什么在我将调试切换到 3 之前不会发生一些变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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