Welcome Guest, Not a member yet? Register   Sign In
Include not working after putting view files inside another folder
#1

[eluser]ninjayan[/eluser]
Okay so its me again with another problem.
So I was looking at the structures of files and I notice that my views folder has some php files now and still growing. So I created a folder inside my views and categorized the files to which folder I'm going to put.

views>includes
views>navigations
views>system_message
views>user_management

So I put the 'login_pending' file inside the 'system message' and changed the include from
include(includes/header.php); to include('../includes/header.php');
Now, I'm receiving this error message

A PHP Error was encountered

Severity: Warning

Message: include(../includes/header.php): failed to open stream: No such file or directory

Filename: system_message/login_pending.php

Line Number: 2
#2

[eluser]solid9[/eluser]
That is very straight forward.
Are you sure you have uploaded the file?

also can you try removing the quotes,
Code:
include(includes/header.php); to include(’../includes/header.php’);

Just do trial and error.

#3

[eluser]ninjayan[/eluser]
Here's the include from view
Code:
include('../includes/header.php');

and this is from the controller
Code:
$this->load->view('system_message/login_pending');
#4

[eluser]solid9[/eluser]
You can try below,
Code:
include('../includes/header.php');

or
Code:
include('./includes/header.php');

or
Code:
include('includes/header.php');

Where did you put header.php ?
Can you indicate the right path for it.

I think you need to consider your base_url() also.
If you have set your base_url then you should include base_url as well.


Code:
$tmp_path = base_url() . '/includes/header.php';
include($tmp_path);

Again just use trial and error.
#5

[eluser]Aken[/eluser]
Why are you using include() in the first place? You can load views inside of views - just do that.
#6

[eluser]ninjayan[/eluser]
In my controller I have this
Code:
public function account_settings()
{
  $this->load->view('users/account_settings');
}

and the navigation is on the other folder.

view>users>account_settings.php
view>navigations>navi.php

so in my account_settings I do
Code:
include('../navigations/navi.php');
but not working. But if I put account_settings.php outside the users folder and remove the '../' from include it works fine.
#7

[eluser]LuckyFella73[/eluser]
I can just repeat: load your view files in the CI way like
suggested here before! Even in your view file if you go that
way.

Code:
$this->load->view('system_message/login_pending');

If you insist on "include" use the APPPATH constant:
Code:
include(APPPATH.'views/navigations/navi.php');
#8

[eluser]ninjayan[/eluser]
I already did $this->load->view and it's not working on all files!
It works on some but not all!
#9

[eluser]LuckyFella73[/eluser]
Ah ok! If you use the "$this->load->view('viewfile')" method
it should look from the folder "views" and then
if defined in a subfolder. If it didn't work in all
cases - maybe you had a typo or a leading slash?
I have subfolders in my views directory all the time and
had never problems calling the files. The only difference
may be that I load the view files in my controller and
send them to the Main views. But it should work even if
you load sub-views in your views.
#10

[eluser]ninjayan[/eluser]
Thanks. I will check what's the error




Theme © iAndrew 2016 - Forum software by © MyBB