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.
Related
I created Custom ReadRequest Class. Than I created folder with "Order" name in Requests folder, and put there my ReadRequest.php file:
After this manipulation Laravel doesn't see this file in my Controller:
How can I fix that?
You haven't written how you know that Laravel doesn't see this file but looking at your screen it seems your IDE doesn't see it it either. So make sure in your ReadRequest.php file you have
<?php
namespace App\Http\Requests\Order;
class ReadRequest
{
// ...
}
It's very possible that you have invalid classname in this file or invalid namespace, so your IDE shows you the error and also composer cannot load the file.
Might be somehow copy of this thread but the choosen answer is not giving me a resolution.
I have copied site built on codeigniter to localhost from server and I get this error message. I have checked the case (altough Windows is non-case-sensitive) in the files and I am using MY_Controller as classname, filename and including file as well, made screenshots, see images:
1. Extending MY_Controller
File structure
MY_Controller class header
The file is in the core folder, but I still get this error message.
What am I doing wrong and what could be the solution?
In the index.php file in the root folder of the site check that the $system_path and $application_folder variables are correct. For example, I keep mine outside of the publicly accessible path, at the same folder depth as my public_html and so these for me are set as:
$system_path = '../system';
$application_folder = '../application';
If you've copied it from a web server then it's possible that something similar has been setup or perhaps an absolute path has been specified.
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.
I have public folder in root of my project. Placed a couple of images, when I try to access them, it says "Sinatra doesn't know this ditty..."
Isn't default public folder supposed to be called "public"? Or do I have to explicitly set that?
Need to not include /public in path.
The folder name should be "public" and then access it with /image.png when your folder structure is public/image.png
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';