Include independent project to the codeigniter view - php

Is there any possible to include the independent project as a browser in separate catalog/server into codeigniter view?
For example:
<?
include 'www.yahoo.com';
?>

Try including this in your view
<iframe class="iframe_element" src="https://www.example.com"></iframe>
Be sure to apply style to your .iframe_element to make it the size and position that works best for you.

Related

How to avoid adding the same navbar template to every .html page

I'm new at the scene and I'm using Bootstrap 3 and this template for the first time. I need help with the navbar. In the template each content.html has their own navbar.
I need the navbar in a separate file, because I do not want to make changes in every single content.html file.
In my old site without Bootstrap I worked with:
<?php
include("includes/navigation.html");
Can someone help me?
You need configure to put your repeated html data's in a single file and include that one into another.
Lets simple,
if your Project structure like this
project(folder)
db(folder)
Dbconnection.php(file)
js(folder)
jquery.js(file)
css(folder)
bootstrap.css(file)
index.php(file)
page1.php(file)
page2.php(file)
Create a new file with contents of your navbar html tags alone.
For ex. in your nav-menu.php contains
<navbar>
......
......
</navbar>
and save them into new includes folder in your project. So now your project structure will be like this one,
project(folder)
db(folder)
Dbconnection.php(file)
js(folder)
jquery.js(file)
css(folder)
bootstrap.css(file)
includes(folder)
nav-menu.php(file)
index.php(file)
page1.php(file)
page2.php(file)
Now you should include this file(nav-menu.php) in all the template files using php include method, like
include("includes/nav-menu.php");
Add this above code in all of your common files.
You can use
<?php include("includes/navigation.php") ?>
in this project too.
Fastest way that comes to my mind is to just include the code you need to change for every page in a separate switch/case and call the different cases at the top of the page that is including the navbar.
Just note your navigation file needs to be .php, not .html like your example.

Including a uri "/user/sidebar" page (Kohana Framework) in PHP

I would like to have the page on user/sidebar on the right in the template design.
Normally, I would include a php file. But I am using Kohana Framework so I have created a view and a controller for this sidebar, and exists on mysite.com/user/sidebar
Now how would i <?php include "/user/sidebar"; ?> correct? I get no such file og dir error for this. I tried full url, but allow_url_include=0
Just looking through the Kohana documentation...
It seems like you can include a "request" inside a view with the following command.
<?php echo Request::factory('user/sidebar')->execute() ?>
See this page for more info: http://kohanaframework.org/3.0/guide/kohana/mvc/views
AndrewR's comment is close. For Kohana 3.2, you'll want to load a view within a view and not a request within a view:
<?php echo View::factory('/user/sidebar'); ?>
or
<?php include Kohana::find_file('views', 'user/sidebar') ?>
Either is acceptable to do.

Is there any way to find in which file - file is included

Am sure the question is vague.
Let me try to explain.
Assume zend frame work - PHP - jquery combination.
I include jquery files in layout.phtml.
i include some files in controller.php.
some file in view.phtml
Atlast when i run and view the page . Is there any way or any tool to find which file is included through which file (layout controller or view) ??
In addition can some one explain which is the best way include js files and where . using zend framework in layout or controller or view
The only way to find where a public, static asset (JS, CSS, image, etc) is included is to trawl through the source code (using something that can "find in files" would save time).
In regards to how and where to include such assets... for global includes (common stylesheets, scripts, etc), include these in your layouts.
For specific page includes, place these in your views.
The best way to include a static asset is using the appropriate view helper. These are generally displayed in your layout file, for example
<?php echo $this->doctype() ?>
<html>
<head>
<?php
echo $this->headMeta()->prependHttpEquiv('Content-Type', 'text/html; charset=' . $this->getEncoding());
// I use "prepend" here so it comes before any page specific stylesheets
echo $this->headLink()->prependStylesheet($this->baseUrl('/css/common.css'));
echo $this->headScript();
?>
</head>
<body>
<!-- content -->
<?php echo $this->inlineScript() ?>
</body>
</html>
You can then add to these placeholders in your view scripts, for example
<?php
// index/index.phtml
$this->inlineScript()->appendFile('https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js')
->appendFile($this->baseUrl('/js/my-jquery-script.js'));
To "include" a file means very different things in PHP (where it is analogous to copying and pasting source code from another file into the current file) and HTML/JavaScript (where you are referencing another file, which the browser must make a separate HTTP request to download). What do you consider "including"? Are image tags "including" the images? At least we can easily count those references by examining HTTP requests; from the client side, it's impossible to tell what include()s went into the source code behind the rendered output. Even naive source code searching couldn't tell you thanks to autoloading. As is, your question is not well enough defined to provide a clear answer.
Controversal answer:
You don't need that.
If you need that then it's something wrong with the way your designed your application.
Note: I've learned (trial and error) that 90% of things I don't know how to do and that seem to be impossible in ZF are a result of wrong application design.

