CakePHP 2.1 How to generate code for a single view? - cakephp

I found that the explanations in
the cookbook do not match my own experiences with the bake shell.
When I run ./cake bake from the shell, I don't get the output as specified above, instead it asks me for an app path and a skeleton path, and then wants to bake a whole application.
I have written most of my code and would like to just bake a single view, i.e. a form for this view. I would like to have the interactive shell like I knew it from 1.3 but I might be doing something wrong.
Like this:
---------------------------------------------------------------
App : app
Path: /path-to/project/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)
>
Edit:
Here is the output when I just run ./cake
Current Paths:
-app: Console
-working: /home/username/Aptana Studio 3 Workspace/aurinko/aurinko/app/Console
-root: /home/username/Aptana Studio 3 Workspace/aurinko/aurinko/app
-core: /home/username/Aptana Studio 3 Workspace/aurinko/aurinko/lib
My working app lies in the path specified as root. What do I need to set app to, in order to just generate single views?

I think I did not try enough. With this command it worked:
./cake bake -app /home/username/Aptana\ Studio\ 3\ Workspace/aurinko/aurinko/app/
Now the interactive shell appears as known from 1.3.
Maybe this helps somebody.

Related

How to check Cakephp version from command line?

I am using Cakephp 3.x but i want to know the exact version number using command line ? is there any command available which can show us the correct version which we are using in our application ?
i know we can use this echo Configure::version(); to check version using code, i was just curious to know if i can come to know the same thing using command line interface only..
FYI, i have windows 7 as OS, xampp as server with composer and other stuff installed in my cakephp application ..
Command for any OS (ubuntu,windows) will be welcomed to come to know about it ..
Thanks
According to their documentation for version 3.x , this is how you can do this. Shells, Tasks & Console Tools
In which they have mentioned to go to directory first using command line tool and then by typing bin/cake Something like this
cd /path/to/app
bin/cake
And in response you will be able to see not only CakePHP's current version but also PHP's current version and few more information.
Welcome to CakePHP v3.0.0 Console
---------------------------------------------------------------
App : App
Path: /Users/markstory/Sites/cakephp-app/src/
---------------------------------------------------------------
Current Paths:
-app: src
-root: /Users/markstory/Sites/cakephp-app
-core: /Users/markstory/Sites/cakephp-app/vendor/cakephp/cakephp
Changing Paths:
Your working path should be the same as your application path. To change your path use the '-app' param.
Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp
Available Shells:
[Bake] bake
[Migrations] migrations
[CORE] i18n, orm_cache, plugin, routes, server
[app] behavior_time, console, orm
To run an app or core command, type cake shell_name [args]
To run a plugin command, type cake Plugin.shell_name [args]
To get help on a specific command, type cake shell_name --help
Also I am not so sure this will work for older version than CakePHP 3.x as I have tried this in version 3.x only.. so please take a note on that too.
Because it doens't show the version when simply typing bin/cake in the project forlder, I also recommend this approach:
Browse to your project forlder
continue browsing to the bin forlder ( cd bin)
then type cake version
That works for me and it shown 3.5.6
Also I recommend including PHP in the system or user path if so you can type php -version anywhere in the prompt to get your php version.

Baking in cakePHP 2 in windows 7

