Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14343

Multiple controllers per page + Multiple instances of the same model

$
0
0
Hi!

I found CodeIgniter yesterday, and thought that it was quite awesome - So I'd like to jump right in and create that webapp idea I've had for a while.

Now, this post contains two (Actually, three - no, four) questions - I didn't find a real answer to those while searching on google, so I hope that I'm not just posting a duplicate of something. If I am, I'm sorry.

My first question is about controllers. Let's assume I have two - or more - functionalities on the page I'd like to present:
1. The main functionality of the page, let's take a blog as example, since this seems to be the standard example everywhere.
2. User functionality: A user can be logged in, can log in, can log out, etcetera. Maybe the corresponding buttons for that user functionality will be displayed on a sidebar.
Obviously, the main controller will be the one handling the blog part. For the sake of clarity, though, I wouldn't like to put the user functionality into the same controller. Moreover, the user functionality will probably be used everywhere accross the site, not only on pages using the blog functionality. So I think that the user functionality should be given it's own controller.
Now the problem/question: How do I handle multiple controllers for one request? There will only be one "main-controller" per page, of course, which is getting specified by the URL; but still, how do I handle that stuff?


Second question - Models. I come from a non-webdevelopment background, and good practice was to have your data stored away in models, like here - But instead of having, for example, a "Post" model with every Post in it, you would have had an array of Post models, with 1 Post per instance of the model. I'm really confused as to how this whole stuff works here!
For example, I'd really like to have only one User per User model. But, if I now want to display multiple User's information on my page, how do I handle this? What is considered best practice here?
(Goal is mostly to separate the current logged-in - or not - user from any users on the page itself. The current user would be handled by my User controller, whereas the others wouldn't be, I guess?)

Third question - Views. Before finding CodeIgniter, I was reading about Ruby on Rails. I did not decide to use it, as I'd need to learn Ruby first, but one concept that should be applied everywhere, which was heavily advertised in every RoR tutorial, was "Don't repeat yourself". So I'd like to know: How do I move out some parts of a view that are bound to be used again in another view? Let's take our almighty blog: I want to have one template for displaying a blog post. And I may have two views: One for displaying an individual blog post, and one for every blog post. How do I move out the blog-post part so that it can be used in both views?

Next one: A long time ago, when I last coded a website, I used AJAX for responsiveness. No idea how it is done nowadays, but, as you could probably guess, the question is about responsiveness. What is best practice with CodeIgniter to adapt code for dynamic/responsive stuff, without losing basic functionality in case a user doesn't have javascript or something? Basically, should I make lots of controllers or controller actions for small AJAX requests? As in "Give me the view for a blogpost-create popup only"?


Uh, I think that was all for now. Thank you very much Smile

Viewing all articles
Browse latest Browse all 14343

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>