0

I have created a view main.php and I have loaded the view internal.php inside main.php

Now, using the following code inside internal.php:

pathinfo(__FILE__, PATHINFO_FILENAME), '.php'

or the code:

echo $_ci_view;

i am getting internal.php while I want main.php as it is the main view being loaded in browser window. How can I do this?

ITSagar
  • 673
  • 2
  • 10
  • 29
  • Is the url in your browser changing when loading internal.php? – Vickel Jan 15 '18 at 15:49
  • No, i am getting main in url – ITSagar Jan 15 '18 at 15:58
  • But since I am using the page name fetching code inside internal, thats why it is showing internal. But how to show main there? – ITSagar Jan 15 '18 at 15:59
  • Why do you need this information? – DFriend Jan 15 '18 at 16:00
  • Also, I cannot write the page view name fetching code inside main page because internal page has a form which is submitted and inside controller, I am receiving the view name from posted data of this form. – ITSagar Jan 15 '18 at 16:00
  • What I am doing is... internal form is being loaded in several outer views. on submitting form, I need to come back to the view from where form was posted. So, on posting form, I am taking view name to controller, doing code work and loading the main view again. – ITSagar Jan 15 '18 at 16:01
  • https://www.codeigniter.com/user_guide/general/views.html#loading-multiple-views and https://www.codeigniter.com/user_guide/general/views.html#returning-views-as-data –  Jan 16 '18 at 03:53

2 Answers2

1

you can parse the url like this:

$q=parse_url($_SERVER['REQUEST_URI']);
$q=(isset($q['path']))?$q['path']:''; 

echo $q outputs e.g.: '/main.php'

see more at the php manual and about parse_url()

Vickel
  • 7,879
  • 6
  • 35
  • 56
  • 1
    What is $query here? my page name is main.php so url looks like: abc.com/main – ITSagar Jan 15 '18 at 16:04
  • parse_url returns an array – Vickel Jan 15 '18 at 16:06
  • as you need the path and not the query part, I've updated the answer – Vickel Jan 15 '18 at 16:08
  • will it have any adverse effect on security or performance in codeigniter? – ITSagar Jan 15 '18 at 16:47
  • and the url still shows the name of controller instead of showing the name of view ... how this can be rectified? – ITSagar Jan 15 '18 at 16:48
  • also Deceze wrote a very interesting post on that issue: https://stackoverflow.com/a/6474936/2275490 – Vickel Jan 15 '18 at 17:00
  • U didnot get it. My query is that the form from main view calls controller sendmessage. Then in sendmessage, I loaded view main, but the url still says servername/sendmessage even after loading view. How to show servername/main here? – ITSagar Jan 15 '18 at 17:14
0

use include 'location/filename.php'; inside main.php

ref https://www.w3schools.com/php/showphp.asp?filename=demo_include2

SANDEEP S S
  • 68
  • 1
  • 9
  • does it adversly effect the security part or performance aspect of codeigniter in any manner? – ITSagar Jan 15 '18 at 16:17
  • loading a single file(contain everything) and loading a file with in another file definitely have Performance difference ,but that difference less – SANDEEP S S Jan 15 '18 at 16:26
  • Actually there is no security issues, but checking the file whether it is exist or not before loading is always good – SANDEEP S S Jan 15 '18 at 16:35