本文介绍了Cakephp从1.3升级到2.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 更新:我问的问题不完全涵盖我在做这个升级有多深!如果你绊倒这个,我希望我的推送的答案对你有用 所以,为了努力让论坛插件工作,我决定将cakephp从1.3升级到2.1 (这是因为论坛插件使用的是CakeDC utils,它们已经达到了cakephp 2.0,的论坛不清楚哪个工具使用它...) 好吧,所以我已经运行了蛋糕升级魔术的东西,根据这里找到的说明: http://book.cakephp.org/2.0/en/console-and-shells/upgrade-shell.html#upgrade-shell 并且我运行升级程序,它说它做了一堆东西,它看起来像做了一堆的东西。 现在当我访问我的网站,它是下降 - 没有任何反应。 apache中的错误日志为:文件不存在的原因是它已更改到升级中的大写CConfig。我缺少什么?解决方案 mensch给出的答案不是我需要的 - 我从来没有碰过index.php文件 - 所以我会详细说明我在这里尝试。 我使用这个网站作为指南,但与我自己的评论太! http://www.paulmarshall.us/blog/migrating- from-cakephp-13-to-cakephp-20 (我也发现这个:https://github.com/dereuromark/upgrade 如果上面的教程失败我可能会有一个镜头我不太热衷于它,虽然,我喜欢超详尽的文档,不 在您的应用程序引导程序中插入`CakePlugin :: loadAll();`以确保此插件已加载 这对我来说是没有意义的...你可以指定文件夹的文件夹吗? line?etc ...我会尝试,并且特别关于我做了什么!) 首先,我注意到index.php,我的蛋糕使用不是与cake2.1代码一起来的index.php。不确定为什么是这种情况,但我复制了新2.1 index.php(是的,这是应用程序/ webroot / index.php文件),现在我有一个新的错误:(其中cake_install是我的蛋糕应用程序所在的文件夹) 现在正在处理... 现在我看到升级工具没有升级core.php文件 - 在app / Config(对于2.1,app / config为1.3) - 升级工具是什么真的吗?我已经剪切和粘贴2.1版本(即,从2.1代码的zip文件,我把/app/Config/core.php,并将其移动到我的/ app / Config目录),并确保盐和安全值被交换。就是这样。 仍然没有运气。所以现在我升级了database.php文件(也在app / Config或app / config)〜我改变了 'driver'=> 'mysqli', 到 'datasource'=> 'Database / Mysqli', 随机配置文件很有趣! 啊,好吧,所以升级到核心和数据库改变错误消息...这是好吗?仍然不确定他们多么vaunted升级脚本做了...它只是改变了文件名? 所以我777的/ cake_install / app / tmp / logs /文件夹(chmod 777 -R文件夹)和 ...猜猜我从来没有升级密码种子。好吧,组成一个新的数字! (密码种子做什么,你问嗯,好吧,bing没有多大帮助 - 我读的代码。似乎用于加密/解密从cookie?好,我可以生活的) Bootstrap.php 我将zip文件中的引导程序移动到我的版本(感谢一点,升级脚本!没有进行任何更改,我想我将需要加载插件虽然...我确信,有很多文档,尽管(hah!) 当然,那些。。的蛋糕升级器无法做另一次升级。检查此页: http://book.cakephp.org /2.0/en/appendices/2-1-migration-guide.html 好的,现在我必须创建文件 - 就像他们在该页面。唯一的窍门是,是的,它是在应用程序文件夹,没有,我的应用程序/ View文件夹,蛋糕制作没有一个帮助器子文件夹...所以对于AppHelper.php我不得不做一个帮手子文件夹在/ app / View /. ... HEY!现在我得到一个背景和一个标志...和这些:很好。某种酷的新蛋糕2功能,这意味着我不能使用$ html?这似乎......奇怪的适当,真的。 令人难以置信。现在我需要改变如何$ this->数据工作?为什么??为什么??为什么这个暴徒不知道apis倾向于是固定合同,而不是浮动的想法...。没关系,最常用的蛋糕行我现在...错了。 这是我运行的: find。我从scala或django开发, -type f -exec sed -i / $ this-> data / $ this-> request-> data / g'{} \; 到/ app目录这样做。这2.1 ...它更好地认真真棒...每个人都需要做的工作量,以获得它。这是我假设,一个正常的日子与低级语言工作。 很奇怪,$ html问题是由于某人不喜欢小写引起的?人们只能想到: 未定义var when在CakePHP 2.0中使用Html Helper 解决方法是:(感谢SO中的另一篇文章)自然与$ session - 找到相同的问题。 -type f -exec sed -i / $ session / $ this-> Session / g'{} \; ... 事情就来了!现在我有不可修改的错误:哦,对于...的爱,所以我需要移动的PagesController在这里找到: lib / Cake / /skel/Controller/PagesController.php 并放在这里 app / Controller / 现在我有了 $ b $ b 找不到帮助程序类JavascriptHelper。 这不是太糟糕了 - 你不会找到任何引用JavascriptHelper ,但是你会在$ helpers数组中找到对Javascript的引用。后端在词Helper中添加了额外的混淆。无论如何,我通过我的PHP文件搜索任何$ helpers数组,并找到一个,在AppController(2.1)类。 我不喜欢也不明白helpers - javascript的,反正 - 所以我从来没有使用过他们。我必须盲目地跟着一个教程在某一点,并添加它在...但我不需要它,所以它就来了! 现在我需要清理所有的ctp文件,我有,我使用要求,以确保使用正确的html。再次,我将使用find命令从上面为此(将其指向视图而不是视图文件夹)叹了。好吧,不,这不是那么简单,是吗?我之前的位置: require(app / View / Pages / man_front.html) : require(/cake_folder/app/View/Pages/man_front.html) 文件夹是我所有的蛋糕的东西是不确定为什么这是,但一个简单的发现固定它: find。-type f -exec sed -i / app\ / View\ / Pages / \ / cake_folder\ / app\ / View\ / Pages / g'{} \; (\会depowera /) 已经做了所有的事情,并让你的网站达到某种可接受的水平,接下来,你可能现在找到一些数据库问题:当然,没有更多的mysqli支持。编辑database.php使用mysql(即我刚刚删除了结尾i) (什么是peeps在cakephp ??? API是什么意思是不要改变一切,如果它会破坏现有的代码,永远不是改变!OBAMAAAAA!〜下一次升级,我会推我所有的代码django或春天或scala,红润的废话。) 下一个问题是我使用的组件 - 我得到一个蛋糕错误说: <?php CakePlugin :: load('Uploader'); CakePlugin :: loadAll (); 所以...不仅是所有的代码都被淘汰了,尼斯。 解决方案是创建一个app / Plugin文件夹(是的,神奇的升级程序不会这样做),然后看看你的插件。现在!这与您的组件不同!我不知道怎么回事 - 查看我的问题可能的答案:组件和插件在cakephp 2.1? - 但现在,我们只是看着PLUGIN文件夹,和插件一般。看起来像在蛋糕1.3,插件列出像这样:这是一个点符号。我可以住在那里。在我的情况下,我需要获取最新版本的Uploader插件(幸运的是,升级为2.x兼容!),并将其放在app / Plugin文件夹 所以我得到: app 插件上传者配置 Locale <其他文件也在这里!> 现在似乎有效了,hooray! 下一个错误是:这很清楚。我很高兴我知道错误是在我的代码。好的错误消息! 现在我看到,愚弄我,认为如果第一个数组为空,Set :: Sort实用程序将继续工作!真的,cakephp人站立,不是在巨人的肩膀上,而是在他们的额头上。 看来,新的2.1升级已经取消了这种破旧的做法,所以现在我需要检查之前任何设置:排序调用,以避免如果有问题的数组空或null。精细。足够简单,但... geeze。 我只是投入了 if $ theArray)){ Set :: sort($ theArray,...); } 现在我得到FormHelper错误 - 它看起来像$ form在视图中现在变为$ this-> Form,所以我有另一个快速脚本替换这: p> 现在我得到的下一个错误是:现在他们已经搞错了FormHelper中的select方法 - 我有这个:我现在有:现在我的一个组件 - 实际上,You_tube_loader_component - 被打破了。我需要修改它,使标题读为: class YouTubeLoaderComponent extends Component { function __construct(ComponentCollection $ collection ,$ settings = array()){ parent :: __ construct($ collection,$ settings); ... } } 默认的uname和密码的valeus - 现在我把它们在...部分,而不是搞砸与神秘的设置数组! is: Soooo这是一个问题,不是在蛋糕1.3中,而是在2.1 问题是在控制器操作被引用,有一个没有类型参数的find调用。也就是说,我有其中我应该有: $ results = $ this-> User-> find('first',array('conditions'=> array(User.id=> ;($ this-> Auth-> user(id))),'fields'=> array(User.confirmed)));另一个问题是,无论什么原因,检查: $ b 这对我很好。 下一个问题是,thios-> auth-> user('id')将在登录用户后不返回任何内容。幸运的是,我遇到了这个职位,这使事情更清楚: 那么,你要做什么?以上链接建议获取所有用户详细信息,然后将其发送到auth登录部分。我不是特别喜欢这个(因为这是一个愚蠢的问题,我不能相信任何这么不起眼的需要),但它是我必须做的。欢迎提出建议! 因此,不要太混乱: if($ this-> Auth-> login($ this-> request-> data)){ ... // argh! 1 我现在有: $ user = $ this-> User-> find('first',array('conditions'=> array ('User.email'=> $ this-> request-> data ['User'] ['email']))); //使用AuthComponent〜Rs登录操作 if($ this-> Auth-> login($ user ['User'])){ ... // omg该条目在数据库中的额外检查只是辉煌和高效 不是这样的更整洁,更少混乱?好的工作,cakephp mavericks! 下一个错误是The reason that file doesn't exist is that it was changed to a capital "C" Config in the upgrade. What am i missing? 解决方案 The given answer by mensch isn't quite what I need - I never touched the index.php file - so i will detail what I am trying here.I am using this site as a guide, but with my own commentary too!http://www.paulmarshall.us/blog/migrating-from-cakephp-13-to-cakephp-20(i also found this: https://github.com/dereuromark/upgrade which i might have a shot at if the above tutorial fails. I'm not too keen on it though, I like super-exhaustive documents, not Put `CakePlugin::loadAll();` in your app bootstrap to make sure this plugin is loadedwhich to me is meaningless... can you specify the folder of the file? Any particular spot in the file to add the line? etc... i'll try and be particular about what i did!)First up, i've noticed that the index.php that my cake was using was not the index.php that came with the cake2.1 code. Unsure why that is the case, but I copied the "new" 2.1 index.php across (yes, this is the app/webroot/index.php file) and now i have a new error:(where cake_install is the folder where my cake app sits)Working on this now...AND now i see that the upgrade tool didn't upgrade the core.php file - found in app/Config (for 2.1, app/config for 1.3)... what did the upgrade tool really do? I've cut and paste the 2.1 version in (that is, from the zip file of the 2.1 code, i took that /app/Config/core.php and moved it into my /app/Config directory), and made sure the salt and security values were swapped across. That's it.Still no luck. So now i have upgraded the database.php file (also in app/Config, or app/config) ~ I changed the 'driver' => 'mysqli',to'datasource' => 'Database/Mysqli',Configuring files randomly is fun!Ah, ok, so the upgrade to core and database changed the error message... that's good? Still unsure what their much vaunted "upgrade" script did... it just changed file names? Really?Ok, so i 777 the /cake_install/app/tmp/logs/ folder (chmod 777 -R folderHere) and...guess i never upgraded the cipher seed. Ok, made up a new number! (What does the cipher seed do, you ask? Um, well, bing wasn't much help - i read the code. Seems to be used for encrypting/decrypting from cookies? Ok, i can live with that)Bootstrap.phpI moved the bootstrap in the zip file to my version (thanks for little, upgrade script!). Haven't made any changes yet, I think i will need to to load plugins though... i'm sure that is well documented though (hah!)So that leaves me with this errror:And of course, the much vaunted cake upgrader has failed to do another upgrade. Check this page out:http://book.cakephp.org/2.0/en/appendices/2-1-migration-guide.htmlOk, so now I have to make the files - just as they are in that page. The only trick was that, yes, it is in the app folder, and no, my app/View folder that cakePhp made didn't have a "Helper" subfolder... so for the AppHelper.php i had to make a Helper subfolder under /app/View/....HEY! Now i get a background and a logo... and these:Great. Some sort of cool new cake 2 feature that means that i cannot use $html? That seems... oddly appropriate, really.Unbelievable. Now I need to change how $this->data works??? WHY?? WHY?? Why can't this mob work out that apis tend to be fixed contracts, not floating ideas... argh. That's ok, the most used cake line i have is now... wrong. I'm developing in scala or django from now on, junior languages suck.Here is what i ran: find . -type f -exec sed -i 's/$this->data/$this->request->data/g' {} \;I went to the /app directory to do so. This 2.1... it better be seriously awesome... the amount of work everyone has to do to get it up. Is this, i assume, a normal day working with the junior languages?Ah fantastic, the $html problem is caused because somebody didn't like lowercase? One can only wonder:Undefined var when using Html Helper in CakePHP 2.0And the solution is: (thanks to another post in SO) And naturally the same problem with $session -find . -type f -exec sed -i 's/$session/$this->Session/g' {} \;...Things are coming along! Now I have the inscrutible error:Oh for the love of... so i need to move the PagesController found here:lib/Cake/Console/Templates/skel/Controller/PagesController.phpand put it hereapp/Controller/again, the Cake installer/upgrader seems to be asleep on the job.And now I haveHelper class JavascriptHelper could not be found.This isn't too bad - you won't find any references to "JavascriptHelper", but you will find references to "Javascript" in your "$helpers" array. The back-end adds in the word Helper for extra obfuscation. Anyway, i searched through my php files for any $helpers arrays, and found one, in the AppController(2.1) class.I don't like nor understand helpers - javascript ones, anyway - so I never used them. I must have followed a tutorial blindly at some point and added it in... but i don't need it, so out it goes!And now i need to clean up all the ctp files i had, where i used a "require" to ensure that the right html was used. Once more i will use the find command from above for this (to point them to the "View" and not "views" folder)Sigh. Ok, no, it isn't that simple, is it? Where before I had :require(app/View/Pages/man_front.html)i now need:require(/cake_folder/app/View/Pages/man_front.html)(where the cake folder is where all my cake stuff is. Unsure why this is, but a simple find fixed it:find . -type f -exec sed -i 's/app\/View\/Pages/\/cake_folder\/app\/View\/Pages/g' {} \;(the \ will "depower" a /)Ok, so having done all that and gotten your site to some sort of acceptable level, what next? Well, you might now find some db issues: Of course, no more mysqli support. Edited the database.php to use mysql instead (ie i just removed the ending "i")(what is wrong with the peeps in cakephp??? API means "don't change everything if it will break existing code, ever." not "change! OBAMAAAAA!" ~ next upgrade, i'll push all my code to django or spring or scala. Ruddy nonsense.)The next issue is the "Components" that i am using - i get a cake error saying:<?phpCakePlugin::load('Uploader');CakePlugin::loadAll();So... not only is all my code busted, but all the old plugins too? Nice.The solution is to create an app/Plugin folder (yes, the magic upgrader doesn't do that, either) and then look at the plugins you had. Now! This is different from your components! I don't know how just yet - check out my question for a possible answer : Difference between a "component" and a "plugin" in cakephp 2.1? - but right now, we are just looking at the "PLUGIN" folder, and plugins in general. Looks like, in cake 1.3, the plugins were listed like this:that is, with a dot notation. I can live with that. In my case, I needed to get the latest version of the Uploader plugin (that, thankfully, was upgraded to be 2.x compatible!) and put it in the app/Plugin folderso i got:app Plugin Uploader Config Locale <the other files here too!>That seems to work right now, hooray!The next error was:Ah, ok then. That is clear. I am glad I know what the error is in my code. Good error messaging!Now I see, foolish me, to think that the utility Set::Sort would continue to work if the first array was empty! Truly, the cakephp people are standing, not on the shoulders of giants, but on their very foreheads.It would seem that the new 2.1 upgrade does away with this shabby practice, so now i need a check before any Set:Sort calls to avoid if the array in question is empty or null. Fine. Easy enough, but... geeze.I just threw in aif (!empty($theArray)){ Set::sort($theArray,...);}and that fixed that.Now I am getting FormHelper errors - it looks like $form in the view now becomes $this->Form, so i have another quick script to replace this:And now the next error I get is:And now they've done gone messed up the "select" method in the FormHelper - so before, where I had this:i now have this:And now one of my components - actually, the You_tube_loader_component - was broken. I need to modify it so that the header reads:class YouTubeLoaderComponent extends Component { function __construct(ComponentCollection $collection, $settings = array()) { parent::__construct($collection, $settings); ... }}Previously i had just defaulted the valeus of the uname and password - now i stick them in the "..." section instead of messing around with the mysterious "settings" array!Next up is:Soooo this is a problem that isn't picked up in cake 1.3, but is in 2.1The issue is that in the controller action being referenced, there is a "find" call without a type paramter. That is, I hadwhere i should have had:$results = $this->User->find('first',array( 'conditions' => array("User.id" => ($this->Auth->user("id"))), 'fields' => array("User.confirmed")));Another issue I had was that, for whatever reason, the check:did not work. Apparently (although am unsure how/why), cakePHP auth in 2.x will no longer store all the user's details to the session. I don't know which details it stores to the session, or how to modify them - looking into that! - but my code wasn't saving the "id" value, so the check above always set the loggedIn value to false.To remedy, I modified the call to read: which worked fine for me.Next problem is that the thios->auth->user('id') will return me sweet nothing after logging in a user. Fortunately I came across this post, that made things clearer:Amazingly, the geniuses at cake labs thought that changing the very way that logging in worked would help clear up some confusion. To be honest, the only thing I'm confused about is who was so confused about the fact that the auth component had all the user's details available after logging in. But fear not, they've cleared the confusion up and... removed the feature entirely.So, what are you to do? The link above suggests getting all the user details, then shipping that into the auth login section. I don't particularly like this (because it is a stupid problem and i cannot believe anything so inelegant is needed), but it is what I have to do. Suggestions welcome!So instead of the oh-so-confusing:if ($this->Auth->login($this->request->data)) { ... //argh! I am so confused by that line above!!!1i now have:$user = $this->User->find('first', array( 'conditions' => array('User.email' => $this->request->data['User']['email']) ));// Use the AuthComponent~Rs login actionif ($this->Auth->login($user['User'])) { ... //omg the extra check that the entry is in the db is just brilliant and efficientisn't that just so much neater and less confusing? Good job, cakephp mavericks!The next error is Which is a bit vague...Ah! Answered already on stack overflow here:Authorization adapter was not found in cakePHPAnd that was it! There might be other issues - god speed on them - but i didn't come across them, so i cannot help you any more. 这篇关于Cakephp从1.3升级到2.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-21 14:12