Are there codeigniter controller sub-directory limits? - php

Greetings,
I've encountered a seemingly bizarre issue, and was wondering if anyone is able to shed a light.
I created a simple controller two levels down from the traditional /application/controllers/ directory and I'm seeing a CI-generated 404 when hitting said controller.
To elaborate, my directory structure is as follows:
/ci/application/controllers/dir1/dir2/myfile.php
The file itself has a simple function with an echo statement. When I move said file up one level such that it is located in:
/ci/application/controllers/dir1/myfile.php
It works.
I've tried changing the name of the "dir2" directory in the example above, the name of the controller, the names of the functions within the controller -- to no avail. I'm able to hit the same php file without going through the Code Igniter framework, and I'm on a Windows machine working normally so I can't imagine this to be a permissions-related issue.
I'm led to think that CI simply isn't willing to go into the controllers directory more than one level. Is this possible, or am I missing something?

Try this out: http://glennpratama.wordpress.com/2009/10/20/multi-level-subfolder-for-controller-in-codeigniter/
Basically, you need to override the default codeigniter router with your own MY_Router class

"Out of the box", Codeigniter only supports a single level directory structure for Controllers.
There are ways to extend the default Router class to enable this feature.

Related

Codeigniter : Regular controllers are ok. HMVC controllers don't work (Page not found)

So this is the annoying kind of problem where something works perfectly on your local project, but everything breaks once deployed in production.
In this case, i can access all the pages generated by a regular codeigniter controller (situated in application/controllers). However, once i try accessing a HMVC module, i just get a codeigniter 404 error.
Situation still ok for regular controllers:
So for instance, if i have a regular controller C1 situated in application/controllers/C1.php, which contains the function page(), i can access www.mysite.com/C1/page without an issue.
Problem for accessing HMVC controllers:
However, if i want to access the controller C2 situated in application/modules/C2/controllers/C2.php, through the url www.mysite.com/C2/page, i'll get a 404 error.
And problem accessing regular controller through ajax:
A second issue appears when performing an ajax call, using a path which references a regular CI controller. The path used in the ajax call doesn't seem to be recognized, and i receive a 500 error. However, when calling the same path directly in the URL bar, the correct function seems to be executed. I had solved a similar issue before by applying the solution found in Codeigniter base_url() not working properly for ajax. However, i have not yet identified if this is the same issue.
It feels like a loader issue, but i'm no expert!
Even if it was a loader issue, why would it work on local and not on production?
Have you ever encountered something like this? Do you have an idea on how to tackle this issue?
**Edit 3: ** I removed the 2 previous edits because they are now irrelevant.
After activating the debug mode, and adding some logs, i finally found what i think to be the answer.
Long story short, my local codeigniter version runs on windows, and for some reason, when trying to reach a controller, the case is ignored. So File.php and file.php are considered the same.
My production server however runs linux, so it doesn't consider that 2 different file names refer to the same file. So i ask for file.php, and the server answer "there's no such file", because the file i actually want is File.php.
I need to turn in. I'll propose a proper answer tomorrow after running some more checks.
Thanks,
Loïc.
So the issue was not related to regular controllers versus HMVC controllers. Basically what happens is that my local dev environment is Windows, and for some reason, windows decides that the case doesn't matter when naming a file.
So file.php would be seen as the same name as File.php (notice that the first is lowercase and the second uppercase).
In my code, i was trying to get file.php (lowercase), while the actual file was named File.php and it worked, on windows.
However, in civilized operating systems File.php and file.php are considered 2 different names, and that's why suddenly things where not working in production, even though the code was the same. The controller files just could not be found.
I changed the names of my controller files (put them in lowercase) and things are working fine now.
Thanks everyone for your suggestions.
Loïc.
With HMVC routes need to be like
$route['something'] = "module/controller/function";
$route['something/(:any)'] = "module/controller/function/$1";
Make sure like that also when use controllers intead of welcome.php make sure controller filename like Welcome.php
When using routes if have not remove index.php from controller then url would be
With http://localhost/project/index.php/something
Without http://localhost/project/something

Zend delete model

