How to create a controller outside application folder in Codeigniter - codeigniter

I have created a controller in a file which is outside application folder. But it throws error Fatal error: Class 'CI_Controller' not found. Can anybody tell me how to do this?

You don't. It either is part of your application or it isn't. Can't have it both ways (not to say it would be impossible to connect, just that why would you?)
If it is a file that looks and works exactly like a controller then why on earth would you take it outside? If you re-route your index.php, then calling your controller's function yoursite.com/controller/function is the same as calling a file that was outside application folder. Suppose you had a folder on root called "controller" and a folder inside it called "function" and an index.php inside of it. You'd call both of them exactly same!
Bottom line: its ok to have 3rd party files outside of application folder, but to have a controller as-is outside of its place simply makes no sense, whatsoever.

Related

Dojo File Caching in Worklight

When using Dojo file caching with Worklight receiving a 404 Error when running in Simulator. It appears the file being loaded is not being copied from the common area to the device. Is there something else I need to define in my project to make that happen? There must be a convention and I wanted to follow it going forward as I expect to have more template files in the project.
My define statement in a .js file:
define(["dojo/_base/lang", "dijit/layout/ContentPane", "dojo/dom", "dojo/text!./templates/Order.html"], function(lang, ContentPane, dom, template){
...
var cp1 = new ContentPane({
title:"Order",
content: lang.replace(template, someJson)
}).placeAt("temp");
My folder structure:
In the common/js directory I have the above code in a .js file and I have a templates folder to keep the Order.html and I would expect to have other template files stored there in the future.
Error on the console:
GET http://localhost:10080/DojoProject/apps/services/preview/DojoApp/windowsphone8/1.0/default/layers/templates/Order.html 404 (Not Found)
It seems that the way you are specifying the path, browser tries to find the file in the "layers" folder which is sibling to "templates".
Have you tried to modify the "dojo/text!./templates/Order.html" to something like: "dojo/text!./../templates/Order.html" to navigate one level up, then go into the templates folder?
I'm not sure this will work, but I think it worths a try.

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';

file/page not found when uploaded online

I am working on a new module of existing live project. It is a website developed in PHP Zend Framework. New module is on admin side. It runs properly on my localhost/virtualhost.
When I uploaded it online with correct directory path it is found that one file is not found.
It is called like
www.example.com/admin/controllerName/actionName
All the actions works except one action that doesn't display anything and returns exception error mentioning that page or file not found.
What could be the issue? I have checked folders. If one action for the same controller works than why doesn't other. Both have their .phtml files in View section.
Help would be appreciated.
Would I be right if I guessed your local development environment was Windows?
It's probably a filename case sensitivity issue.
Assuming your request looks like
www.example.com/admin/fusionmaps/newpage
I'm not sure how you've setup your modules but if it's reasonably standard, you should have something like this (note the upper and lowercase characters)
application/modules/admin/controllers/FusionmapsController.php
The controller classname should be Admin_FusionmapsController with action public function newpageAction()
The view script should be at
application/modules/admin/views/scripts/fusionmaps/newpage.phtml

Codeigniter controller in subfolder extends outside one

Is it possible a controller inside a subfolder, lets call it 'category', extends from a controller from the parent folder?
Example:
application_controller.php in the controller folder
category in the folder controller/category
It keeps me showing the error
require_once(../application_controller.php) [function.require-once]: failed to open stream: No such file or directory
Is there some trick i'm missing to do that?
Thanks in advance
Elkas
You're technically executing in a wierd scope because of how the controllers are loaded up.
require_once(APPPATH.'controllers/application_controller.php');
This is what you're looking for.
APPPATH will always point to your application/ folder.

Referencing script files from MVC

I am having problems referencing scripts that should be included in my view, when I access the page using a different route my scripts fail.
The idea is that two routes actually point to the same action:
http://localhost/PaydayWebsite/registration
http://localhost/PaydayWebsite/organizations/p001/departments/vest/employees/chn/registration
where the second just include more params for my action. I have tried using
ResolveUrl, Url.Content and mvccontribs Html.ScriptInclude but neither seem to work. Any ideas?
You should be able to use Url.Content, but you'll need to make your path relative to the root of the application rather than the current path.
Use
Url.Content( "~/Content/Scripts/jquery-1.3.2.min.js" )
rather than
Url.Content( "../../Content/Scripts/jquery-1.3.2.min.js" )

Resources