Codeigniter datamapper is not loaded upon 404 overrides - codeigniter

When a 404 override caused by nonexistent action (only action, not controller) is being handled by Codeigniter, the datamapper fails to load, thus causing any database functionality impossible.
My usage case is: I want to register data about who/when/where encountered a 404 on the site.
Version info: codeigniter 2.1.0; datamapper 1.8.2

I figured the problem is in the way datamapper "extends" the db class. The file that defines the name of the db class to use is only included once, thus when the codeigniter object is re-constructed, the name remains un-overridden. To fix this, at your own expense, you have to hack the datamapper files.
File "application/third_party/datamapper/system/DB.php" after line 143:
// load Datamappers DB interceptor class
require_once(APPPATH.'third_party/datamapper/system/DB_driver.php');
put these lines:
// HACK to make datamapper load correctly after codeigniter has been reconstructed in
// cases of invalid actions (404 overrides)
$driver = 'DM_DB_Driver';

Related

I have just deployed a codeigniter framework to my one.com domain and I get errors that I dont get on any other domain-setup I have

I have a Codeigniter framework setup that I move cross multiple domain setups as a default starting point. However when I was going to apply it for the first time to a one.com domain I got an error.
An Error Was Encountered
Unable to load the requested class: Form
So far I have tried with checking the source for this. I went into the autoload.php and first tried to change from "form" to "Form" as I found out on another site because of Linux being sensitive to capital letters, but to no use.
I then removed the form all together and then I got the same error, but from the helper "url". I removed that and it went up to libraries and started printing same error for the first in that array.
$autoload['libraries'] = array('Database', 'Session', 'User_agent', 'Upload');
$autoload['drivers'] = array('Form', 'Url');
If there is anything more I can add to shine light on this or make the question better please tell me and I will add it. I am not sure at all where the fault might lie so therefore the information is a bit pale.
You are trying to load a CI helper as a driver ! So the framework looks for a driver Form.php file, which doesn't exist (not in the standard CI installation).
| These classes are located in system/libraries/ or in your
| application/libraries/ directory, but are also placed inside their
| own subdirectory and they extend the CI_Driver_Library class
What you want to do is to load the "form" helper (and the others). A helper is loaded like: $this->load->helper('form'); or autoloaded.
CI - helper
CI - autoload
CI - driver

Laravel Auditing AuditableTransitionException Error on Morphmap on transitionTo()

I am able to successfully record changes to classes, and return what has been changed (not including many-to-many). However, I am unable to revert back any change using the built-in new transitionTo() method.
I get the following error on all classes:
Expected Auditable type App\XYZ, got XYZ instead
I have all of my morphable classes (which are all I am using for tracking audits) attached correctly within AppServiceProvider in a morphmap like so:
\Illuminate\Database\Eloquent\Relations\Relation::morphMap([
'Employee' => \App\Employee::class,
];
All classes work correctly with all other Laravel morphTo methods.
The auditable code looks like it is tripping the error in line 467 of the Auditable class:
if (!$this instanceof $audit->auditable_type) {}
It doesn't appear to be looking to the map for any of the morphed classes. Or, I could be totally missing something of course!
Any help on how to get this to work using the auditing method -- has anyone gotten this to work with standard morph classes? (It will of course revert the class manually by looping on the old fields and saving the object).
Using Laravel 5.5 and the latest version (5.0) of Laravel-Auditing.
Sent a note to the developer - this was in fact a bug. Vendor code was needed to include morphMapped objects.
Developer at Laravel Auditing responded within an hour and had a fix a few hours later. I can confirm this is now functioning as expected. Outstanding support.

Codeigniter database result instance class location and class name

I recently learned that you can provide a class name to the Query->result() and it will use that to instantiate the results, rather then using plain stdClass. more here
My first attempt was to the in application/models/classes and name them the same as the model, but without the _model suffix. So I would have a Posts_model that returns instances of Post from the database. But the problem is that I also have a Controller named Post and obviously PHP throws a Fatal Error.
So the question is: Is there is a convention as to where to put this classes and how to name them?
As far as Codeigniter goes, there are no convetions, and the built-in loader is kinda ill-suited for only including files and not instantiate them. I would recommend to integrate some psr-0 compatibile autoloader.
As of most mvc web frameworks, they usually uses the plural form for the controllers and singular for models. For example: Users is a controller and User is the modell.

CakePHP, Helper class AjaxHelper could not be found

I am trying to do this cakePHP ajax tutorial found at this site: http://poli.bonzahost.net/2010/07/17/simple-ajax-call-in-cakephp/
But it doesn't work. I made the database for it and made the table brokers with the needed fields, id, name, and last_name and added created and modified as 2 extra fields to the table. I set the settings in the database.php file to point it to my host and user and database schema with the right password and all that. I changed some things such as form->create, form->input, and ajax->submit to this->Form->create, this->form->Input and this->Ajax->submit, because I am working with CakePHP 2.1.2, not CakePHP 1.3.
But I get in my app: Helper class AjaxHelper could not be found.
Error: An Internal Error Has Occurred.,
I think the AjaxHelper.php file is missing from my download of cakePHP. I think it should be in: www\cakeAjax\app\View\Helper, but its missing from there. Is that the cause of this problem?
If so where can I find a copy of the AjaxHelper.php file, and is www\cakeAjax\app\View\Helper where I would put it? If not, how to I solve this problem?
Ajax helper is deprecated since CakePHP 1.3. You can now use the CakePHP's JsHelper for Ajax stuff.

PHPUnit + CodeIgniter multiple objects with same name

I currently test my CodeIgniter app with phpunit by using CIUnit (https://bitbucket.org/kenjis/my-ciunit). The problem is that I have multiple controllers with the same name. I have a controller in the root controller directory named "Blog" and I have a controller called "Blog" in the controller/ajax/ directory.
The reason is to seperate all ajax requests from the main controller.
When I am running tests on both files, I get the following error:
PHP Fatal error: Cannot redeclare class Blog in ...
Well, I am not suprised I am getting this error.
What are my options to resolve this?
Prefix controllers in ajax directory with "ajax" (looks only a bit stupid url/ajax/ajax_blog)
Use namespaces (I guess I need to namespace codeigniter too then)
Create 3 seperate phpunit.xml files
This aren't really solutions I am looking for. Do I have any other options? Is it somehow possible to run each testsuite seperatly, but still in one command? Can I "clean" objects between testsuites? Anything else?
There are no other options except those you mentioned, as it is impossible to "unload" class definitions in PHP.
Naming two controllers the same is not a problem when you run CI normally, since only one controller is instantiated per request, but something that should be avoided.
If it is just the ajax-url you don't like, maybe override it in a route (in config/routes.php):
$routes['ajax/blog'] = 'ajax/ajax_blog';

Resources