蛋糕控制台2.2.1:烘焙错误 [英] cake console 2.2.1: Bake errors

查看:251
本文介绍了蛋糕控制台2.2.1:烘焙错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行MAMP的OSX计算机。 CakePHP 2.2.1安装和配置正确(意味着当我浏览到Index.php文件时,我有所有绿色条,我已经完成了博客教程,我正在开发我的第二个应用程序与脚手架正在运行)。



根据菜谱(和其他),我安装了一个新的蛋糕副本到目录(我的用户目录)和然后将路径变量放在我的.bash_profile文件中
export PATH =$ PATH:/ Users / p_scott / cake221 / app / Console
我可以进入终端,输入 cake ,并让控制台上来。你可以看到,到那时,我是从应用程序目录调用控制台。



我第一次尝试运行 cake bake 从终端使用-app参数和指定我的练习应用程序的路径。我第一次做到这一点,我得到了以下

 欢迎来到CakePHP v2.2.1控制台
---------
应用程序:app
路径:/ Applications / MAMP / htdocs / blog / app /
-------------
交互式烘焙外壳
---------------
[D] atabase配置
[M] odel
[V] iew
[C] ontroller
[P] roject
[F] ixture
[T] est case
[Q] uit
烘焙? (D / M / V / C / P / F / T / Q)
> c
--------------------
烘焙控制器
路径:/ Applications / MAMP / htdocs / blog / app / Controller /
--------------------
\Use数据库配置:(默认/测试)
[默认]>

无论我为数据库输入什么(如果我留空, ,但任何答案给我以下错误:

 警告错误:PDO :: __ construct():[2002]或目录(尝试通过unix:///var/mysql/mysql.sock连接)[/Users/p_scott/cake221/lib/Cake/Model/Datasource/Database/Mysql.php,第149行] 

错误:数据库连接SQLSTATE [HY000] [2002]没有这样的文件或目录缺少或无法创建。
#0 /Users/p_scott/cake221/lib/Cake/Model/Datasource/DboSource.php(260):Mysql-> connect()
#1 / Users / p_scott / cake221 / lib / Cake / Model / ConnectionManager.php(101):DboSource-> __ construct(Array)
#2 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ModelTask​​.php(906):ConnectionManager :: getDataSource('default')
#3 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(396):ModelTask​​-> getAllTables('default')
#4 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(419):ControllerTask-> listAll(NULL)
#5 / Users / p_scott / cake221 / lib /Cake/Console/Command/Task/ControllerTask.php(136):ControllerTask-> getName()
#6 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php( 61):ControllerTask-> _interactive()
#7 /Users/p_scott/cake221/lib/Cake/Console/Command/BakeShell.php(113):ControllerTask-> execute()
# 8 /Users/p_scott/cake221/lib/Cake/Console/Shell.php(393):BakeShell-> main()
#9 /Users/p_scott/cake221/lib/Cake/Console/ShellDispatcher.php (201):Shell-> runCommand(NULL,Array)
#10 /Users/p_scott/cake221/lib/Cake/Console/ShellDispatcher.php(69):ShellDispatcher-> dispatch b#11 /Users/p_scott/cake221/app/Console/cake.php(33):ShellDispatcher :: run(Array)
#12 {main}
pre>

一旦我开始得到这个错误,我试着在终端导航到< cake install dir> / app / Console 文件夹和< different instance of cake install dir> / app / Console 文件夹,从我的应用程序中试用控制台。我得到相同的错误,或者它问我不同的问题,如:

 什么是你想要烘烤的项目的路径? 
[/ Users / p_scott / myapp]> / Applications / MAMP / htdocs / history / app
要复制的目录布局的路径是什么?
[/ Applications / MAMP / htdocs / history / lib / Cake / Console / Templates / skel]>

安装了PHP CLI,似乎正在工作

  PHP 5.3.8(cli)(built:Dec 5 2011 21:24:09)
版权所有(c)1997-2011 PHP集团
Zend Engine v2.3.0,版权所有(c)1998-2011 Zend Technologies

我的PDO支持启用。在终端I键入:

  php --ri pdo 
PDO
PDO支持= enabled
PDO drivers => mysql,sqlite,sqlite2



我在Apache中没有php.ini文件在Mac上),但是在PHP 5.36目录中,启用了以下扩展:

  extension = imap.so 
extension = yaz.so
extension = mcrypt.so
extension = gettext.so
extension = pgsql.so
extension = pdo_pgsql.so
extension = pdo_mysql.so

休息一会儿后,我发现了一篇文章
/www.dereuromark.de/2011/10/31/freshly-baked-cake2-0-tips/),谈论2.0控制台位置的变化。我应该尝试从该位置使用它(< cake installed dir> / lib / Cake / Console )。一旦我尝试这个,我得到关于我想要使用的布局的问题,或者... ONCE,我能够让烘烤应用程序要求我创建一个数据库配置。我经历了这些步骤,它在结束时抛出这个错误:



