CakePHP View URLs case-sensitive on one server, not another... why? - php

So I'm working on a CakePHP app, and had this line in one of my controllers:
$this->render('/vids/index');
It was working fine in MAMP. But on my live site (on MediaTemple) the controller couldn't find the view. After nearly pulling my hair out, I changed the line to this:
$this->render('/Vids/index');
And it worked.
Zuh? What could account for one system being case sensitive, and another not? My assumption is that this isn't a Cake issue, but I'm so baffled, I have no idea what's causing the discrepancy.

Simply because the 2nd line (uppercase Vids) is correct for a 2.0 app. And I guess there are differences between OSX (guess that from you using MAMP) and the servers OS you deploy the app on.
And why do you call render() manually? If you access /vids from the web it should automatically route to VidsController::index() and the controller will auto pick the right view.
Stands Vids for videos? Thats a horrible name. Abbreviations in code suck hard, if you want to rely on /vids for the URL use the router to rewrite that url.

Related

My CodeIgniter 3.0.3 model files cannot be found unless lcfirst (example_model.php)

I'm building a simple web application using CodeIgniter 3.0.3, and have run into a lot of issues regarding capitalization consistency. The CI 3.x documentation clearly states that Model files should be ucfirst and referenced using lcfirst i.e. file application/models/Foobar_model.php, loaded using $this->load->model('foobar_model'), and called with $this->foobar_model. Source: Official CI 3.x User Guide.
When I follow those rules, I get the following error message Unable to locate the model you have specified: foobar_model. Referencing the model using Ucfirst i.e. $this->load->model('Foobar_model') and $this->Foobar_model generates the exact same error message. I am able to resolve the issue by making my filename lcfirst application/models/foobar_model.php while the class name inside the file remains Ucfirst. As long as I name my file lcfirst foobar_model.php, it does not seem to matter whether I use Ucfirst or lcfirst to reference it from inside my controllers.
Strangely, I have found that I need to use application/controllers/Ucfirst_controller.php for my controllers with case-sensitive routing i.e. $route['default_controller'] = 'Ucfirst_controller';. I receive a 404 error when trying to route $route['default_controller'] = 'lcfirst_controller'; to application/controllers/lcfirst_controller.php.
Everything I have found on stackoverflow and other forums for CodeIgniter model and controller issues seems to involve people using lcfirst instead of Ucfirst on CodeIgniter 3.x, or using Ucfirst instead of lcfirst on CodeIgniter 2.x.
Basically my question is where is this case inconsistency coming from and how can I fix it? I want to follow standards so that others can join my project at a later point.
Other Info: I don't think that this should matter, but just in case. I am developing on LAMP on an Ubuntu machine with ext4 file formatting which is obviously case sensitive. I plan to deploy my project with Google Compute Engine running debian-7-wheezy with a HHVM stack. I am currently developing with just one partner, who is developing on a MAMP stack with non case-sensitive file formatting so he does not experience any of these issues.
Thanks everyone :~)
My system/core/Loader.php file was not updated properly when I updated from CI 2.x to 3.0.3. Properly updating this file resolved my case inconsistency issues, I am now able to name my models and controllers Ucfirst.php and reference them as $this->lcfirst and everything works properly.

How to create an index-file for Xampp

I apologize in advance if this issue has been posted before. My problem is that my programmer had to bail on my project due to personal reasons and left me alone with a 95% finished site. I have some basic experience with ASP classic but PHP is fairly new to me.
FireFTP scr_shot: https://www.dropbox.com/s/9lws1u0sl8k93rg/fireftp_scr_shot.jpg
To shorten it up; (with Xampp installed) I have downloaded my site to the hard-drive and is now trying to get it work on 'localhost'. Immediately I sense the absence of an index-file.
Do I need to make one myself for the use in localhost? In that case, what am I looking for?
Thank you in advance.
First if you want to make an index-file of your current website, you have to put all your pages in a folder in
xampp/htdocs/
e.g
C:\Xampp\htdocs\mywebsite
then after you make a directory just visit the url like this:
localhost/mywebsite
, remember to put an index file inside the mywebsite folder.
It turned out that there was a MYSQL-database behind the site which I had no idea about or any knowledge of how to get around.
I had the database taken off and written the code into the site-files.
Afterwards everything worked as laid out above comments.

Kohana: server can't find core.php because of naming convention change

I have a project written in Kohana 3. The /system subdirectory is pulled in via a git submodule:
[submodule "system"]
path = system
url = git://github.com/kohana/core.git
After version 3.3 it seems all classes were changed to the first letter being upper-cased. ie core.php is now Core.php. This didn't seem to have any effect locally on my mac but now that I've uploaded my app to hosting provider Fort Rabbit I'm getting an error that it failed to open system/classes/kohana/core.php. I suspect this is because that is now system/classes/kohana/Core.php
Can anyone advise the best way to proceed? Do I need to change every instance of require SYSPATH.'classes/kohana/classname'.EXT; to the uppercase equivalent?
Basically yes. In 3.3 when you call a class, you have to be case sensitive. The same applies to the file names. Migration guide explains this quite well.
You can also check this post to automate the upgrade.

Using multiple php frameworks on one website

Our main website uses symfony 1, and by the time I started working on the code it seems impossible to upgrade (too much custom code from previous developer). Now we are adding a large addition to what the company offers. Instead of using a really old framework I wanted to use CodeIgniter, also since I'm very familiar with it. My real question:
What is a proper way of setting up a website to use multiple frameworks. The new features will be separate from the original website, but it will still need a few tables of the database.
I was going to have apache handle where the root directory was depending on the url and just do everything normally. The main website is example.com and the new feature will be abc.example.com
I'm really looking for people who have done this and some tips and warning they had.
PHP will run the framework based on which directory is loaded on the server. For instance, on most apache servers the root directory for example.com would be /www. Which means all of the code for Symphony would be in /www/*.
When you setup the path of your subdomain, just put it outside of the /www folder. Then, when you go to abc.example.com apache won't try to load the original site along with the Symphony framework.
I think it will be fine for both frameworks to share the same database tables. I'm not entirely sure how you plan for these two applications to work, but as long as you don't change the column names and types you should be okay.
If you don't want the applications to share the data in the original table, then look into using mysqldump or something of the like to copy the data over to a new table.

How do I ensure Symfony url_for() includes the PHP filename?

I've been battling to set up my Symfony project on a IIS web server, but have got it pretty much working.
I still can't get the nice URLs working though. When I use my dev environment, url_for generates URLs that look like .../frontend_dev.php/booking/create and everything works fine. But as soon as I use the prod environment url_for generates URLs that look like .../booking/create, which don't work presumably because of problems with the rewrite setup on IIS.
I don't want to try and get the proper rewrite working on IIS - I've stuffed around with that for ages now and have given up. If you have a silver bullet to fix my problem then I'd love to know but that's not really what the question is about.
I've found that calling .../index.php/booking/create works fine. Therefore I can fix my problem simply by ensuring that url_for always adds the filename. But how can I do this? I thought it might be just assuming index.php, so I made a copy called frontend.php but it still generates nice URLs, without the filename. It seems that if it's the dev environment, it adds the file, but if it's the prod environment, it hides it. Any ideas on how to override this?
In apps/appname/config/settings.yml, set no_script_name to false.
See the symfony Reference Book.

Categories