iframe/frame in codeigniter - php

i cannot use iframe in codeigniter. My have tried following
/My controller things.php
function index()
{ $this->load->view('view_index'); }
In view view_index.php there r 4 frame header, main, left & footer. My view_login.php will be loaded in main frame which actually loads my function login()

To send data to different parts of a page the use of templates is advised, at least by myself.
For instance, a template page file look like this
$this->load->view('tops/home1'); //header
$this->load->view($content);//main content(your login area)
$this->load->view('bottoms/main_home'); //footer
From the controller
$data['content'] = 'home/home_content'; //this is the **main** part of your page
$this->load->view('template1', $data);
To include your login script, simply put the login file in the root(in a directory made by you) and include it as a normal php include wherever you want it to be. As Aren noted, the use of Iframes is ancient and should be avoided

Related

Output flickers if I include HTML in PHP

for my website i have some static header/footer HTML and some dynamic content generated by PHP. When it comes to render the output I just include a file with HTML inside from my PHP code. This works perfect - also when I switch between pages.
<?php
...
public function render() {
...
// file for output
include $fileName;
...
}
?>
But I also need some header.hmtl and footer.html that contains the static information (text and some divs for formating) and want to put that in front of each dynamic content, represented by $fileName.
So I simply add two includes that represent the static information.
// file for output
include "./Views/html/header.html";
include $fileName;
include "./Views/html/footer.html";
So this does what I like (formatting, etc.), but if I switch from page to page it flickers for one time. As much as I can see the page is first renderd without header/footer information and then a second time with header/footer information. Looks like this generates the flickering.
How can I avoid this ? Is this probable related to a RewriteRule of my MVC-Framework ?
Any hint is appreciated.
thanks to Lawrence who led me to the right term. It solved my problem completely.
I put a <body><script>0</script><!-- rest of the code --></body> in my code and it works now. –

Can I assign an include_once file to a $var with PHP?

