I am getting a Missing Helper error when I am trying to upload my cake php files to a shared host.
Undefined variable: javascript
Missing Helper File
It is working fine on my local machine.
I have the following directory structure in shared hosting:(using cpanel)
/home/user/
/app
/cake
/vendors
/public _html
/css
/img
/js
.htaccess
index.php
I have also made all the relevant changes to the index.php file and I was getting the full colored cake php intro page.
The strange thing is that it is recognizing the HTML helper and hence i am able to see my web page with full CSS. However, it is giving problems with javascript and other helpers.
I already have an app_controller file with all helpers well defined in $helpers =array().
Why is it giving this error??
As mentioned above, I have made changes to my cake directory structure. So, do I have to make changes to the paths.php file located in the cake/config folder??
I think that cake is not finding the javascript helper because something is messed up with config files. Is it so or there is some other problem??
in /app/app_controller.php, add:
var $helpers = array('Javascript');
your structure doesn't seem like cakephp structure :-(
Guys, I found a simple way to tackle this problem. I certainly cannot call it the solution for the problem. May be a temporary way to make things work.
I simply replaced
<?php echo $javascript->link(array('tabulator')); ?>
with the standard HTML,
<script type="text/javascript" src="/blog/js/tabulator.js"></script>
and it worked!!
I still don't know the problem with javascript helper. All other helpers, Html, Form and Ajax are working fine. I am also using Gravatar for my blog. So, the Gravatar Helper was also giving problems.
The solution to this problem was weird.
I renamed the helper file gravatar.php instead of Gravatar.php. This worked insipte of the fact that helper file name should begin with a capital letter according to cake naming conventions!!
I also had to solve numerous other problems like making changes to the index.php file so that cake can locate the modified directory structure.
Also, had to make changes to .htaccess file for rewriting the base and directing the blog to the new URL.
Man..so much for rapid development!! :O
Related
UPDATE
If I browse url like
localhost/myapp/index.php/about_us/index
it works. What is this index.php in url? Do I need to mention it in some config file so that it gets appended and forms correct url in menu/links on site?
Original Question
I have no knowledge of PHP but I got a project which in php (codeigniter) to convert in Ruby on Rails.
I could set up db and application well, when I browse application with base url(without mentioning controller & action) it loads page properly. But as soon as I mention url like
localhost/myapp/home/index
it shows message
The requested URL was not found on this server.
If I change default controller to anything in routes.php that page with index method works fine but not with explicit mentioning controller and action.
I am not sure what is the issue, I don't know how routing works in php :(
Any help will be appreciated.
In CodeIgniter, all requests are directed through the index.php file, which acts like a front controller.
index.php must be present in the URL unless you have created a solution to eliminate it. When using Apache, that is typically done with an .htaccess file. There are hundreds of articles and questions regarding this technique -- certainly you can find something to help you.
In regards to URLs and a config option for defining index.php, CodeIgniter URL helper functions such as site_url() utilize the config setting $config['index_page'] found in application/config/config.php. If you remove index.php from your URLs using an .htaccess solution, you can make this setting blank:
$config['index_page'] = '';
This setting is useful for when you want to rename index.php to something else, as well (not very common).
It seems that you had not configured your web server properly. See this question for details for Apache: routing problem in codeigniter
And here are rules for nginx: http://wiki.nginx.org/Codeigniter
I was loading view in CodeIgniter as
$this->load->view('../../myfolder/footer');
It was working fine on windows machine. I have uploaded app to linux machine and start getting error
Unable to load the requested file: ../../myfolder/header.php
myfolder is in CI application folder.
How can i load view from application/myfolder
Please help me and thank you in advance.
Why you need tho load views in application/myfolder?? Code Igniter expects that views are located in application/views or application/views/myfolder. Put your files in application/views and then you can load it using:
this->load->view('footer');
or
this->load->view('myfolder/footer');
If it worked on Windows but no longer works on Unix, it could be because the filepaths are case sensitive in Unix.
Check the file structure and file names to make sure they match the CodeIgniter requests exactly.
E.g.:
$this->load->view('../../myfolder/footer');
Will fail trying to load:
../../MyFolder/footer
../../myfolder/Footer
../../MyFolder/Footer
etc
$this->load->view(base_url().'myfolder/footer');
That should work but I have no idea why you're trying to work outside the views folder to begin with. Just structure your views folder like below. Load the header, footer and anything else that's static from a template page.
Views
--pages
--admin
--templates
--etc.
On my local setup I have a load of different CakePHP websites. I'm using a Mac so the folder structure is something like ~/Users/cameron/Sites/sample-website and then within each of these websites I will have the typical Cake folder and App folder.
What I would like to do is have just a core cake folder and then have ALL the sites pull from that one cake core so I don't have the same stuff several times over. I have been reading some tutorials on the web: http://rickguyer.com/cakephp-one-core-many-apps/
So I have my cake folder here: ~/Users/cameron/Sites/cake-1.3/ and then my site here: ~/Users/cameron/Sites/sample-site/ and in this folder I have the usual app folder and htaccess to tell it where to find webroot etc.
Now I have edited the index.php file inside webroot like the tutorial BUT have only changed one line because I haven't moved my files OUTSIDE of the App folder like he does. So the only like I have changed is as follows:
if (!defined('CAKE_CORE_INCLUDE_PATH'))
{
define('CAKE_CORE_INCLUDE_PATH', '..'.DS.'..'.DS.'cake-1.3');
}
As far as I can tell that is correctly looking two directories up and finding a folder called cake-1.3 however it just gives a error 500?
Any ideas what the problem is? Thanks
EDIT:
Even doing this doesn't work???
Which If I echo: echo CAKE_CORE_INCLUDE_PATH; gives /Users/cameron/Sites/cake-1.3 and if I paste that in the address bar it loads up the cake folder so it's definitely the correct folder structure JUST it doesn't like looking at cake outside of the main url?
if (!defined('CAKE_CORE_INCLUDE_PATH'))
{
define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3'); echo CAKE_CORE_INCLUDE_PATH;
}
You are right on the money with:
define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3');
Just make sure that Users sits in root. In other words, when you go to terminal you can get to this directory by typing: cd /Users/cameron/Sites/cake-1.3
It looks like you may be on a MAC. If so, your linking is correct. Most of the time what I find is you have done a copy paste of the app directory and it does not get the .htaccess files. I would check those first. But here is a comprehensive list of what you should verify:
Make sure the host is pointing to
the correct directory
(/Users/cameron/Sites/sample-site/)
Verify mod_rewrite is in fact on.
Verify you have copied the .htaccess
file in both the
/Users/cameron/Sites/sample-site/
and the
/Users/cameron/Sites/sample-site/webroot
directories.
Confirm that the
/Users/cameron/Sites/cake-1.3/
directory has a directory called
cake in it that contains the core.
Once all of this is confirmed, you will be good as gold!
Happy Coding!
UPDATE:
When the index.php file looks for the cake core, it will look for a directory inside the location you are pointing to for another directory called cake. So in your case:
define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3');
You must have the cake directory inside /Users/cameron/Sites/cake-1.3. Your directory structure will look like:
/Users/cameron/Sites/cake-1.3/cake
/Users/cameron/Sites/cake-1.3/cake/libs
/Users/cameron/Sites/cake-1.3/cake/config
/Users/cameron/Sites/cake-1.3/cake/console
etc.
CakePHP 3.0+
In CakePHP 3.0+ this configuration is moved out of webroot/index.php to App/Config/paths.php
If you have access to your php.ini, you can add the path to Cake core there. Doing it this way means you don't have to change webroot/index.php at all. Example in php.ini:
include_path = ".:/usr/local/lib/php:/home/something/phpinc/cakephp2/lib"
According to the CakePHP 2.x docs, this is the recommended way to share the Cake core (assuming you have access to your php.ini).
You can have only one cake core but you must have one app folder (containing MVC) by site.
Is this a misunderstanding of the folder structure of CakePHP?
From the docs (CakePHP folder structure):
The app folder will be where you work your magic: it’s where your application’s files will be placed.
The cake folder is where we’ve worked our magic. Make a personal commitment not to edit files in this folder. We can’t help you if you’ve modified the core.
So the cake folder shouldn't change between all of your uses, therefore you have 1 copy. You can always change some of the functionality of the core by making your own changes in the app folder i.e. extending.
There is no need to edit index.php.
Just put an alias (or link in UNIX) to your cake folder in each of your sites folder. Works perfectly. Same goes for plugins and vendors folder.
I recently downloaded cakephp-1.3.4. I set it up on my web server. I followed the advanced installation settings. My folder structure is as follows.
/common/
cakephp/
app/
etc...
/htdoc/
The /htdoc folder is the webroot; cakephp resides in the common folder.
I have configured the paths in index.php to point to this folder structure. I have the app up and running. I created a layout, the app has picked it up (along with all the css and images - all that works).
I created a posts_controller.php in cakephp/app/controllers/. Now when I try to access the following page: http://localhost/posts. I get a message that the controller cannot be found and that I should create a app/controllers/posts_controller.php (it already exists!).
Also the strange thing is using the default pages_controller works. I created an about.ctp and dropped it in app/views/pages/about.ctp. Vising http://localhost/pages/about shows up as expected.
SOLUTION:
Sam helped me solve this problem (see the long comment thread below). The problem was I had set relative paths for my ROOT folder. This messed things up. The solution is to either directly set an absolute path or call realpath with your relative path for it to be resolved into the right absolute path.
Make sure your controller class is named correctly (should be PostsController) and inherits from AppController (not strictly necessary but good practice).
I have installed zend framework on my local machine. I have configured a vhost in httpd.conf and have added a line in my hosts file (127.0.0.1 mysite). I am running windows 7. Everything works perfect. The problem is when i upload on a hosting server the paths get mixed up.
I am uploading on a remote dir called zf-framework. To access the index page i need to type this url: http://mysite/zf-framework/public. It displays the index page but when i press any links on the page they get mixed up and end up being something like http://mysite/controller/action when in fact it should be http://mysite/zf-framework/public/controller/action. I have found a work-around for this situation...to use echo $this->baseUrl(link) for any links i have in the layout.phtml. The problem is more serious when it comes to submitting forms. I can't use baseUrl there....or i don't know how to use it. Is there a way to write some general config stuff so that this could be automatically resolved by the framework. Let's say to write something in index.php or bootstrap.php that will fix the paths automatically?
If you're using Zend_Application, then add the following to your configs/application.ini file.
resources.frontController.baseUrl = "/your-path-here"
If you're not using Zend_Application, then do this in your bootstrap, or index.php file.
$front = Zend_Controller_Front::getInstance();
$front->setBaseUrl('/your-path-here');
You won't have to use $this->baseUrl() when submitting a form to the same action and controller (just leave out the action attribute in the form tag), or when using the Redirector action helper. However, links in your view scripts will require you to $this->baseUrl('/url-without-base'), which doesn't seem too bad to me.
I am not 100% on this, but if you specify the route in your routes.ini as zf-framework/public/Controller/Action etc this should fix your issue.
I would see this as a bandaid, but I am not 100% sure on how to properly fix your issue other then you modifying the vhosts file on the remote server to set a document root to the public folder. If that is not an option, well the above should work, but know that all of your files are potentially accessible from everyone (at least your folder structure). I am not sure what harm this can do (if any) other then if your database schema is in the /data directory.
It is better to try and get the public set as the web root, if possible.