Welcome Guest, Not a member yet? Register   Sign In
Unable to find url trying to "include" path, but the url is correct!
#1

[eluser]Rubiz'[/eluser]
Well, I'm very happy to have meeting a framewrok like Code Igniter!! Thnx God a good friend told me about it, and helped me with the first steps.

Now I'm having a problem with trying "include" header/footer in my pages.

I have searched some posts with similar problems but couldn't find something for solving my problem.

So...

This is the way I'm trying make something like include:
Code:
<? echo $this->load->view(base_url().'essenciais/header.php', '', false); ?>
And this is the error message:
Code:
An Error Was Encountered

Unable to load the requested file: http://192.168.0.107/villa_branca/essenciais/header.php

But... my page is there, this is correct path...

Someone can help this lost path to find itself? Remembering, the function call is in the view page... not in the controller page.
#2

[eluser]Skulls[/eluser]
is your header.php file in the ci structure... in the views folder? if it is there .. and in the subfolder essenciais you need to load it with
Code:
$this->load->view('essencialis/header');

if that file is outside the views folder... although you should keep it there, you can load the file by calling
Code:
$this->load->file('path/to/file');
#3

[eluser]Rubiz'[/eluser]
Well, I'm addapting slowly to the code igniter coding thinking...

Now I see I have to use something like require() inside the controller.
So I did that:
Code:
function index()
    {
        if ($this->Valida_user_model->checkUser())
        {
            $nome_usuario = $this->db_session->userdata('us');
            $data['user'] = $nome_usuario;
            $data['header'] = require('essenciais/header.inc');
            
            $this->load->view('logado', $data);
        }
        else redirect('');
    }
It works! But now I have other problem, I usualy post the admin username identification with the other header information.

The code I want require is like this:
Code:
<h1>Admin name</h1>
<hr />
<div id="userSt">Wellcome &lt;? if ($user) echo '<span>'.$user.'</span>' ?&gt;</div>
<div class="right"><a href="&lt;?=base_url()?&gt;index.php/valida_user/doLogout">Logout</a></div>

The header now is without style and the username returns me "1"...

Someone have an ideo for solution?
#4

[eluser]Rubiz'[/eluser]
Well Skulls, I havent read your post befor posting, I can load several views and send it all for the same page?

What I want to do is something as simple as include 'path.php';
I'm seriously thinkig why I couldnt do this yet, its something so easy...
#5

[eluser]alexsancho[/eluser]
Code:
function index()
    {
        if ($this->Valida_user_model->checkUser())
        {
            $nome_usuario = $this->db_session->userdata('us');
            $data['user'] = $nome_usuario;
            $data['header'] = $this->load->view('essenciais/header.inc', $data, true);
            
            $this->load->view('logado', $data);
        }
        else redirect('');
    }
#6

[eluser]tonanbarbarian[/eluser]
The problem with what you were originally trying to do was because you were using base_url.

Code:
&lt;? echo $this->load->view(base_url().'essenciais/header.php', '', false); ?&gt;
should have just been
Code:
&lt;? echo $this->load->view('essenciais/header.php', '', false); ?&gt;
then have a folder called essencials under the view folder.

Using base_url was inserting the full URL of your website into the path, rather than the file location.

I have a post here http://ellislab.com/forums/viewthread/66997/#329953 where I talk about partials or elements.
You can use the renderElements code I have provided to load sub views from within a view, rather than doing it in the controller

Also sounds like you could do with a layout library
check out http://ellislab.com/forums/viewthread/67521/#332687 this post that has a couple of links to layout libraries
Using the layout library you can wrap the main content of your views in an overall layout

hope these help




Theme © iAndrew 2016 - Forum software by © MyBB