Welcome Guest, Not a member yet? Register   Sign In
Multiple controllers per page + Multiple instances of the same model
#13

(This post was last modified: 07-22-2016, 03:01 PM by Call-Me-Captain.)

(07-22-2016, 11:00 AM)PaulD Wrote: It is! Welcome to CI
Thanks!

(07-22-2016, 11:00 AM)PaulD Wrote: Excellent plan! But do the tutorials first, a lot will become very clear.
Yeah, I've read a lot on the user guide. Mostly because I did jump right in and needed clarification, but, hey, "trial by error" can be seen as an established learning concept Tongue

(07-22-2016, 11:00 AM)PaulD Wrote: You don't normally but you can. The controller can call libraries. So you would call your user_library to do users authorisations etc. A controller would normally call many libraries.
I've actually solved this by using the HMVC extension (As suggested by InsiteFX) and creating my own controller for user related stuff. I figured that the only data I need to know on pages and page parts that aren't directly user-related is the logged in user's ID, so this has been working fine for me for now. Was it a bad way of doing things? Because whereever I go, people are talking about using your own library, and not a controller. After being done with my user system, though, I don't see the benefits of the former, since it's also going a little bit against the MVC concept, or isn't it?

(07-22-2016, 11:00 AM)PaulD Wrote: A CI model is normally used to deal with the database. So if I want a user details in the controller I would call my user_library with the method get_user_details and it would do whatever logic is needed, then call the user_model that would interogate the database and return the requested data. This means that should I change my database structure I need only change the user_model, and all calls to it will still work fine.
Yeah, I'm using the models like that now. It still seems a little weird to me though, haha (I mean, CI is so flexible that I could even do it the way I'm used to do it, but I chose to do it the CI way, since good practice usually means good results, too)

Quote:Tons of ways to approach this. The easiest is to construct the page with several views. So load->view(header), then sidebar, then page_content, then footer, as many views as you need to construct your page.
Alternatively, you can create your own theme_library and call that to construct your page. Alternatively you can use an integration of a template engine like Twig, which is relatively easy to integrate, or use an existing integration library you can google for.
Well, that question was mostly for situations where I'd need to include the same view multiple times depending on a for loop in another view. But after looking around a little bit I realized that I can actually do $this->load->view inside of another view. (While writing this I'm suddenly not so sure anymore, but, eh, I'll just try once I get to that point.)


Quote:Only use Ajax if it improves the user experience. You can use multiple different methods in a single Ajax_controller, or you can create seperate controllers for each ajax call, that is up to you. I usually have one Ajax controller for each page or page-group, but sometimes have done it with an seperate controller for users, one for posts etc. Although I do like to group page functions into one controller. I only seperate out the Ajax to a seperate controller so I can set the route as CSRF free in the config file.
Responsiveness is something I associate with screen size manipulations, but that is an HTML and media-query css issue.
My bad, I always seems to use the term 'responsiveness' when I actually mean, uhm, "dynamism" or something. Basically, the whole "No need to refresh that page pal, I got your back" part. AJAX.
May I ask what benefits there are to creating a new controller per page for AJAX, as to creating another set of actions in the same controller? Right now, I'm even using the same action for the AJAX and non-AJAX version, delivering a different output depending on an argument. Obviously, I have no clue what can be considered good practice and should be used.
The thing is, that I do not want to force the AJAX on the user, meaning that the site should still work fine even when the user doesn't have javascript. (So instead of a login popup, or some data-list dynamic refresh, the whole site refreshes/changes URL.)

Quote:Your welcome. I would suggest that many of these questions would be best answered by getting a domain, getting CI up and running and having a play. I would not plough into a serious build of something too soon, but work towards it maybe. From experience, you will probably have to rebuild a few times anyway as your plans for the site change and mature. By keeping your code with good seperation using librariies and models, you should be able to re-use lots of stuff even if your plans change.

Good luck,

Paul.
Well, I am kind of using my "serious build" to learn everything, so maybe I'll kill two birds with one stone - Let's hope, haha.
And thank you very much! (edit: huh, where did your post go?)



@mwhitney
Okay then, thank you very much! I guess I'll just define my "base functionality" in the MY_ core controller, and extend it with my real controllers - One of them therefore containing close to no code. Right Big Grin?
Reply


Messages In This Thread
RE: Multiple controllers per page + Multiple instances of the same model - by Call-Me-Captain - 07-22-2016, 02:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB