I'm trying to bake my first CakePHP application and am unable to get any page to particularly load for me right now. I've updated my config settings for salt,database, etc. and the index.php page tells me that I have configured everything.
So far I've used cake bake all on just one database table so far to make sure it loads properly. I created the Model, Controller, and View for the standard add/index/view/edit pages. When I try to access URL/organizations/index.php I'm hitting a 404 error however.
Is there any troubleshooting someone might have advice for how to solve this one? It is confusing to me that the index.php loads (so it redirects properly when loading the webroot) but trying to view any View pages yields no results. Is there any debug commands I can do to view what the valid pages would be? Or any additional information I can provide?
If you try URL/index.php/organisations or something similar to this and it works, then there is an issue with URL re-writing on the server which you'll need to correct.
I believe if you have things set up correctly you would want to visit /organizations in order to access the index() method of the organizations controller.
In general the ".php" is left off of the URL, as your index.php file initiates all the bootstrapping and routing. This also requires a correct .htaccess setup. Hard to say exactly what the problem is without seeing the app or an error message.
Try in url
URL/organizations/index.php
To
URL/organizations/index
or
URL/organizations/index.ctp
Cakephp using .ctp extension, that means cakephp Template. Please see this link. And also you can see your app\view\Organizations folder. Here all file is with .ctp extension. Isn't it ?
Related
Background: I'm new to CakePHP and trying to modify an preexisting project.
When I try to add a new UploadsController it is supposed to handle xxxx/uploads requests right?
However, when entering the url neither AppController or UploadsController, allow index.php to do a dispatch. Files are being called. It goes straight to /uploads which is a directory.
I realize this is a bad design to begin with but trying to fix things one step at a time. Need to authenticate before going to /uploads, and than take action.
What am I doing wrong? I tried to modify routes.php to specify controller but that does not work either.
So as I said I am new and fixing someone else's project. I found that there is a security issue where uploads directory is exposed. So I figured I would add Controller to take care of this. uploads folder was under webroot as a result it was going to uploads folder and was not directing to controller. Thanks and hopes this helps someone in the future.. although kind of doubt it since it was a really bad way to do this to begin with.
With the info you gave this is what I can suggest:
Check to see if the UploadsController is in the Controller folder.
Make sure that there's at least a index.ctp file in Views/Uploads/
Check to see if the UploadsController has a default index() method. This is what www.example.com/uploads/ will hit.
I am new to Cake PHP, in regular PHP I had a index.php and for any bad url tried it would just show home. In Cake, I am switching an old PHP and HTML website to use Cake PHP. I already successfully converted one page :(. Which is good but that page is just about_us. I have not done Home (which would be index.php). So here is my scenario
I created all the controllers and models with no code in it except for this one page that gets a bunch of products,but I have the following questions as I do not understand CakePHP documentation:
1) How can I set up an index.php page and where should I put it and Actually this page needs to grab something from the db too. Should it go under views/pages? (i am not sure)
2) Also how do i retrieve parameters in Cake PHP? i used to have index.php?name=blah and just pull name in. I am not too clear on how the cake website says to do it.. you just add the parameter after a /index/2 for example? How come?.
Thank you
I think cake is quite well-documented. You just didn't take enough time to read the book.
1) If you want to create a 'Home' page, it doesn't have to be an 'index.php' file.
(cake has some index.php file to call the bootstrap and dispatch logic and don't mess with them)
You can
- create a view (some .ctp file), put it to /app/View/Pages/ so you can use the url '/pages/' to access the page. Or you can edit /app/Config/route.php file to connect the page to whatever path you want
- create a normal controller/action/view (if you need to grab something from the db so you should have some models, your controller will call the models and pass data to the view). You can edit /app/Config/route.php to connect the page with your path.
Cake is convention-over-configuration. But you should understand both the convention and the configuration. Read the book. Learn more about MVC, about cake's convention and mechanism.
2) You can retrieve the parameter from controller or view (you should do it in the controller) by using $this->param or $this->passedArgs. There are named ones (e.g: profile/name:john) and unnamed ones (e.g: profile/john).
The url structure of my cakephp based site is mysite/cakephp/myapp/index.php/controller/action/input_paramaters
I cannot remove index.php from my url, as I dont have access to httpd.conf file.
Anyways, my question is that I just need to change the url of my homepage to something like http://mysite or mysite/myapp
How would I do that?
Thanks a lot!!
The problem sounds to me that you don't have mod_rewrite enabled or Apache AllowOverwrite is not set properly.
If you don't have mod_rewrite then you cannot change the urls with the pretty ones (provided from CakePHP).
If the AllowOverwrite is not set to On. Then even if you have mod_rewrite enabled, the .htaccess files in your directories doesn't take effect.
I don't know which is worst. Speak with your hosting provider and ask for help.
It is not really clear to me which part of the URL changes. CakePHP routing applies only relative from the cake directory. So if you move from http://example.com/foo to http://www.example.org/bar nothing needs to be changed in Cake.
However you might have hardcoded some img/CSS/JS URL-s that needs some work now. I also use the HTML base tag so my app works perfectly fine under various base URL-s.
I have a client who has many blog customers. Each of these WordPress blogs calls a plugin that provides a product link. The way that link is composed looks like this:
{website}/wp-content/plugins/prodx/product?id=432320
This works fine on all blogs except two. On those two, when you try to call the URL, you get a 404.
So, I disabled all plugins except prodx and reverted the theme to default (Kubrick), thinking perhaps a plugin intercept with add_action() API was doing this, such as intercepting URLs and redirecting them. However, this did not help.
So, I upgraded the WordPress to the latest version. Again, didn't fix.
So, I checked permissions, comparing with a blog that worked just fine. Again, didn't fix.
So I replaced the .htaccess, using one from a working blog. Again, didn't fix.
So I replaced all the files using some from a working blog that was identical to this one, and then restored the wp-config.php file back so that it talked to the right blog database. Again, didn't fix.
Again I checked permissions meticulously, comparing to a perfectly working blog. Again, didn't fix.
So, I created a test.php that looks like so:
<?php
print_r($_GET);
echo "hello world";
I then copied it into another plugin folder and used my browser to get to it -- again, 404. So I copied it into the root of wp-content/plugins and tried to call it there -- again, 404. So I copied it into wp-content -- again, 404. Last, I copied it into the root of the WordPress blog website, and this time, it worked!
Doesn't make sense.
I started to think that perhaps something was going on with /etc/httpd/conf/httpd.conf for this customer, but the only thing I saw different in their for this customer was the IP address was different than the customer's blog that worked. Each customer gets their own IP in this environment my client has built.
My client sysop is baffled too.
What do you think is going on? Is there something wrong in the WP database for this customer? Is there something wrong in httpd.conf?
You could check for bad URLs in plugins' options in the WP options table using phpmyadmin (and compare other aspects of each blogs' options) which might be already available at your host, or as a plugin: WordPress › Portable phpMyAdmin « WordPress Plugins. Or delete the plugins' options with Clean Options to completely "reset" the plugin (if the plugin uses options): Clean Options « WordPress Plugins
You should look into your server's error log, there should be an explanation. If not, turn up debugging levels etc. That said, the plugin really shouldn't link to the file in the plugin dir, it should use the wordpress rewrite class http://codex.wordpress.org/Function_Reference/WP_Rewrite
I think the problem was that the URL was too long. Here's some great info about that:
http://www.boutell.com/newfaq/misc/urllength.html
And for some reason the blog was getting a 404 instead of a 413.
The fix was that I used gzcompress to shorten my long product ID (which was a cloaked URL), then bin2hex. So I made the URL like so:
http://myblog.com/item/789ccb282929b0d2d72f2f2fd7cb4ac92fcc4faed44bcecfd54fcec94cced63536373334b730d7353430333334b530b60f0df2b1cd00ea503576543572032290befcb2d4a2e292fce46c904e90b0b15b1a50854b9aaa915980a3bb2b901910e4ef12ea1c0214f00f0ef60e058a181a199b5b18999b0100194725b4
From there, I had my plugin add an init handler to hijack the URL, inspect it, and redirect. That function looks like this:
add_action('init','hijackURL');
function hijack_URL() {
$sURL = $_SERVER['REDIRECT_URL'];
if (empty($sURL)) {
$sURL = $_SERVER['REQUEST_URI'];
}
if (strpos(' ' . $sURL, '/item/')>0) {
$sID = str_replace('/item/','',$sURL);
$sID = trim($sID);
if (empty($sID)) {
require('../../../wp-blog-header.php');
$sBlogURL = get_bloginfo('wpurl');
header('HTTP/1.1 302 Moved Temporarily');
header("Location: $sBlogURL");
exit(0);
}
$sID = pack('H*', $sID);
$sURL = gzuncompress($sID);
header('HTTP/1.1 302 Moved Temporarily');
header("Location: $sURL");
exit(0);
}
}
I am having some issues with a site that was working correctly until i implemented full page caching in CakePHP.
I have followed the guidance in the Manual and have my $session->flash in a no-cache block as so:
<cake:nocache>
<?
if($session->check('Message.flash')){
$session->flash();
}
?>
</cake:nocache>
However, whenever a controller sets a flash message and redirects to a cached page the page loads down to the tag and then gives the error:
Notice (8): Trying to get property of non-object
[CORE/cake/libs/view/helpers/session.php, line 145]
Fatal error: Call to undefined method stdClass::renderLayout() in
/home/decipherd/domains/example.com/public_html/beta/cake/libs/view/helpers/session.php
on line 14
If i then go to a page created by another controller the correct (delayed) message is displayed and the page loads correctly.
I have now submitted this to the CakePHP trac as ticket 282
Sounds like it might be an issue with the core, have you tried submitting a bug report?
Are you sure that there is something in the flash message? Try:
debug($session->read());
OR to output it to the debug.log
$this->log($session->read(), LOG_DEBUG); // this might not work in the view?
Looking at the error message, it seems as is SessionHelper is not available for some reason.
I am not sure why exactly, this helper is usually loaded automatically when using AuthComponent or SessionComponent in your application.
Just a guess, but it might be worth putting $helpers = array('Session', ...); in your problem controller or AppController for good measure.
You can inspect everything available to your view with debug($this);
Ultimately, I would take Matt's advice and upgrade to the latest stable version anyway.