How do you include PHP files in the view file of a Zend/MVC?

Maybe I dont understand the MVC convention well enough, but I'm trying to include a file to the index.phtml view for the main Index Controller, and it keeps giving me an Application Error. I have no idea what this error is or why its not working. But I'm using a standard include_once(...) in the view.
Is this even allowed?
A view in Zend is still just a php file. If you are getting errors in a view using include_once(), they are probably because the file you want can't be found in your include path. Trying dumping get_include_path() into the view and you will see what directories PHP is searching to find your included file.
As an alternative to include_once, you could use
<? echo $this->render('{module}/{action}.phtml') ?>
to pull in the file.
There are partial views for such purpose
http://framework.zend.com/manual/en/zend.view.helpers.html (ctrl+f Partial Helper)
The view is only the HTML that will be rendered. It's the very last thing that is processed. The controller is called first, then it calls whatever models are needed within. After passing all the data to the view, the view's HTML is rendered.
In short: whatever you include in the view, the controller isn't aware of it. You need to run your PHP includes earlier in the code. If you do it in the controller, it should work OK, I suppose (not tested, so I don't guarantee anything).
You can use Zend View Helpers for this purpose
last time this works fine for me. You can try this:
<?php echo $this->partial('common/left_menu.phtml'); ?>

Zend organization question

So I had a question on general organization of code for the Zend framework with regard to the layout.
My layout is basically this:
(LAYOUT.PHTML)
<div id='header'>
<?= $this->Layout()->header ?>
</div>
<div id='main'>
<?= $this->Layout()->main ?>
</div>
<div id='footer'>
<?= $this->Layout()->footer ?>
</div>
and so on and so forth. Now, in order to keep my code in my header separate from the code of my main and the code of my footer, I've created a folder for my view that holds header.phtml, main.phtml, footer.phtml. I then use this code to assign the content of header.phtml into $this->layout()->header:
(INDEX.PHTML)
$this->Layout()->header = file_get_contents('index/header.phtml');
$this->Layout()->main = file_get_contents('index/main.phtml');
$this->Layout()->footer = file_get_contents('index/footer.phtml');
That was working great, but I've hit a point where I don't want main to be static HTML anymore. I would like to be able to insert some values with PHP. So in my Controller in indexAction, I want to be able to load from my database and put values into index/main.phtml. Is there a way to do this without restructuring my site?
If not is there a way to do it so that I can have:
The ability to put code into different sections of my layout, such as Layout()->header, Layout->footer.
Separate these pieces into different files, so that they're easy to find and organize, like my index/footer.phtml, index/main.phtml etc.
Not have to put that code into quotes unnecessarily to turn it into a string to pass it to Layout()->header etc.
Thank you guys so much for your help.
-Ethan
Here is an idea:
Assign layout()->header the filename instead of the contents.
Put your code in this file
In your layout file, include() or require() the layout->header().
Since your layout headers/footers are now parsed, you can use them just like a view.
The ->header in $this->layout()->header is response segment. You can render parts of response using $this->_helper->viewRenderer->setResponseSegment('header'); in an action.
If you use
$this->layout()->header = $this->render('index/header.phtml');
It will even use the view, therefore keeping all your variables defined when rendering the header.
I would suggest using something like
<?php echo ($header = $this->layout()->header)?
$header : $this->render('headerDefault.phtml'); ?>
in your layout file - it will render a default header from the layout folder if the view script doesn't override it.
Have you tried looking at view helpers. They are a way of structuring view logic into reusable and modular code. In this case you would use a view helper to generate each of your required segments. So your example view script would look like
$this->Layout()->header = $this->header();
$this->Layout()->main = $this->main();
$this->Layout()->footer = $this->footer();
The benefit of using view helpers over include and require statements is that all of the file handling and name resolution is handled by the framework. The manual has more information on how to set up the paths and usage examples etc.
helpers are good. Another option is like the above, putting filenames in header/footer - put the template names and use $this->render($this->layout()->header)), etc etc. This is just like the include/require above, but more consistent.

Categories