Welcome Guest, Not a member yet? Register   Sign In
Can't understand basic concepts - probably just as thick as mince.
#1

[eluser]MountainMan[/eluser]
Please forgive me, I am a total newbie to web development, I'm old and it's difficult to teach an old dog new tricks! :-) I was brought up on BASIC on the old chicklet keyboard Commodore Pet, for those of you old enough to remember that classic!

To my point:

I understand CI and the MVC concept to a certain degree.

However, I can't get my head round how CI handles site navigation using MVC.

I create a controller which pulls data from a model and passes it to a View. The controller presents the view to the user. Voila. Web page with data.

But how do I interact with the view? Or rather, how does the view feedback interaction and/or data back to the controller?

I can't even figure out how to do something as simple as clicking on links in a view for example!

I presume that you can't call views from views, since everything should route through the controller, so somehow you must be able to feed back to the controller which link was pressed and then allow the controller to call the relevant view?

How do you get a menu system to work in this system?

Any help would be much appreciated - once I've got the concepts, I think I will be fine with this. Even though it looks like it may not be supported much more, and everyone seems to be banging on about newer frameworks, I'd like to get my head round this.

The code I've written works very nicely, but it's just simple presentation stuff from a database at the moment. I've no real idea how to do navigation.

Thanks.

JB
#2

[eluser]noideawhattotypehere[/eluser]
Well, you make a link pointing to lets say:
Code:
<a href="&lt;?=base_url()?&gt;controllername/functionname">Link</a>
then in your controller
Code:
public function functionname(){
$this->load->view('someview');
}

Controller is webapps 'brain', you tell him what to do with models/views.

You could also take a function with parameter and load diffrent views using switch case, but i just gave you the simplies possible example.
#3

[eluser]sv3tli0[/eluser]
Pretty simple :

Controllers are responding for your site URLs (when user go to any page in your site it loads a Controller / method depending on your route settings).
Inside that controller/method you decide what models/view to load, what to do and what to return to user..
#4

[eluser]MountainMan[/eluser]
Thanks folks - so it is ok to call controller functions from within a view?

In fact, would I be right in saying that that's the only way that you change the flow of a web site? (I almost said "program" there!)

How would I pass data back from a view to a controller?

Cheers

JB
#5

[eluser]Unknown[/eluser]
From what I understand you should only make calls to controllers with CI. The controllers determine what models to use and what views to present.

This page in the CI Tutorial gives a pretty clear explanation of how to call controller's methods directly from views which is what you are asking about:

http://ellislab.com/codeigniter/user-gui...ction.html

As a side note, if a function is within a class it's called a method. Otherwise, it's a function.
#6

[eluser]MountainMan[/eluser]
Thanks for all your help everyone. I've managed to crack how it works - I've managed to call back from a view into a function inside a controller with data!

Thanks again.

JB




Theme © iAndrew 2016 - Forum software by © MyBB