How do I get CakePHP configured so it shows up correctly in my browser?
I am a cakephp newbie and I had trouble to view the files under the view folder through browser.
I used cakephp console to bake model, controller and views. (ex: Invoices_controller.php for controller, invoice.php for model and a invoices folders under views folder). According to the tutorial I read, I can access the invoice view by t开发者_开发百科yping http://localhost/myProject/invoices
(there is no index.php inside the invoices folder..but the tutorial shows it still can display a page. no idea how they did it)
The path for my invoices is myProject/views/invoices and there add.ctp, index.ctp, edit.ctp files inside the invoices folder.
The browser showed the file is not found when I typed http://localhost/myProject/invoices
You have some lack in your knowledge about how the webserver handling a request when cakephp is installed. Assume that we use apache. In cake's folder structure you can see .htaccess files in the root, app and webroot directories what have url rewrite rules in them. At the end a normal request to a cakephp site will be transformed to a http://site.url.root/app/webroot/index.php?url=original.url
In nutshell to understand it in your point of view: That index.php call the required php files and at least a cakephp app object is built up in the memory with the required models and methods. Then the app object let say start and calls its methods (model, controller and view methods) and at the end it gives back a result to apache what serves it to you.
Therefore the original url path is a "non existent" virtual url.
If you enter http://localhost/myProject/ do you get a cake intro page? If so does it highlight any problems?
It sounds to me as if you do not have Apache set up properly. I don't know what OS you're using, but it might be worth checking this link, written for Ubuntu, to make sure all is well: http://leoponton.blogspot.com/2010/05/getting-cakephp-up-and-running-on.html
I fixed the same problem. if you are using windows 7 os, wamp server, cakephp 2.2.3. then
goto apache -> http.conf -> open -> search for mod_rewrite -> uncomment the line LoadModule rewrite_module modules/mod_rewrite.so
Now restart your server, now it should work fine.
Jerry, I think the issue is this. You have put the CakePHP folder in the root of localhost. I would propose that you create a virtual host pointing the myProject so the url becomes:
http://myProject/accounting
This may solve your problem. Be sure rewrite module is on. Also, when you point the virtual host to myProject, it should be the APP folder of the cakephp. If you want to run multiple projects off the same core, you can set them up like so:
/var/www/cake
/var/www/html/myProject
/var/www/html/myProject2
The /var/www/cake directory is where you drop the cake core. Under this directory you will have cake, app, plugins, vendors, etc. the myProject(2) directories will be the contents of the app directory.
Now, to get this to work, you need to go to /var/www/html/myProject/webroot/index.php and edit it to point to the cake directory in /var/www/cake. This will then load the core when rewrite points to index.php in webroot. You should be good to go!
精彩评论