Welcome Guest, Not a member yet? Register   Sign In
How does one to extend Controller class?
#1

[eluser]TaxiMan[/eluser]
It's necessary to extend basic CI class Controller. How can it be released right?

P.S. Sorry if such question was somewhere on the forum. Thanks!
#2

[eluser]alboyd[/eluser]
I think you are not explaining your situation correctly because if you know anything about CI you always extend the CI controller when you create your controller.. So references to how to do this are splattered all over the user guide and this forum....

Please explain exactly and in as much detail as you can what it is that you would like to know.
#3

[eluser]TaxiMan[/eluser]
I'll try to explain. I'm just learning CI by creating some project. And now there is a barrier. First of all I don't understand how can CI load secondary views from primary right? For example I have a primary view with marked {} secondary views inside:

Code:
<html>
{head}
<body>
{top}
<div class="menu">
...
</div>
{footer}
&lt;/body&gt;
&lt;/html&gt;

How to implement this scheme by means of CI?

I've got a real attitude problem. Temporaly I've left this question. But there is another one. I have a lot of my controllers wish must use my method. Accordingly I must to create some parent class for the method. But this parent controller class must extends CI Controller. How can I do it right? Thanks!

P.S. I hope you understand me.
#4

[eluser]jedd[/eluser]
[quote author="TaxiMan" date="1251664687"]I'll try to explain. I'm just learning CI by creating some project. And now there is a barrier. First of all I don't understand how can CI load secondary views from primary right?[/quote]

You can load views from within a view - that's quite do-able, and a lot of people do it this way.

*I* don't like it, because I find it confusing (and I think the controller should be handling this more directly).

There's some options for you [url="http://codeigniter.com/wiki/Header_and_footer_and_menu_on_every_page/"]in the wiki[/url] if you haven't found them already.


Quote:I have a lot of my controllers wish must use my method. Accordingly I must to create some parent class for the method. But this parent controller class must extends CI Controller.

Happily this is covered by the above page, too - as well as in [url="http://ellislab.com/codeigniter/user-guide/general/core_classes.html"]some detail in the CI User Guide[/url]
#5

[eluser]Boris Strahija[/eluser]
It's really simple to load views from a view. I have it setup like this:
Code:
&lt;?php
    // Include header view
    $this->load->view('_inc/header');
    
?&gt;
    
    <div id="main">
        <div id="cont" class="clearfix">
            <h2>&lt;?php echo $title; ?&gt;</h2>
            
            &lt;?php get_notice(); ?&gt;
            &lt;?php
                //load the content view
                if (isset($content_view)) :
                    ?&gt;<div id="mid">&lt;?php
                    $this->load->view($content_view);
                    ?&gt;</div>&lt;?php
                endif;
            ?&gt;
        </div>
    </div>
    
    <div id="push"></div>

&lt;?php
    // Include footer view
    $this->load->view('_inc/footer');
    
?&gt;
#6

[eluser]JoostV[/eluser]
If you have a lot of controllers that must use a certain method you can create that method in a model or a library.

Call that method in the __construct() of every controller that needs it. Or you can autolad the library if EVERY controller needs it.

EXAMPLE LIBRARY
Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Somelib
{
    public function __construct()
    {
        // Instantiate the CI libraries so we can work with them
        $CI =& get_instance();
        // Place some array in the controller's $data array
        $CI->data['somelib'] = array(0 => 'zero', 1 => 'one');
    }
}
EXAMPLE CONTROLLER
Code:
&lt;?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
class Somecontroller extends Controller
{
    /**
     * Contains all data to be passed to view
     * @var array $data
     */
    public $data = array();

    function __construct ()
    {
        parent::Controller();
        // Load library
        $this->load->library('somelib');
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB