• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
No Controller Call In Controller Anymore

#1
Hi there,

I would like to make feature request to the thread named 'No Controller Call In Controller Anymore'.

I have created this for CodeIgnitor 3 and it would be nice to have it in the new version CI 4.

This is just an idea of how it's done :
Code:
Get the first registered numeric key

Separate it to segments -> path to class folder,file class,class method,method numeric data,other data
                
http://your-cool-server.com/path/to/folder-class/YourClass/YourMethod/MethodNumericData
                
//Simple Examples :
                            
http://your-cool-server.com/FrontEnd/YourClass/YourMethod/MethodNumericData
http://your-cool-server.com/BackEnd/YourClass/YourMethod/MethodNumericData
                            
http://your-cool-server.com/FrontEnd/User/Register
http://your-cool-server.com/BackEnd/User/ShowProfile/365
                            
http://your-cool-server.com/Web/User/Login
http://your-cool-server.com/Web/User/ShowProfile/365
http://your-cool-server.com/Web/Content/Page/657
                
//More complicated Examples :
http://your-cool-server.com/FrontEnd/Web/User/Login
http://your-cool-server.com/BackEnd/User/ShowProfile/365

//Note : ShowProfile is the class method and 365 is the Profile_ID
http://your-cool-server.com/Public/Web/User/ShowProfile/365/OtherData/ID/248
http://your-cool-server.com/Public/Web/User/ShowProfile/365/Content/Page/1
http://your-cool-server.com/Public/Web/User/ShowProfile/365/Content/Page/657
                            
//If you try to have url like this :
http://your-cool-server.com/BackEnd/User/ShowProfile/UserName
http://your-cool-server.com/BackEnd/User/ShowProfile/MichaelJakson
this is not going to be working because it is based on ID

You can have look in my code :
Click here to see : "No Controller Call In Controller Anymore"
I know it's not maybe the ideal way of creating what i have done,because it's not actually accepting the id yet.

It actually still need some tweeking,which i will do soon or later.

Well and why i actually created this tweak ?

1. I've seen many people over the internet try to do it ...than they got's some issue with session.php or other issues,even i've got that issue when i was trying for example to have nice url when called controller in controller.Which CodeIgnitor is not designed for.

2. It is good to have a structure of the controllers to keep them more organised instead of have too many in one folder.

Incease if i forgot something i'll write it later.
I was writing this in rush.
Reply

#2
Just to let you know that now classs "My_Router" it's working as it should.
It would be great if you intergrate this to the "CI_Router" core.

So how it's working? Lets start with the base.
Default old settings :

controllers->Welcome.php

default url :
PROTOCOL://your-site.extension/
PROTOCOL://your-site.extension/Welcome
PROTOCOL://your-site.extension/Welcome/index

Default new settings :
after applying the code to the core it will automaticly redirect internet browser to the default_controller and it's default method.
So if user enter : PROTOCOL://your-site.extension/
it will directly become :
PROTOCOL://your-site.extension/Welcome/Index

and that's not all.

The other thing is when developer of the app want to have controllers organised like so :

Lets just for now pretend that we are now creating a structure of the controllers and developing new application.

Simple view :
The developer change a setting in the default_controller to class "Web".
that means the url will look like this :
PROTOCOL://your-site.extension/Web/Index

Next thing is that the developer want to act with user login for example which can be done this way :
the developer don't have to create any method called "User" where it will usualy operate with the user action.
Instead of that developer can create same named folder "Web" as the main class and create "User" class inside the folder with method "Login".

now we have : controllers->Web->User.php
and url :
PROTOCOL://your-site.extension/Web/User/Login
PROTOCOL://your-site.extension/Web/User/Logout
PROTOCOL://your-site.extension/Web/User/ResetPassword


Now the developer want to have a profile for user with option to view,delete or edit profile.
It can be done the same way as above.
All the methods can accept the id of the profile (by ID i mean some number).

example :
Create folder with the subclass name "User" and a new class inside with the name Profile.
so we have : controllers->Web->User->Profile.php
and url :
PROTOCOL://your-site.extension/Web/User/Profile/View/1
PROTOCOL://your-site.extension/Web/User/Profile/Edit/1
PROTOCOL://your-site.extension/Web/User/Profile/Delete/1

This feature will sort out :
1. Developer don't have to use too much settings in route to re-route and to have nice and simple url.
2. Keep controllers more organised and to have less code in each controller.
3. Developer can always continue use CodeIgniter the usuall way.
4. When intergrated,Developer don't need to write another file "My_Route.php".

Thanks for reading and I hope this feature will be in CI 4
PS; Don't hesitate to contact me if anyone will need answers.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.