Welcome Guest, Not a member yet? Register   Sign In
include controllers as you would a normal .php page
#1

[eluser]rossmurphy[/eluser]
Hi all,

So i was wondering if it is possible to use the php include to include a controller and hence the view like so:

Code:
<?php include "/games/topwinners"; ?>

This way you would be able to include the view, and the data that comes with it.

I have tried but keep getting an error, wondering if anyone else has had any luck with this.
#2

[eluser]rossmurphy[/eluser]
Here is an overview of my main goal here.

I have say 20 controllers, each doing different things. Sometimes a client needs the functionality of 2 or more controllers in a single page. For example, a client needs a page to display slot games and keno games i the same view.. but these are 2 separate controllers with their own views.

This is why i have been trying the include, i thought i might be able to achieve my goal through the view.

I have also thought about doing this to achieve my goal..

Lets say i need slots and keno on the same view. I put in the url 'http://example.com/template?slots&keno;'. The query string is retrieved and broken down. I then need to call the method in the slots controller and the keno controller and output the data from both into a single view.

Does anyone know if i can do this using a helper or library. I'm pretty sure i can't call a method from another controller.. is this correct?

Thanks
#3

[eluser]John_Betong[/eluser]
[quote author="rossmurphy" date="1248386465"]Here is an overview of my main goal here.

I have say 20 controllers, each doing different things. Sometimes a client needs the functionality of 2 or more controllers in a single page. For example, a client needs a page to display slot games and keno games i the same view.. but these are 2 separate controllers with their own views.

...
...
...

Thanks[/quote]
 
 
I would be tempted to create a "debug_21st_controller" and two new libraries (which have the same "functionality of 2 or more controllers in a single page".

The new libraries will be called in your "debug_21st_controller" and the existing "partial views" will also be called.

Output will go to a new "debug_21st_view".

By doing it this way your existing code will not be affected.

Check out http://ellislab.com/codeigniter/user-gui...aries.html and searching this forum on "partial views".
 
 
 
#4

[eluser]rossmurphy[/eluser]
Hmm, a library may be the way to go. Is it possible to access methods in controllers from a library?
#5

[eluser]John_Betong[/eluser]
[quote author="rossmurphy" date="1248416157"]Hmm, a library may be the way to go. Is it possible to access methods in controllers from a library?[/quote]
 
I reckon you should just play about with the simple licrary examples given in the User Guide, get a "feel for them", then try to apply the libraries to your particular application.
 
>>> Is it possible to access methods in controllers from a library?
Maybe since CodeIgniter can be used or abused and is not rigid.
 
I think the MVC way is to access the library methods from your controller and not to access the controller methods from your library:
 
Try this:

1. include the library into your controller
2. call the methods in your library
3. load "partial views" with your data
4. output the data to your view
 
 
 
#6

[eluser]rossmurphy[/eluser]
Im not sure what a partial view is. Had a look around, but not luck. Mind explaining a bit.. Thanks.
#7

[eluser]John_Betong[/eluser]
[quote author="rossmurphy" date="1248421043"]Im not sure what a partial view is. Had a look around, but not luck. Mind explaining a bit.. Thanks.[/quote]
 
This Search returned 15 pages related to "partial views'.

In a nutshell a "partial view" is a self-contained part of your final output view. Controller $data may be passed and displayed in the "partial view".

From bitter experience I find that each "partial view" is better if it is in a self-contained block ie. either has no structure blocks (DIV, P, FORM, etc) or if it does then ensure the each structure is closed and complete, otherwise it wreaks havoc with the final output and is not easy to debug.
 
 
Your final output view:
Code:
<html>
  <head>
    <title><?php echo $title ></title>
  </head>
  <body>
    <div id='container'>

      <div id='box_left'>    
        &lt;?php echo $box_left_partial ?&gt;
      </div>

      <div id='box_main'>    
        &lt;?php echo $box_main_partial ?&gt;
      </div>

      <div id='box_right'>    
        &lt;?php echo $box_right_partial ?&gt;
      </div>

    </div>&lt;?php /* container */ ?&gt;

  &lt;/body&gt;
  &lt;/html&gt;
&nbsp;
&nbsp;
&nbsp;




Theme © iAndrew 2016 - Forum software by © MyBB