I am new to the cakePHP and first starting to bake so I face this problem when following a tutorial and do the following:
Add paths to php and cakePHP
Run the CMD and type "cake" and get the following message:
Welcome to CakePHP v2.2.3 Console
---------------------------------------------------------------
App : C:
Path: C:\
---------------------------------------------------------------
Current Paths:
-app: C:
-working: C:
-root: C:
-core: C:\xampp\cake\lib
Changing Paths:
Your working path should be the same as your application path to change your pat
h use the '-app' param.
Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp
Available Shells:
[CORE] acl, api, bake, command_list, console, i18n, schema, test, testsuite, upg
rade
To run an app or core command, type cake shell_name [args]
To run a plugin command, type cake Plugin.shell_name [args]
To get help on a specific command, type cake shell_name --help
3.I type in the path where the app that's being developed is saved, that is:C:\xampp\htcdocs\blog
I have tried to add all possible paths like
C:...blog\app,
C:...blog\app\console,
C:...blog\lib\cake\console,
but I still get the message that the system cannot find the path specified.
I have been looking for the solution for couple of hours now and could only find it for the previous versions of cakePHP or any other OS but Windows 7.
You may want to set your path to folder/app/console of your project. Also to the folder where php.exe resides. This is the way i've set mine and works for me.
Try typing cake help in cmd, it should show cake help file.
edit: i have change this answer so everyone can have cake configured ok!
C:\xampp\htdocs\proyecto\app>set PATH=C:\Program Files\Common Files\Microsoft Sh
ared\Windows Live;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\win
dows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Windows Live\Shared;C:\Pr
ogram Files\TortoiseSVN\bin;C:\xampp\htdocs\proyecto\app\Console;C:\xampp\php;
then from your "project" folder (in my case "proyecto") go to app in a cmd window and type "cake help" it should show something like:
Welcome to CakePHP v2.2.1 Console
App : app
Path: C:\xampp\htdocs\proyecto\app\
Current Paths:
-app: app
-working: C:\xampp\htdocs\proyecto\app
-root: C:\xampp\htdocs\proyecto
-core: C:\xampp\htdocs\proyecto\lib
wich means, everything is good to go!
start the command promt
type cd\ press enter and then cd:/xampp/php press enter
php.exe C:/xampp/htdocs/cakeblog/lib/cake/console/cake.php bake press enter
where “C:/xampp/htdocs/cakeblog/lib/cake/console/cake.php” is the path of bake file.
Have Baking!

Cakephp2 Baking

i am using Cakephp2 and i am trying to baking my application using commandprompt
here is my steps
c:/>xampp\htdocs\projectname\app>..\cake\console\cake bake
it doesnot work .
But if i use cakephp1.3 with same steps it works fine and look like as
Interactive Bake Shell
[D]atebase Configuration
[M]odel
so on
AnyBody Tell me what to do ?
Thanks
The location of the Cake console has changed in 2.0. It's in: YOUR_CAKE_DIR/lib/Cake/Console/. Change YOUR_CAKE_DIR to the path to your Cake installation and you should be able to invoke cake bake again.
Just realised you're developing on Windows, I guess, in that case, the path becomes:
c:/>xampp\htdocs\projectname\app>..\lib\Cake\Console\cake bake
You can do it without changing your path variables.
For window machine and xampp you can do following step to bake:-
Type cd\ press enter
Type cd:/xampp/php press enter
Type php.exe C:/xampp/htdocs/projectName/lib/cake/console/cake.php bake press enter
1st assign proper path variables in your computer
2nd install updated cakephp2 files
3rd open cli , like MAMP/htdocs/project/app/console -> cake bake or i recommend cake bake all
Let me know if you need more guidance

Having trouble getting cake bake to work

