Welcome Guest, Not a member yet? Register   Sign In
Access controller in side another controller
#1

Hi

i want to access controller inside another controller
same as given in below link
http://www.techsirius.com/2013/01/load-c...other.html
its works in ci2.2

but in ci 3
when i do the above code in CI 3 mention in url page gives error

Unable to locate the specified class: Session.php

I want to access controller using uri and same controller as a object in another controller.

Thanks.
Reply
#2

Best to just create a library, and then use it in as many controllers as you want. CI was never meant to do "controller within controller". There are hacks, yes. HMVC allows this, which is an addon to CI, but I like to stick to as close of native CI as I can.
Reply
#3

Or you can use this replacement for the Session driver:

https://github.com/cgarciagl/CI3-Native--Session
Reply
#4

(05-23-2015, 10:29 AM)cgarciagl Wrote: Or you can use this replacement for the Session driver:

https://github.com/cgarciagl/CI3-Native--Session

... or not, because it's not related to the problem at all.
Please don't self-promote your library everywhere that you see the word 'Session'.
Reply
#5

(05-23-2015, 11:38 AM)Narf Wrote:
(05-23-2015, 10:29 AM)cgarciagl Wrote: Or you can use this replacement for the Session driver:

https://github.com/cgarciagl/CI3-Native--Session

... or not, because it's not related to the problem at all.
Please don't self-promote your library everywhere that you see the word 'Session'.

Of course it is related to... i had this very same problem of using a controller within a controller with CodeIgniter3 using sessions; and the only way of make it work was with this library... because the session driver fails in this case, so i had to substitute it with this library. 


And i'm not self promoting anything, just sharing a solution in two questions about the same subject: try to use a controller inside a controller in CodeIgniter 3; not as you say: wherever the Session word appears.
Reply
#6

Well, CodeIgniter doesn't support "controller inside another controller" in the first place. So the problem is, you use an unofficial, third-party hack to achieve that and chances are - that hack is designed for CI2, while you're trying to use it with version 3.

This library that you're sharing is not the solution, it is only hiding the problem that you create for yourself by doing things wrong. That is, in addition to the fact that "controller inside another controller" and "session" being mentioned in one place doesn't necessarily mean it's the same issue you had, hence my previous comment.
Reply
#7

Besides, WireDesignz HMVC (and possibly others) manages to permit you to call a controller from within a controller without modifying the session library. It isn't an issue with the session library which causes the error, it's the fact that the CI_Controller is intended to be a singleton and loading it (or extensions of it) multiple times in the same application is problematic.
Reply
#8

You were absolutely right!!, my mistake... the library of Session wasn't the problem as you said... i'd redesigned my classes and take some ideas from WireDesignz HMVC... now all works perfect in CI2 and CI3

Thank you for the advises Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB