editPrie
editPrie

Reputation: 31

Load views - Error with codeigniter

I'm a newbie with codigniter, I'm doing a menu, so I put all the links not in the same main file for not repeat all time.

My code is:

In the main.php

    <?=$this->load->view('headers/menu');?>

In the menu.php

    <span><a href="<?=base_url()?>main/agregar">Agregar</a></span> 
    <span><a href="<?=base_url()?>main/modificar">Modificar</a></span> 
    <span><a href="<?=base_url()?>main/eliminar">Eliminar</a></span> 
    <span><a href="<?=base_url()?>main/buscar">Buscar</a></span> 

So, the following error appears and I don't know why... any ideas??? Thank you so much

A PHP Error was encountered

Severity: 4096

Message: Object of class CI_Loader could not be converted to string

Filename: views/main.php

Line Number: 15

Backtrace:

File: C:\xampp\htdocs\everisgas\application\views\main.php Line: 15 Function: _error_handler

File: C:\xampp\htdocs\everisgas\application\controllers\main.php Line: 9 Function: view

File: C:\xampp\htdocs\everisgas\index.php Line: 292 Function: require_once

Upvotes: 3

Views: 16887

Answers (7)

Muhammad
Muhammad

Reputation: 7344

if you want to load the content of the view and print it, then you have to tell CI to return the view content as a string, by passing the 3rd parameter as true, if you dont set the 3rd parameter to TRUE it will return the CI_Loader instance for the purpose of chaining.

<?=$this->load->view('headers/menu', '', TRUE);?>

Upvotes: 6

Endang Taryana
Endang Taryana

Reputation: 1

you can makey your coding like this

<?php $this->load->view('vadmin/menu'); ?>

this is can solve your problem

Upvotes: -1

screamzt
screamzt

Reputation: 37

Don't use

<?= 

because it is the same as

<?php echo

But $this->load->view return not a string, so you just need to use

<?php $this->load->view('some_template');?> 

without echo!

Upvotes: 1

srkn sltrk
srkn sltrk

Reputation: 418

This can be about the version of your framework. For example in CI 2.6

    <?php echo $this->load->view('headers/menu');?> 

works but in CI 3.0

    <?php $this->load->view('headers/menu');?>

is the usage.

Upvotes: 17

Mr. Programmer
Mr. Programmer

Reputation: 3103

In Codeigniter version 1.5.4(or lower) using load->view('headers/menu');?> will load the view file but in Codeigniter version 3.0 this wont work anymore instead you simply use like this load->view('headers/menu'); ?>

Upvotes: 0

Ramesh Mhetre
Ramesh Mhetre

Reputation: 404

Can you try using like below in your main view:

<?php $this->load->view('headers/menu'); ?>

This will load your menu view file in main view file.

Upvotes: 3

Vinie
Vinie

Reputation: 2993

Why are you echoing <?=$this->load->view('headers/menu');?>

instead of doing this load it in your controller before loading main view or use include 'menu.php' if main.php and menu.php in same directory.

Upvotes: 1

Related Questions