CodeIgniter Forums
Loading a view from a different class. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Loading a view from a different class. (/showthread.php?tid=7711)



Loading a view from a different class. - El Forum - 04-20-2008

[eluser]Taff[/eluser]
I've spent quite some time browsing the forum, bookmarking things that I will probably need on my way, but haven't been able to find a solution to this, which either means I don't know what I'm on about, or I have no idea what I'm on about.

I have built a little class based on the blog tutorials to create names for projects.

class Project extends Controller {
Code:
function Project(){
        parent::Controller();
        $this->output->enable_profiler(TRUE);
        $this->load->scaffolding('projects');
        $this->load->helper('url');
        $this->load->helper('form');    
    }
    function index(){
        $data['title'] = "Project Management";
        $data['subtitle'] = "| Nothing more, nothing less";
        $data['query']= $this->db->get('projects');
        $this->load->view('project_display',$data);
    }
    function p_list(){
        $data['query']= $this->db->get('projects');
        $this->load->view('project_list',$data);
    }
}

In particular I like my project_list view which I'm embedding into my project_display view and works very nicely without me having to repeat the code anymore.

My next step was to make a client class for all my client information. This client class is essentially very similar and allows me to output their data in a list using my client_display view:

Code:
<div id="normalcontent">
        <h3>Clients</h3><p>&lt;?php echo anchor('client/add', 'Add a new client' , array('title' => 'Click to add a new company')) ?&gt;</p>    
        
                &lt;?php foreach ($c_query->result() as $row): ?&gt;
                <div style="width:50%;float:left;">
                <h4>&lt;?php echo anchor('clients/'.$row->client_id, $row->name , array('title' => 'Click to edit '.$row->name)); ?&gt;</h4>
                <p>Address &lt;?php echo $row->address; ?&gt;<br />
                City &lt;?php echo $row->city; ?&gt;<br />
                State &lt;?php echo $row->state; ?&gt;<br />
                Zip &lt;?php echo $row->zip; ?&gt;<br />
                Country &lt;?php echo $row->country; ?&gt;<br />
                URL&lt;?php echo $row->url; ?&gt;<br />
                Phone&lt;?php echo $row->phone; ?&gt;<br />
                Fax &lt;?php echo $row->fax; ?&gt;</p>
                &lt;?php echo anchor('clients/'.$row->client_id, 'Edit' , array('title' => 'Click to edit '.$row->name)); ?&gt;
                </div>
            &lt;?php endforeach; ?&gt;
        
        
</div>

I am now at a total loss as to how I can embed my project_list into this view. Everything I have tried tells me it can't find query or mad attempts such as
$projects=$this->Projects->p_list();
have had no avail.

As mentioned at the beginning this is most probably due to my lack of terminology and a total grasp of the pattern, and maybe I should be approaching this is a different manner?

Thanks for any pointers!

Taff


Loading a view from a different class. - El Forum - 04-20-2008

[eluser]Jamie Rumbelow[/eluser]
Are you making sure you run the query for the projects on the client controller? Make sure that you are querying the right table.


Loading a view from a different class. - El Forum - 04-20-2008

[eluser]Taff[/eluser]
Thanks for helping, I was sure that I was calling that query, and it really had me stumped, but thanks to your reply, it got me thinking.
It was in fact an error on my part (no surprise there then Wink in the fact that I was doing the $this->load->view bit before the $this->db->get bit.

Thanks for pointing me in the right direction.
Taff