• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Library recall from a Helper issue

#1
[eluser]Feathers And Down[/eluser]
Hi everyone hope someone can help me with this. I try to do my own library (about templates and assets, etc...) and I have found a trouble with this situation: when method controller logic is done, finally it have to output the final result, so I use my library 'library1' to render the page with a method called 'method1', the method calls the $this->ci->load->view( 'view1', $data ); so it load the web page. Inside the web page it have a call to a helper 'helper1' that calls 'method2' from 'library' to add a value in an array that the same 'method1'(from library1) use to the final page. Is something like recursion:

controller
-> 'library1'
-> 'method1'
-> load ci 'view'
-> 'view' call helper 'helper1'
-> 'helper1'
-> call 'method2' from 'library1'


The problem is that when helper call method2, it work for its own values and from the library attributes class, but when then leave the method and start the final render with $this->ci->load->view() (inside library1->method1 called from controller) it doesn't keep helper values added/deleted from its logic.

Please help me with this I will give more info if you want.

controller calls:
Code:
public function prueba1( ) {

        $this->load->helper ( 'helper1' );
        $this->load->library( 'libreria1' );

        $this->libreria1->metodo1( 'vista1' );
    }

Library1
Code:
class Libreria1 {

    private $ci = NULL;
    private $head = array( );

    public function Libreria1( ) {

        $this->ci =& get_instance();
    }


    public function metodo1( $vista ) {

        $this->head[] = 'value_temp'; //this value print fine
        $this->ci->load->view( $vista, array( 'head' => $this->head ) );
    }


    public function metodo2( $archivo ) {

        $this->head[] = $archivo;
    }
}


Helper1
Code:
function helper1( $archivo ) {

    $CI =& get_instance();
    $CI->libreria1->metodo2( $archivo );  //The library1 recall
}

View1
Code:
<?php
helper1( 'archivo' );
?>
<body>
    Hola mundo =)


    <?php foreach( $head as $key => $val )
        echo $key. '=' .$val.'<br>'; ?&gt;

&lt;/body&gt;

I don't know if I make understand me and sorry by my poor english is not my native language.

#2
[eluser]WanWizard[/eluser]
There's an error in your train of thought.

By the time you get to helper1 (in de the view), methodo1 has already loaded the view, and passed $this->head to it (note: as a copy, so NOT by reference). helper1 then modifies $this->head, but that doesn't help the view, it still have the old value.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.