Welcome Guest, Not a member yet? Register   Sign In
Variable in view not the same in all pages.
#5

[eluser]sb05[/eluser]
I also tried this post from 'cahva' in this topic:
Passing controller variable to more then one view

This person had something similar with my issue. In the end this code worked for him:
Code:
class Filesystems extends Controller {

    var $data;

    function __construct();
    {
        parent::__construct();
        
        $this->load->model('Links_model');
        $results = $this->Links_model->getlinks();
        $this->data['links'] = $results['rows'];
        $this->data['num_results'] = $results['num_rows'];
    }
    
    function index()
    {
        #
        # Some code here
        #
        
    
    
        # ..and in the end of method
    
        // Either this
        $this->load->view('includes/template', $this->data);
        
        // Or like this
        $this->load->vars($this->data);
        $this->load->view('includes/template');
    }
}

//Now in the template you would have $links and $num_results. If you load views inside includes/template view, use the load->vars //option and those variables will work also in the nested views.

So I tried to do this with my controller:
Code:
class Ads extends Controller {

    
    var $data;
    // num of records per page
    private $limit = 10;
    
    function __construct()
    {
        parent::__construct();
        
        $this->load->model('adModel');
        $results = $this->adModel->get_by_id($ad_id);
        $this->data['ads'] = $results['rows'];
        $this->data['num_results'] = $results['num_rows'];
    }

function index()
{
//some code

//at the end of the method

$this->load->vars($this->data);

        
            $this->load->view('banner_view', $data);
            $this->load->view('left_column_view', $data);
            $this->load->view('right_column_view', $data);
            $this->load->view('adList', $data);
            $this->load->view('footer_view', $data);
    }

}

But then I get an error 'undefined variable: ad_id' at
Code:
$results = $this->adModel->get_by_id($ad_id);

And I get also this error:
ErrorException [ Fatal Error ]: Cannot use object of type CI_DB_mysql_result as array
on line:
Code:
$this->data['ads'] = $results['rows'];

I'm so stuck :S


Messages In This Thread
Variable in view not the same in all pages. - by El Forum - 01-13-2011, 07:35 PM
Variable in view not the same in all pages. - by El Forum - 01-13-2011, 09:14 PM
Variable in view not the same in all pages. - by El Forum - 01-14-2011, 04:24 AM
Variable in view not the same in all pages. - by El Forum - 01-14-2011, 04:40 AM
Variable in view not the same in all pages. - by El Forum - 01-14-2011, 04:49 AM
Variable in view not the same in all pages. - by El Forum - 01-14-2011, 04:52 AM
Variable in view not the same in all pages. - by El Forum - 01-14-2011, 04:52 AM
Variable in view not the same in all pages. - by El Forum - 01-14-2011, 05:44 AM
Variable in view not the same in all pages. - by El Forum - 01-14-2011, 06:01 AM
Variable in view not the same in all pages. - by El Forum - 01-15-2011, 06:47 PM
Variable in view not the same in all pages. - by El Forum - 01-15-2011, 08:46 PM
Variable in view not the same in all pages. - by El Forum - 01-16-2011, 05:35 PM
Variable in view not the same in all pages. - by El Forum - 01-16-2011, 05:48 PM
Variable in view not the same in all pages. - by El Forum - 01-17-2011, 06:54 AM
Variable in view not the same in all pages. - by El Forum - 01-17-2011, 09:10 AM
Variable in view not the same in all pages. - by El Forum - 01-17-2011, 11:01 AM
Variable in view not the same in all pages. - by El Forum - 01-17-2011, 11:08 AM
Variable in view not the same in all pages. - by El Forum - 01-17-2011, 11:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB