Welcome Guest, Not a member yet? Register   Sign In
How to send model return data and some single variable information to view page from controller function
#1

[eluser]mi6crazyheart[/eluser]
Hey guys,
I'm using CI from last 2 months in one of project. So , don't having so much sound knowledge about CI. But, can say gradually learning a lot. Right now I've stuck with a problem & really can't understand how to solve it.

Actually, I've a controller function. Here are codes of the controller function...
Code:
function membermanage($DboardID,$UserID)
    {
        $this->load->model('board/dboard_members_model');
        $data['query1'] = $this->dboard_members_model->extract_basic_member_info($UserID);
        
        $data1 = array(
               'ID1' => $DboardID,
               'ID2' => $UserID              
              );
              
        $this->load->view('board/manage_members_view',$data);
    }

Here in the controller , i'm extracting some info from a MODEL and sending those info to a VIEW page. I've successfully manage to do this. But, when i'm trying to send a another array (at here in controller: $data1) i can't getting any way..... for , how to send that $data1 with $data to the view page & access $data1 info in view page. Whether, i've to do some like this [ $this->load->view('board/manage_members_view',$data,$data1) ] or some else, i can't understand.

Plz, if any body have any idea reply me soon. I Google a lot about on this issue but didn't get any satisfactory information.
#2

[eluser]Ben Edmunds[/eluser]
Simply add your $data1 to your $data array:

Code:
function membermanage($DboardID,$UserID)
    {
        $this->load->model('board/dboard_members_model');
        $data['query1'] = $this->dboard_members_model->extract_basic_member_info($UserID);
        
        $data['data1'] = array(
               'ID1' => $DboardID,
               'ID2' => $UserID              
              );
              
        $this->load->view('board/manage_members_view',$data);
    }

Then you will have whatever your query returns and data1 accessible from your view.

I have to point out though that your naming conventions are very bad and will become a big issue as your application grows.

For example, I would have the member_info() method also return the ID's and then the controller would look something like this:

Code:
function member_manage($dboardId,$userId)
    {
        $this->load->model('board/dboard_members_model');

        $data['dboardId'] = $dboardId;

        $data['members'] = $this->dboard_members_model->extract_basic_member_info($userId);
        
              
        $this->load->view('board/manage_members_view',$data);
    }

Have fun,
#3

[eluser]mi6crazyheart[/eluser]
Thanks a lot Ben for u'r quick reply. By d way, about that naming conventions..... Ya, i know my naming conventions is really getting wild. There is proverb u might have heard that... "Little Knowledge is very dangerous" . This d thing which has happened with me. From the beginning i couldn't able to take proper care of my naming conventions. Actually, i never used CI before this. So, i generally habituated with some different kind of naming conventions. But, as CI has it's some times it's own way of naming different files(Ex:Controller file...First letter should Capital) when i started use CI, i needed to change my style of naming files.

So, I just couldn't able to choose the sweet-able way naming files & this is the result of it. Any way, thx again for u'r quick help. Hence forward, i'll take care of these naming conventions of files.




Theme © iAndrew 2016 - Forum software by © MyBB