controllers inside subfolder gives blank page - codeigniter

im having a small web app developed using Codeigniter and in my controller folder i have a separate folder which has the controllers related to the admin.
for an example when i try to access my site http://example.com/panel/index.php?/admin/dashboard/home i get a blank page. It happens with all the controllers inside the subfolder.
It works on my localhost but when i upload it to my hosting on Godaddy all i get is a blank page. No errors nothing.
Below is my folder structure
controller
----- admin
----------Login.php
----------Dashboard.php
----------Settings.php
------ user
----------Login.php
----------Dashboard.php
----------Settings.php
Can someone tell me what might be causing this?

The issue it with controller name
http://example.com/panel/index.php?/admin/Dashboard/home
Changed filenaming convention (class file names now must be Ucfirst and
everything else in lowercase).
So you controllers and files name should be
My_controller (only M upper case rest lower case)

Related

Codeigniter - dots in a controller folder name

I'm using the latest version of Codeigniter and I try to achieve specific controller folders structure.
I'm would like to create a controller folder for each of my webapp version:
/controllers/1.0.0/login (where login is the name of the controller)
/controllers/2.0.0/login (where login is the name of the controller)
the problem: it seems Codeigniter working great with controller folders but not working with controller folders that contain dot :(
Like this working good (without dots):
/controllers/100/login (where login is the name of the controller)
/controllers/200/login (where login is the name of the controller)
Is there a way to make Codeigniter work with dots on controller folders?
Thanks
Shai
I also getting the same issue.
You can use like this in your route
config/route.php
$route['Controller/1.0.0/login'] = 'Controller/100/login';
$route['Controller/2.0.0/login'] = 'Controller/200/login';
This is working fine for me

Laravel - how to protect /public/files/uploads/ from web acces by customers

I've got a question.
the admin and employee can upload stuff into /public/files/uploads/
and the customers are only allowed to see a part of the files in uploads.
but when I login as customer and visit: /public/files/uploads/
I can open and view every file.
I would like to know how to protect this from customers, like when they try to open /public/files/uploads/ they redirect back to the home view.
This would need some sort of .htaccess but I can't seem to figure out how to get it working.
Any help would be appreciated.
Thanks in advance.
Try to put an empty index.html file in this folder.
Also, are your normal URLs contain public? If so, you have wrong web server configuration and you should point your web server (Apache, Nginx) to a public directory instead of Laravel project's root folder.

What is the maximum layer of subdirectory at codeigniter controllers

I have a a project(codeigniter) where file directory is like that.
mysite
application
config
controllers
super_admin
admin.php
tasks
setup
bank.php
assets.php
Now if I try to access
http://localhost/mysite/tasks/seutp/bank
It calls codeigniter 404 page
But I can access
http://localhost/mysite/tasks/assets
Actually I can get access any controller under controllers and controllers/tasks folder.
But I cannot get access under controllers/tasks/setup folder
My question is
Is there any limitation of sub-directory at codeigniter?
If Yes: Is there any way to solve the limitation and How?
If No: Why I cannot access the third layer sub-directory controllers?Did I do something wrong?
yes there is a default for the ci controllers file folder levels. i am using this solution:
https://degreesofzero.com/article/controllers-in-sub-sub-folders-in-codeigniter.html
the author includes a lengthy mod rewrite but if you already have a working htaccess rewrite file to eliminate index.php from the url then it will probably work as is.

Creating an admin section controllers and views in Code Igniter 2.0

I have created my site with controllers such as about, products etc... which gives me example.com/about/ etc..
How would I create a admin section with the same controller name, like example.com/admin/about or example.com/admin/products ?
How do I organize my controllers?
2 more options to compliment WebweaverD answer.
Use Modular Separation
Create a second application folder and index file, that will be responsible for admin, connect them to the same system folder.
The second option is really easy to manage once you have set it up. There are variations but I find the structure below to be the most convenient.
mykewlwebsite.com
apps/
frontend/
app/ frontend codeigniter application folder
public/
index.php
assets/ frontend js, css, images
backend
app/ backend codeigniter application folder
public/
index.php
assets/ backend js, css, images
config/
database.php
constants.php
system/ codeigniter system folder
The database.php file contains the code from CodeIgniter's config/database.php and is shared for all applications of your project - simply remove all code and add require_once('../../../../config/database.php'); to the config/database.php
index.php files inside public folders have two important variables $system_path and $application_folder, change them to
$system_path = '../../../system/codeigniter';
$application_folder = '../app';
constants.php file can have some constants like the ENVIRONMENT constant from the index.php files and some other. Just require_once() it from the index.php files.
Though there are pros and cons.
PROS
For those of you, who are developing on localhost and deploying to servers via FTP or other systems can simply upload one folder - apps and overwrite the target folder without fear of overwriting database.php settings (I'm sure most of you have them different from the local ones).
Adding one more application is easy - just duplicate one of existing. You can add as many applications as you want - api, ajax, user cabinet, etc.
CONS
This structure is meant to be used if you have a domain as mykewlwebsite.com and have the ability to add sub-domains to it, so you just configure the home folders for each of them:
mykewlwebsite.com: path/to/mykewlwebsite.com/apps/frontend/public/
admin.mykewlwebsite.com: path/to/mykewlwebsite.com/apps/backend/public/
api.mykewlwebsite.com: path/to/mykewlwebsite.com/apps/api/public/
You have a few options here:
1) CREATE A SUBFOLDER - Put them in a folder called admin within the controllers directory (in application/contollers/admin/products.php)
A word of warning here is that you can only go one folder deep or codeigniter gets upset. Also, it will use first level controller/methods first so be careful of naming conflicts - e.g if you have an admin controller with a products method in it, that will get called before it looks in the admin directory for a products controller. (when going to example.com/admin/products)
2) USE THE ROUTES FILE - If it is just the urls you are worried about you could just call the controllers whatever you want and use the application/config/routes to redirect those paths to the controllers you want like this:
controller name: admin_products.php
routes file:
$route['admin/products'] = "admin_products";
3) USE A MASTER CONTROLLER FOR ALL - Final option would be to have a single admin controller and use named methods inside it, so for example you have admin.php controller with a products method within it this would then be called by admin/products uri (this will probably get messy though in a big application/site - not recommended)
Hope I have explained this OK for you, if you need any clarification please ask and I will try to elaborate.