I've installed the latest version of CakePHP on a Ubuntu 10.10 machine. I was able to run through a beginner tutorial just fine so I think my configuration is close to being correct. I can't get cake bake to completely work though. Below is my session. Things that look like anomolies are in bold. I think I must have one or more small errors in my configuration that are manifesting when running the bake shell. Thanks!
ubuntu#myserver.com:~$ cd /var/www/app
ubuntu#myserver.com:/var/www/app$ ../cake/console/cake bake -app /var/www/app
Failed loading /usr/lib/php5/20090626.so: /usr/lib/php5/20090626.so: cannot open shared object
file: No such file or directory
Welcome to CakePHP v1.3.2 Console
App : app
Path: /var/www/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)
P
What is the full path for this app including the app directory name?
Example:/var/www/app/myapp
[/var/www/app/myapp] > /var/www/app
Bake Project
Skel Directory: /usr/share/php/cake/console/templates/skel
Will be copied to: /var/www/app
Look okay? (y/n/q)
[y] > y
Do you want verbose output? (y/n)
[n] > y
Created: app in /var/www/app
/usr/share/php/cake/console/templates/skel/app_controller.php copied to
/var/www/app/app_controller.php
/usr/share/php/cake/console/templates/skel/app_model.php copied to
/var/www/app/app_model.php
/usr/share/php/cake/console/templates/skel/index.php copied to /var/www/app/index.php
/usr/share/php/cake/console/templates/skel/.htaccess copied to /var/www/app/.htaccess
/usr/share/php/cake/console/templates/skel/app_helper.php copied to /var/www/app/app_helper.php
Creating file /var/www/app/views/pages/home.ctp
File /var/www/app/views/pages/home.ctp exists, overwrite? (y/n/q)
[n] > y
Wrote /var/www/app/views/pages/home.ctp
Welcome page created
Random hash key created for 'Security.salt'
Random seed created for 'Security.cipherSeed'
Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in /var/www/app/webroot/index.php
Could not set permissions on /var/www/app//tmp
chmod -R 0777 /var/www/app//tmp
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)
q
ubuntu#myserver.com:/var/www/app$
Mark Murphy,
1.
Failed loading /usr/lib/php5/20090626.so: /usr/lib/php5/20090626.so: cannot open shared object
*.so files are shared libraries. I would try to tackle it be (re-) installing the PHP CLI.
2.
Could not set permissions on /var/www/app//tmp
How could the slash creep in twice? Such a folder should not exist.
Edit0:
It is a bit strange, as CakePHP should work right out of the box, but maybe you really should take a look at the specified variable in app/webroot/index.php and see if you can change the CAKE_CORE_INCLUDE_PATH so that the superfluous slash vanishes.
Edit1:
For general deployment there is nothing better than this afaik.
Edit2:
cake bake help returns:
-app Absolute/Relative path to your app folder.
Hence you should call either:
cake bake app /var/www/<your_project_name>/ <---- note the trailing slash
or
when in /var/www/ call cake bake app <just_your_project_name>
Edit3:
In a nutshell: You could download the CakePHP tar.gz and unzip it in your /var/www/, then rename the folder (having some weird cakePHP-1234... name) into the name of your application, e.g. missioncontrol. Then in your browser: http://localhost/missioncontrol , proceed as instructed.
This is a very quick method to get going, but you can develop other methods according to your build process.
After you have developed your app and intend to deploy it on a host different than your local machine, use the link provided under edit1.

Cakephp database migration error

I am using Ubuntu + cakephp 1.3. I am trying the database migration with the help of cakeDC migration plugin. I configured the plugin as per the instructions.
But when i goes to the terminal, goes to the path of the application application_path/app/ dir then fire a command 'cake migration help' it gives me following error,
Hello user,
Welcome to CakePHP v1.2 Console
Current Paths:
-working: /path/to/cake/
-root: /path/to/cake/
-app: /path/to/cake/app/
-core: /path/to/cake/
Changing Paths:
your working path should be the same as your application path
to change your path use the '-app' param.
Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp
Available Shells:
app/vendors/shells/:
- none
vendors/shells/:
- none
cake/console/libs/:
acl
api
bake
console
extract
To run a command, type 'cake shell_name [args]'
To get help on a specific command, type 'cake shell_name help'
Then i followed the steps given in the :
http://book.cakephp.org/view/108/The-CakePHP-Console
$ cake -app /path/to/app
But i am not getting the success. Can anybody help me out from this issue...
Thanks in adavnce.
You're executing cake shell, which is somewhere in your $PATH (type which cake to see which one comes in $PATH first). To run cake shell belonging to your app (version 1.3), execute /path/to/your/application/cake/console/cake (if you're in your /app dir, simply execute ../cake/console/cake) with any options you may need (like -app).

Resources