I am trying to roll my own MVC purely for learning purposes, but am hitting a snag when I try to load in the view files. Here's my problem:
Front controller grabs appropriate page controller, page controller include_once() the appropriate view. The view is a file containing HTML and PHP. When I return the include file from the controller, the included file content appear out of sequence of the PAGE layout intended. (example: I want to display HEADER CONTENT FOOTER, but when I include the view's contents, my controller spits out CONTENT, HEADER, 1, FOOTER).
In my front controller I am attempting to set my included file contents to a variable I then echo in between my HEAD and FOOTER in the PAGE template. But this does not work as intended. I can wrap my view file contents in: return "code" but I don't want the added headache of worrying about stray quotes/double quotes in my view code that could break the script. I have tried file_get_contents(), but this only spits out a string (albeit in the right place/sequence in my template) and does not the PHP in my view files correctly (ie at all).
My question is: Is there a way I can return my view file to my front controller using include_once() in a variable? I can't seem to find a adequate answer to this. I'd be happy to add my code if it would help.
You can assign a return value from an include(). A lesser-known feature of this function is that you can have a file like this:
<?php
// config.php
return array('database_host' => 'localhost');
and you can read it in thus:
<?php
$config = include('config.php');
However, you're wanting to do this:
<!-- text.html -->
<h1>Heading</h1>
<p>Hello</p>
and read it in with this:
$html = include('text.html);
You can try doing that, but as soon as the include() scans the file, the output will be sent to the web server. That's how PHP works. Since there is no explicit return value, moreover, the $html variable comes back empty.
Thus, we use the output buffering functions to modify PHP's behaviour: we start buffering, and then we fetch it and clear it. This is then not sent to Apache, unless of course you choose to turn off output buffering and echo what you have collected, in which case it goes back into the normal output buffer and is actually sent.

PHP and web page displaying

I have searched all over the web trying to figure this out and am now trying to get a direct answer from some experienced users. I hope I can explain myself completely.
I know HTML and CSS and some PHP and Javascript, but no mean an expert. This is my questions:
When creating a website by hand (no Drupal, or Wordpress or predesigned templates), The first thing I do is create an index.php file that shows my HTML page layout. The second thing I do is create my links.inc.php file that will show all the links to my pages, ex: Home, About Us, Contact Us. Now on the index.php page I create php include files for the header, footer, and link pages. (these would read header.inc.php, footer.inc.php, links.inc.php) Now here is where I am trying to figure if there is an easier way to do the next step.
My normal steps would next to be to create a home.inc.php, aboutus.inc.php, contactus.inc.php files which will have all the "content" I want shown for each page.
I would then create a duplicate of the index.php and create aboutus.php where I would use the php include function to add the aboutus.inc.php into the "main content" area I would want this information displayed at. Then I would create anther duplicate of the index.php and name it contactus.php and "include" the contactus.inc.php file.
Is there any way to use the index.php file and have all the inc.php files on that page? For instance,
<div id="main">
<?php
include ("home.inc.php");
include ("aboutus.inc.php");
include ("contactus.inc.php")
?>
</div>
Obviously this does not work they way I have it laid out above, it shows all the pages at the same time instead of only showing the one page that is clicked on from the menu. Any suggestions? Is there a different way or am I doing it correctly with creating multiple pages?
Thank you for any help and I hope I was clear, if not I can try to explain a different way.
My suggestion is to include files conditionally, based on a variable that defines the current page.
For example, given the following navigation:
Home
About Us
Contact Us
Configure your index.php file to include external files, something like this:
// determine the requested page, default to the home page
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
// check if the requested include file exists
$include_file = is_file($page.'.inc.php') ? $page.'.inc.php' : false;
// if the requested include file exists, include it
if ($include_file) {
include $include_file;
}
Feel free to adjust the logic. For example, if a $page value is not recognized as a valid page on your site, you may want to show a 404 page, default to the "home" page, etc.
Edit
If your include files are in a different directory, you'll need to provide the correct path:
// define the path to includes
$path = 'inc/';
// check if the requested include file exists
$include_file = is_file($path.$page.'.inc.php') ? $path.$page.'.inc.php' : false;
You could send a variable to PHP index.php?action=home; then, inside index make some verifications
if($action=="home") {include index.inc.php; }
else if ($action=="contact") {include contact.inc.php }
and so on.

jQuery not working in a PHP include

I am building a website that utilizes a template and brings each "content" page in through an include statement. On one page, I am using wt-rotator which is a jQuery script based slide show so to speak. My problem is that the page that I am wanting to include runs the script perfectly, but when I try to view that page through the main template using the include, there is no slideshow. This is the code that makes the "include" work:
<?
include "/home/content/82/7960182/html/alliantwellness/contentfiles.php";
$pid = $_GET["pid"];
if ($pid == "") {
$pid = 0;
}
?>
That part is at the very top of the index.php page. Then this:
<?
//Main Content including Navigation fills in here
include "/home/content/82/7960182/html/alliantwellness/content/" . $content[$pid];
?>
is what I use to call the page. The contentfiles.php page is just an array of "content" pages that are stored in a folder called "content".
Any ideas on why the slideshow works outside the template, but not inside?
Here are the URL's so you can see what I am talking about:
http://www.alliantwellness.com
http://www.alliantwellness.com/content/home.php
I think you need to remove this line:
<script type="text/javascript" src="http://www.alliantwellness.com/scripts/jquery.wt-rotator.js"></script>
from index.html. That file is not a Javascript file, it looks like it's a duplicate of the index.html file. You're already loading jquery.wt-rotator.min.js on a different line of the file, and that's the correct JS.
I also wonder why you're loading both http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js and http://www.alliantwellness.com/scripts/jquery-1.7.1.min.js, why do you need to load two different versions of jQuery from different locations? But home.php loads both of them and it seems to work.

Ajax content area with CodeIgniter?

Have recently started to re-develop an application with CodeIgniter and I am trying to implement my template into the system.
I am facing an issue that I can't yet see a way around
Basically, at the minute within the controller an example of what I am doing is:
/*
* Load view for header
*/
$this->load->view('header_view');
/*
* Load view for navigation
*/
$this->load->view('navigation_view');
/*
* Load view for content
*/
$this->load->view('content_view');
/*
* Load view for footer
*/
$this->load->view('footer_view');
However the problem I am facing is that the content area has pages dynamically loaded in to it.
So the navigation area links don't open up the HREF URL but they load that page data in to the content div via ajax.
I need to be able to go to my controllers directly via the URL such as 'http://www.website.co.uk/controller/method_name/parameters' which at the minute is fine.
The navigation however will load that link in to the content area which also includes the header/navigation/footer so I end up with nested layouts in the content area...
The simple way around it is 'well don't include the header/navigation/footer views in every page' however then you can't directly go to the URL such as above, it would only work when loaded in to the content area as it would need to have the header, navigation and footer.
The solution that I ideally need is that the header/navigation/footer are ALWAYS loaded around any controller so that if I go to a controller/method via the URL I don't have to load the header/navigation/footer in the controller but it is automatically loaded around it.
Any ideas appreciated, thanks
Why not extend the CI controller with a MY_Controller, then all your controllers will extend MY_Controller. In my_Controller have a function like:
public function loadView($file, $data=array()){
$this->load->view('header', $data);
$this->load->view($file, $data);
$this->load->view('footer', $data);
}
Then, from your controllers actions, just call it :
public function index(){
// code code code
$this->loadView('welcome', array('message'=>'Hello!'));
}
I think you get the point.
in ajax you can use views like this:
<div id="header"></div>
<div> //here all your stuffs</div>
</div id="footer"></div>
then just :
<script>
$(function(){
$('#footer').load('my_footer_view_url');
$('#header').load('my_header_view_url');
});
</script>
this is a poor example, you can define both a php method which serves the views and a js method which loads them into divs, so each view then must have only a <div> where to load partials
Important
if you can use Ajax, this solution is great, cause once you move the #footer div somewhere else in your views you moves an enteire footer view for example, php will be more static anyway, but it depends, i sad, if you can or not use ajax ;)

Categories