why my IgnoreRoute does not work?

I want to prevent users access for my "~/Content/..." folder I wrote it as follow in "Global.asax.cs" and put this line of code at the top of every other routes
routes.IgnoreRoute("Content/{*pathInfo}");
but it does not work. in fact user can see every files in content folder by type the URL in browser.
am I missing something?
How did you figure out that it does not work? Give example.
You may have put it last in the Routing table. So try to move it up so that it gets added to the routing table first. The route collection is an ordered list of routes.
Also try this : Routes.IgnoreRoute("Content/");, but your version of ignore is also correct and it should work.
Lastly, I do not know what you mean when you say the user can see all the contents of the Content folder : Isn't that the point? User must be able to download files from the folder, and we usually just need MVC to ignore the requests from coming into the framework, and so that IIS can directly serve those files.
or did you mean Directory browsing is enabled, and you want to disable that : In that case go to IIS manager, and select your website and look for the Directory browsing option and disable it as shown here.
Your problem cannot be solved by routing constraints. There are 3 significant steps in processing request:
IIS got request.
IIS watch at filesystem and search for direct correspondence to file
If IIS didn't found any file - it gives request to ASP.NET MVC for processing.
So, you need to configure folder security to forbidden direct access to files, but allow access to application, as here.
But I don't recommend to secure folder, that should be shared. I don't believe that your site shouldn't have images to display :) If you have some secured content, you need to create another folder.

Resources