Welcome Guest, Not a member yet? Register   Sign In
Sending data from one view to another and extending controller.
#1

[eluser]Unknown[/eluser]
Hey guys,

Just started with CodeIgniter (first MCV) and need some info about sending data to view.

I've got controller which send data from database to view and that works fine.

After that I'm using foreach statement to get access to objects properties. No problem with that as well.

Current view:
Code:
<?php foreach ($data as $item) : ?>
<p>&lt;?=$item->id; ?&gt;</p>
&lt;?php endforeach; ?&gt;

But then I want to load another view from that current view and use one of properties in it to generate a link.

Current View:
Code:
&lt;?php foreach ($data as $item) : ?&gt;
&lt;?php $this->load->view('anotherView');
&lt;?php endforeach; ?&gt;

Another View:
Code:
&lt;?=anchor("controller/method/$item->id"); ?&gt;

Unfortunately it dosn't work Sad

What I figurout till know is that in Another View I can access only data originally sent to Current View by controller. So - I can print_r $data array but can't use properties of $item.

I even tried to pass properties in array to Another view.

Current View:
Code:
&lt;?php foreach ($data as $item) : ?&gt;
&lt;?php $newData = array('id' => $item->id); >
&lt;?php $this->load->view('anotherView', $newData); ?&gt;
&lt;?php endforeach; ?&gt;

Another View:
Code:
&lt;?php echo $id; ?&gt;

...but it didn't work as well.

So how does it work?

1. Is it controller responsible for translating array into variables?
2. Are variables inherited from view to view? And only those inherited can be used?
3. Doesn't load->view work like including? Meaning - code isn't just pasted into view?

Was trying to find some info about that but I'm probably to exhausted by now to come up with good google query.

And second question: What is the best way to implement method in all my controllers? Extend Ci_controller?

Sorry if those are dummy question but I'm still new to OOP and MVC. Oh... and I know my english isn't perfect Smile Sorry for that as well.

And thanks for all your help.




Theme © iAndrew 2016 - Forum software by © MyBB