Welcome Guest, Not a member yet? Register   Sign In
New to CI trying to get my head around it, controller problem
#1

[eluser]Unknown[/eluser]
Hi guys and girls,

I have been reading up on CI for a few days now as I need to use it in future projects for work, I have a basic knowledge of MVC and believe I have got more of it understood.

I have now come to a part in my learning where I am going to put it in to a real practise scenario but I seem to have fallen at the first hurdle.

I am trying to create 2 functions, one called view_profile which I will use to call functions etc from a model which will in turn call another function which should invoke to views which include the header and footer etc and pass data to the view.

At the moment it is very simple and will have additions in the future but for now it will not work, the page stays blank.

In my views folder I have this structure

pages
////home

templates
////header
////footer

My code is this

Code:
Class User extends CI_Controller {
        function view_profile(){
            $data['title'] = 'This is a title';
            $this->view_user_profile('home', $data);
            echo 'text';
        }
        
        function view_user_profile($page, $data) {
            $this->load->view('templates/header');
            $this->load->view('pages/' . $page , $data);
            $this->load->view('templates/footer');
        }
    }

I go to localhost/codeignitor/index.php/user/view_profile and nothing appears, not even a error. I know its the correct page though as if I change the view_profile() function to just echo text it works.

Many thanks in advance.


#2

[eluser]Pet[/eluser]
try this one

Class User extends CI_Controller {
function view_profile(){
$data['title'] = 'This is a title';
$this->view_user_profile('home', $data);

}

function view_user_profile($page, $data) {
$string=$this->load->view('templates/header','',true);
$string.=$this->load->view('pages/' . $page , $data,true);
$string.=$this->load->view('templates/footer','',true);
return $string;
}
}

i might mistaken but the idea is to make use of the load->view() 3rd parameter and pass it as a string.




Theme © iAndrew 2016 - Forum software by © MyBB