致命错误:在/ Applications / MAMP中找不到类'DATABASE_CONFIG' /htdocs/history/lib/Cake/Console/Command/Task/DbConfigTask.php on line 264



这会让我再多一个的信息。这是我在< cake installation dir> /history/app/Config/database.php 文件中的默认数据库配置。

  class DATABASE_CONFIG {

public $ default = array(
'datasource'=>'Database / Mysql',
'persist'=> false,
'host'=>'localhost',
'login'=>'cakeHistoryUser',
'password'=>'cakeHistoryPassword'
'database'=>'cake_history',
'prefix'=>'',
//'encoding'=>'utf8',
);

在发布此问题(和所有这些信息)之前,我花一些质量时间在这里似乎我的大多数问题是或CLI相关,但我只是不知道我需要改变的东西,小时和小时后,我需要一些帮助。



帮助我是Obi Wan,你是我唯一的希望

解决方案

问题是你正试图通过命令行与数据库交互,然而,PHP-CLI是不同于MAMP证明的安装,所以它不知道数据库服务器。



尝试更改 localhost在 app / Config / database.php 文件中的 127.0.0.1 做诡计。


OSX machine running MAMP. CakePHP 2.2.1 installed and configured properly (meaning that I have all green bars when I browse to the Index.php file, I have completed the Blogs tutorial and am working on my second app with which scaffolding is up and running). Now I am trying to Bake for the first time.

Per the cookbook (and others), I installed a fresh copy of cake into a directory (my users directory) and then put the path variable in my .bash_profile file export PATH="$PATH:/Users/p_scott/cake221/app/Console" after which I was able to go into Terminal, type cake and have the console come up. You can see that up to that point, I was invoking the console from the app directory.

I first tried running cake bake from the terminal using the -app parameter and designating the path to my practice apps. The first time I did this, I got the following

    Welcome to CakePHP v2.2.1 Console
    -------------
    App : app
    Path: /Applications/MAMP/htdocs/blog/app/
    ------------- 
    Interactive Bake Shell
    --------------- 
    [D]atabase Configuration
    [M]odel
    [V]iew
    [C]ontroller
    [P]roject
    [F]ixture
    [T]est case
    [Q]uit
    What would you like to Bake? (D/M/V/C/P/F/T/Q)
    > c
    -------------------- 
    Bake Controller
    Path: /Applications/MAMP/htdocs/blog/app/Controller/
    -------------------- 
    \Use Database Config: (default/test)
    [default] >

No matter what I put in for the database (if I leave it blank, it asks me again), but any answer gives me the following error:

    Warning Error: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in    [/Users/p_scott/cake221/lib/Cake/Model/Datasource/Database/Mysql.php, line 149]

    Error: Database connection "SQLSTATE[HY000] [2002] No such file or directory" is missing, or could not be created.
    #0 /Users/p_scott/cake221/lib/Cake/Model/Datasource/DboSource.php(260): Mysql->connect()
    #1 /Users/p_scott/cake221/lib/Cake/Model/ConnectionManager.php(101): DboSource->__construct(Array)
    #2 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ModelTask.php(906): ConnectionManager::getDataSource('default')
    #3 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(396): ModelTask->getAllTables('default')
    #4 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(419): ControllerTask->listAll(NULL)
    #5 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(136): ControllerTask->getName()
    #6 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(61): ControllerTask->_interactive()
    #7 /Users/p_scott/cake221/lib/Cake/Console/Command/BakeShell.php(113): ControllerTask->execute()
    #8 /Users/p_scott/cake221/lib/Cake/Console/Shell.php(393): BakeShell->main()
    #9 /Users/p_scott/cake221/lib/Cake/Console/ShellDispatcher.php(201): Shell->runCommand(NULL, Array)
    #10 /Users/p_scott/cake221/lib/Cake/Console/ShellDispatcher.php(69): ShellDispatcher->dispatch()
    #11 /Users/p_scott/cake221/app/Console/cake.php(33): ShellDispatcher::run(Array)
    #12 {main}

Once I started getting this error, I tried navigating in terminal to the <cake install dir>/app/Console folder and the <different instance of cake install dir>/app/Console folder to try the console from within my app/s. I either get the same errors or it asks me different questions, like:

    What is the path to the project you want to bake?  
    [/Users/p_scott/myapp] > /Applications/MAMP/htdocs/history/app 
    What is the path to the directory layout you wish to copy?  
    [/Applications/MAMP/htdocs/history/lib/Cake/Console/Templates/skel] > 

PHP CLI is installed and it appears to be working

    PHP 5.3.8 (cli) (built: Dec  5 2011 21:24:09) 
    Copyright (c) 1997-2011 The PHP Group
     Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

My PDO support appears to be enabled. In terminal I typed:

    php --ri pdo
    PDO
    PDO support => enabled
    PDO drivers => mysql, sqlite, sqlite2

I don't have a php.ini file in Apache (because I am on a Mac), but the one in the PHP 5.36 directory, I have the following extensions enabled:

    extension=imap.so
    extension=yaz.so
    extension=mcrypt.so
    extension=gettext.so
    extension=pgsql.so
    extension=pdo_pgsql.so
    extension=pdo_mysql.so

After taking a break, I found an article (http://www.dereuromark.de/2011/10/31/freshly-baked-cake2-0-tips/) that talks about a change of console location in 2.0. I should try using it from that location (<cake installed dir>/lib/Cake/Console ). Once I tried this, I either got the questions about what layout I wanted to use or... ONCE, I was able to get the bake application to ask me to create a database configuration. I went through the steps and it pooped out this error at the end:

Fatal error: Class 'DATABASE_CONFIG' not found in /Applications/MAMP/htdocs/history/lib/Cake/Console/Command/Task/DbConfigTask.php on line 264

Which leads me to one more piece of info. This is my default DB configuration in the <cake installation dir>/history/app/Config/database.php file.

    class DATABASE_CONFIG {

public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'cakeHistoryUser',
    'password' => 'cakeHistoryPassword',
    'database' => 'cake_history',
    'prefix' => '',
    //'encoding' => 'utf8',
   );

Before posting this question (and all of this information), I spend some quality time out here and it seems like most of my issues are or CLI related but I just don't see where I need to change something and hours and hours later, I need some help.

Help me Obi Wan, you are my only hope

解决方案

The problem is you are trying to interact with the database via the command line, however the PHP-CLI is a different install than the one proveided by MAMP so it doesn't know about the database server.

Try changing localhost to 127.0.0.1 in your app/Config/database.php file and that should do the trick.

这篇关于蛋糕控制台2.2.1:烘焙错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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