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
Related
i'm new on CodeIgniter and i try to install Aauth. But the installation Guide is not so clear.
I put the application/libraries/Aauth.php in libraries, application/config/aauth.php in config and application/controller/example.php in controller.
Next I import the sql file in phpmyadmin (with aauth for DB name). After that i put the halpers in helper folder even if it's not mentionned. Same for languages.
And then
You must set up database connections from
application/config/database.php
I tried database' => 'aauth'.
You can also make some changes on application/config/aauth.php"
I don't know what to do? I have never used a framework before.
I created a controller and put $this->load->library("Aauth"); in __construct, and did the tutorial.
Problems are:
Fatal error: Call to undefined method Aauth::deny()
If i dont use the deny function, there is no error but when i look in the DB I only have legolas and no frodo or gandalf. But all perms and groups are there.
If I give "immortality to hobbits", it still say that hobbits do not "immortality".
I work with Xampp and Codeigniter 3 on Windows 10.
You do not have to change anything in your database config file. Just make sure db_profile in the Aauth config matches the name of the database active_group.
As for the Aauth config, for CI3, change use_cookies to false.
To load the library, change the name to lowercase, $this->load->library("aauth");
I've created a custom banner module for Magento and I've tested it locally on my Vagrant/VirtualBox setup running an instance of precise32 and everything is working great.
When I pulled the code from GitHub on to a staging server the extension is not working and I'm getting the following error:
PHP Fatal error: Call to a member function getCollection() on a non-object in /var/colourbox/app/code/local/AffinityCloud/ACBanners/Block/Slider.php on line 7, referer: http://colourbox.affinitycloud.co.uk/tub-storage.html
This is while viewing the home page, so I'm not sure why it's referencing http://colourbox.affinitycloud.co.uk/tub-storage.html as the referer as this is a category page.
I've cleared the cache (is disabled anyway) and reindexed. Stil no joy. I've also tried to rename the model classes using lowercase characters and the first character uppercase with no result.
I've added the module code to GitHub below so you can see the code:
https://github.com/garethdaine/acbanners
Any ideas why this would be working locally and not on the staging server? It's as if it can't find the model classes but has no problem fining the Slider.php class.
I'm at a loss as to what to do here.
NOTE: For brevity, I would like to add that I have logged out and back in to the admin, while also deleting the module tables and the reference in core_resource to no avail. It creates the tables fine but I still get the same issues and the module is showing as enabled in the advanced config.
The problem is case sensitivity.
On windows systems the file names are not case sensitive. On Unix they are case sensitive.
So in the ways you configured the module and named the files, when calling Mage::getModel('acbanners/acbanners') the magento autoloader looks for the file
AffinityCloud/ACBanners/Model/Acbanners.php But the real name of your file is AffinityCloud/ACBanners/Model/ACBanners.php
So the file is not found and the class is not loaded and Mage::getModel(...) returns null.
You have 2 options here.
The cleanest and fastest. rename all your classes in the Model folder to start with a capital letter and the rest should be lowercase. Acbanners.php in the example above. You may need to do the same for the files in Block and Helper.
The long version. If you want to keep the file names you need to change Mage::getModel('acbanners/acbanners') to Mage::getModel('acbanners/aCBanners') or Mage::getModel('acbanners/ACBanners'). but I guess this will take a lot of refactoring. You may also need this for blocks and helpers also.
I have a strange error with CodeIgniter using HMVC extension. On localhost it runs fine and on a Linux server I get this error Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid. even tho everything is configured fine. I have done some core CodeIgniter debugging and found that fetch_directory() base method is returning
../modules/{controller}/{action} instead of modules/{controller}/{action}
Anyone else had this problem? what is the solution to fix this ?
I had this identical problem, also using HMVC architecture. Here is my solution for the benefit of others.
In my case, it turned out to be the fact that I had removed the /application/controllers/ directory. Because this directory is always empty, being replaced by the controllers in the individual modules, I (wrongly) thought it would be fine to 'tidy it up'.
Actually, the MX routing references it in the path it creates for the router to find the modules;
APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php'
So the ../ part is correct. I suspect your local environment is Windows (like mine) which managed to work around this broken path somehow, in a way that Linux is unable to.
So the simple fix for this scenario is... put the /application/controllers/ directory back.
It could be several things:
) Check your config file and see what the config['base_url'] is set to, it could be a mismatch between your development environment (e.g. "localhost") and your production environment (e.g. "http://www.example.com")
) Double check your routes.php file and make sure that the default page controller is set to the controller. Then triple check to make sure the spellings match!
I had the same problem and change $this->class and $this->method to $class and $method respectively in set_class and set_method function in My_Router class like,
public function set_class($class) {
$this->class = str_replace('-', '_',$class).$this->config->item('controller_suffix');
//---^ remove $this from here
}
public function set_method($method) {
$this->method = str_replace('-', '_',$method);
//---^ remove $this from here
}
I too solved with charliefortune's answer. Thanks.
Be aware that if you recreate from .rar or upload to certain servers, empty folders might be deleted. Therefore, you should maybe add some files to the "controllers" folder.
On my WAMP box, I did the following:
Added a file called /application/libraries/Foo.php
Foo.php is a class, and it's name is Foo
In /application/config/autoload.php, I added $autoload['libraries'] = array('foo');
Everything works fine. When I upload to my LAMP box, I get the following error:
Unable to load the requested class: foo
Permission of /application/libraries/Foo.php is 0755. Owner is the same as the rest of the CI files. Taking foo out from autoload makes the problem go away.
Any ideas what might be wrong?
In Windows, capitalization in paths doesn't matter. In Linux it does.
When you autoload, use "Foo" not "foo".
I believe that will do the trick.
I think it works when you take it out of autoloading because codeigniter is smart enough to figure out the capitalization in the path and classes are case independent in php.
I had a similar issue when deploying from OSx on my local to my Linux live site.
It ran fine on OSx, but on Linux I was getting:
An Error Was Encountered
Unable to load the requested class: Ckeditor
The problem was that Linux paths are apparently case-sensitive so I had to rename my library files from "ckeditor.php" to "CKEditor.php".
I also changed my load call to match the capitalization:
$this->load->library('CKEditor');
If you're using a linux server for your application then it is necessary to use lowercase file name and class name to avoid this issue.
Ex.
Filename: csvsample.php
class csvsample {
}
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.