Good day everyone.
I am frontend developer but I have to make slight adjustments in the backend, built with Zend Framework.
I have a controller CalendarController.php, and wanted to make a relative model, called Calendar. The model was instantiated as
`class Project_Model_Calendar extends Project_Model_Abstract`
in a file called Calendar, placed in Model directory.
Later on I figured out that I dont need this model, so I simply deleted it, along with only reference to it in the controller. (it was used like this
`$this->form = new Project_Model_Calendar();`
)
Apparently there is some memory cache or config file that saved this model, and tries to load it every time.
I get the following error
Zend_Session::start() Error #2 include_once() [function.include]: Failed opening 'Project/Model/Calendar.php' for inclusion
Why do I get this error if I dont use the model anywhere? How can I clear this cache of loaded models?
Could you please help me with it? Please forgive me for asking such unspecific questions, but I need to fix it, and Zend framework is still a mystry for me most of the time.
Including the file will probably still result in an error, even if you're not using it. Make sure it isn't hardcode included in the paths in your php.ini, httpd.conf, or .htaccess files.

Model Missing, Codeigniter

I am using and have been using the framework CodeIgniter for a while. It works perfectly on my localhost, once I upload it to a server it gives the following error message
Unable to locate the model you have specified: auth_model
To point it out, it works on my apache perfectly, do you have any idea to what the problem can be? I am talking with customer support of the webbhotel, but they can't seem to find anything on their end.
Thanks in advance.
Edit: It manages to load many different files, the session library, my own controllers, helpers and view files. It just models that it stops at, I've named them all 'Auth_model.php", 'Login_model.php' etc. The models themselves are declared class Auth_model extends CI_Model {}
Sounds like a path issue,
I would first check where your starting at and get some data to compare with
CodeIgniter FCPATH and APPATH are both set in the main index.php file,
FCPATH = root
APPATH = application folder
Find out what your paths are set to, check your config/config.php file make sure you have correct info there.
Just a thought, are you using a common auth library? Sucb as freak/ion/bit/etc auth's
The session error, is being caused by echoing data you can google the error and get a decent understanding of the error from there.
As it turns out the webhotel (one.com) got a delay when you upload, hence it was a bit troublesome to actually troubleshoot it, but here it goes. Every file name except for the exception of MY_Controller needs to be in lower cases. So the answer was pointed out by some people.
The problem is with codeigniter because it looks for lower cases only in some cases. So yeah, models should be in lower cases from now on!

Codeigniter: user defined helper function does not load

I made a custom helper extending the system string_helper.php.
I placed it in my /application/helpers directory, called it MY_string_helper.php as required, unit-tested its functions.
Now, when I try to call one of its functions from a model, it does not work.
The functions in the default string helper work, instead. It looks like my extension is not loaded for some reasons.
Thanks a lot, and happy holidays.
Edit: even funnier. I saved the file as categories_helper.php in the system/helpers directory, and when I try to load it within a model i got the following response: *Unable to load the requested file: helpers/categories_helper.php*
I had the same problem. I came from windows OS development of my codeigniter project, then shifted to Ubuntu, but somehow it still didn't load my helpers.
I found that changing the naming convention to lowercase solves the problem. Don't follow what's written in the doc where you are given a prefix to insert, especially if it's in uppercase. Make use of lowercase.
The Codeigniter User Guide for helpers describes that helpers are available to controllers and views only. It does not explicitly mention that helper functions work in models.
CodeIgniter does not load Helper Files
by default, so the first step in using
a Helper is to load it. Once loaded,
it becomes globally available in your
controller and views.
Linux is case sensitive, Windows no. So, if you are development in OS Windows, before upload your system in a Linux hosting foe example, you need have the names of the files in lowcase.
For example:
In Windows: application/helpers/MY_functions_helpers.php
In Linux: application/helpers/my_functions_helpers.php
mmm, i'm not sure it will work for helpers, but have you tried to load the helper in this way?
$CI = & get_instance();
$CI->load->helper('string');
I faced a similar kind of situation. My development environment was WINDOWS and it worked fine as described in the DOCs i.e. MY_string_helper.php
On the production environment of UNIX, it gave error:
Unable to load the requested file: helpers/my_form_helper.php
Changing the file name to lower case resolved this error BUT the helper was not actually loaded.
After a lot of time waste, by hit and trail it worked [ it is un-documented ]
In the autoload.php, just include the mention the extended helper before the default helper:
$autoload['helper'] = array('my_string', 'string');
Also, the prefix has to capital, it did not work with lower case prefix:
$config['subclass_prefix'] = 'MY_';
you just have to change your helper function name with your prefix like found in application/config/config.php
after helper renamed make sure it contains small letters only
then change autoload file with the function name that you renamed,
main problem because of OS like your Hosting server is linux and you develope with windows so this problem rise

Missing Helper file error in cake php on shared hosting

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

Categories