Welcome Guest, Not a member yet? Register   Sign In
passing data from one controller to another , help needed
#1

[eluser]johansonevR[/eluser]
hi there,
I am using one model to query a database and return results to controller. Controller passes it to view. I want to pass the field id taken from the database to different controller.I have .
cover_model -query database.
cover.php - controller, send result to view.
cover_view- output results.
Now i have a database table field 'Id' which i want to pass to
view_model so i can select the info corresponding to it from DB, send them to
view.php and output the result corresponding to the id.
I hope you understood.
I can post some code if it matters.
Bye.
#2

[eluser]Sarfaraz Momin[/eluser]
Code will definately help but I will just put down several way of doing it.

1. If the controller you want pass the id to directly linked from source controller you can add that id to its URL segment. Adding it to the URL segment will give you access to the ID in the new controller which you can then use to pull whatever data you want from the DB.

2. You can use sessions to temp store the ID and use it on the new controller and when you have used it you can reset the session variable you have created for storing the ID.

-Sarfaraz
#3

[eluser]johansonevR[/eluser]
i've tryed passing data like this
Code:
<body>
<?php foreach($select->result() as $adv):?>
<div class='row'>
<span class='anchor'>&lt;?php echo anchor('view/res/'.$adv->id,'view');?&gt;</span>
<div class='contents'>
<p><span class='title'>&lt;?php echo $adv->title;?&gt;</span> <span class='author'><br />author: &lt;?php echo $adv->created_by;?&gt;</span> <span class='date'><br />published: &lt;?php echo $adv->created;?&gt;</span></p>
</div>
</div>

&lt;?php endforeach;?&gt;
&lt;/body&gt;
and in my view.php
Code:
class View extends Controller{
    function View(){
        parent::Controller();
        $this->load->model('cover_model');
        }
    function res($id){
        echo $id;
        $data['adv']=$this->view_model->select($id);
        $this->load->view('view_view',$data);
        }
}
and it works i guess this makes this topic solved, but if you have a better ways of doing this, pls share.
#4

[eluser]adamp1[/eluser]
I would go for the session idea and specifically the flashdata option. SO while you are in the View::res method you call keep_flashdata('id'); then when your in your second controller call flashdata('id') to get the value.




Theme © iAndrew 2016 - Forum software by © MyBB