How to display one view in another view page - php

i have this below code where i want to display only "Welcome to my 3rd Blog!" of "blogvieww.php" in
"blogview.php" using codegniter. But the below code what i tried with is that, even "Welcome to my 2nd Blog!" of "blogvieww.php" is getting displayed in "blogview.php".
actually i just want to display only "Welcome to my 3rd Blog!", how to do this can any one tel me please im not getting where im going wrong.
Blogcontroller.php(controller file)
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Blogcontroller extends CI_Controller {
public function index()
{
$data['blogvieww'] = $this->load->view('blogvieww', '', TRUE);
$this->load->view('blogview', $data);
}
public function blogvieww()
{
$this->load->view('blogvieww');
}
}
?>
blogview.php (view file)
<html>
<head>
<title>My Blog</title>
</head>
<body>
<div>
<div><?php echo $blogvieww; ?></div>
<h1>Welcome to my 1st Blog!</h1>
</div>
</body>
</html>
blogvieww.php (view file)
<html>
<head>
<title>My Blog</title>
</head>
<body>
<div>
<h1>Welcome to my 2nd Blog!</h1>
</div>
<div>
<h1>Welcome to my 3rd Blog!</h1>
</div>
</body>
</html>

Your can do simply using $this->load-view('view_name'), like following :
view1.php
<p>View 1</p>
view2.php
<html>
<head>
<title>My Blog</title>
</head>
<body>
<div>
// Load View 1
<?php $this->load->view('view1'); ?>
<h1>Welcome to my 1st Blog!</h1>
</div>
</body>
</html>

I am not sure what you want, but you can anytime to var_dump the value of $data['blogvieww'], and if you want make a view section, don't use double tag

Related

Remove script tag from url YII 1.17

I have a yii 1.17 application. Problem is any one can inject scripts in url. Ex: If user puts this after page url ?redir=%3C/SCript%3E%3CsvG/onLoad=prompt(7)%3E application gives popup with given message.
How can i avoid this?
Main Layout:
<html lang="en">
<head>
</head>
<body>
<?php ?>
<app-header></app-header>
<md-content id="wrapper" layout-fill layout-margin layout-padding>
<section class="grid_outer">
<?php echo CHtml::encode($content); ?>
<div class="md-grid-container md-grid-padding">
</div>
</section>
<app-footer></app-footer>
</md-content>
</body>
</html>
View File:
<app-login></app-login>

view in another view page not getting displayed

I want to display Welcome to my 3rd Blog! of blogvieww.php in
blogview.php using codegniter.
But in the code below, what I've tried is that even Welcome to my 2nd Blog! of blogvieww.php is getting displayed in blogview.php.
Actually I just want to display only Welcome to my 3rd Blog!, how to do this can any one tell please tell me where my mistake was?
Blogcontroller.php(controller file)
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Blogcontroller extends CI_Controller {
public function index()
{
$data['blogvieww'] = $this->load->view('blogvieww', '', TRUE);
$this->load->view('blogview', $data);
}
public function blogvieww()
{
$this->load->view('blogvieww');
}
}
?>
blogview.php (view file)
<html>
<head>
<title>My Blog</title>
</head>
<body>
<div>
<div><?php echo $blogvieww; ?></div>
<h1>Welcome to my 1st Blog!</h1>
</div>
</body>
</html>
blogvieww.php (view file)
<html>
<head>
<title>My Blog</title>
</head>
<body>
<div><h1>Welcome to my 2nd Blog!</h1></div>
<div><h1>Welcome to my 3rd Blog!</h1></div>
</body>
</html>
Change in your blogview.php
<html>
<head>
<title>My Blog</title>
</head>
<body>
<div>
<div><?php echo $data->blogvieww; ?></div>
<h1>Welcome to my 1st Blog!</h1>
</div>
</body>
</html>

how to call a section of one view page in to another view page?

how can i display only "Welcome to my 3rd Blog!" of "blogvieww.php" in
"blogview.php" using codegniter. But the below code what i tried with is that, even "Welcome to my 2nd Blog!" of "blogvieww.php" is getting displayed in "blogview.php".
actually i just want to display only "Welcome to my 3rd Blog!", how to do this can any one tel me please im not getting where im going wrong.
Blogcontroller.php(controller file)
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Blogcontroller extends CI_Controller {
public function index()
{
$data['blogvieww'] = $this->load->view('blogvieww', '', TRUE);
$this->load->view('blogview', $data);
}
public function blogvieww()
{
$this->load->view('blogvieww');
}
}
?>
blogview.php (view file)
<html>
<head>
<title>My Blog</title>
</head>
<body>
<div>
<div><?php echo $blogvieww; ?></div>
<h1>Welcome to my 1st Blog!</h1>
</div>
</body>
</html>
blogvieww.php (view file)
<html>
<head>
<title>My Blog</title>
</head>
<body>
<div>
<h1>Welcome to my 2nd Blog!</h1>
</div>
<div>
<h1>Welcome to my 3rd Blog!</h1>
</div>
</body>
</html>

Codeigniter best way to handle controller calling views

i just want to know if this is a good way in adding fragmented views.
lets say "header.php" is like this
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Admin Theme v3</title>
some links..
</head>
</html>
then "body.php" is like this
<!DOCTYPE html>
<html>
<body>
lots of stuff..
</body>
</html>
lastly "scripts.php"
<!DOCTYPE html>
<html>
<body>
some scripts..
</body>
</html>
then in my "MyController.php"
$this->load->view('header');
$this->load->view('body');
$this->load->view('scripts');
The best way I find is create a default view.
views > default_view.php
views > includes > header_view.php
views > includes > footer_view.php
views > information > contact_view.php
On that view
<?php
$this->load->view('includes/header_view');
$this->load->view($content_page);
$this->load->view('includes/footer_view');
?>
Then on the controller to load view this way you do not have to load the header and footer views all the time.
Following the Codeigniter StyleGuide
Filename: Example.php
<?php
class Example extends CI_Controller {
public function index() {
// Add any other variables
$data['content_page'] = 'information/contact_view'; // This will be your content page example
$this->load->view('default_view', $data);
}
}
There are too many redundant tag like <html>,<body> try separate it
header.php
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Admin Theme v3</title>
some links..
</head>
<body>
body.php
lots of stuff..
scripts.php or footer.php
some scripts..
</body>
</html>
It is not good way. Except in some cases (using frames for example), document should have just one declaration and one pair of open/closed html tag.
It could be something like:
header.php
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Admin Theme v3</title>
some links..
</head>
<body>
some_page.php
<div class="container">
<div class="row">
//some stuff and forms here
</div>
</div>
footer.php
<div class="footer">
//©2016
</div>
</body>
</html>

Phalcon - add css assets collection

I have a problem to add css assets to the collection called from view layout.phtml
This is my code:
<?php echo $this->tag->getDoctype() ?>
<html>
<head>
<?php $this->assets->outputCss('header') ?>
</head>
<body>
<?php $this->assets->get('header')->addCss('test.css'); ?>
<?php $this->assets->get('footer')->addJs('test.js'); ?>
<?php $this->assets->outputJs('footer') ?>
</body>
</html>
And this is output in browser:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type="text/javascript" src="/test.js"></script>
</body>
</html>
Why is not the output of CSS tag in the head?
The Assets component basically works like this:
You add your assets to the service in your controller action (because that's where the application logic is supposed to reside)
In your view, you can then access the Assets component and request the output of single assets or an entire asset group
Suppose the view you mentioned is displayed via this controller:
use Phalcon\Mvc\Controller;
class IndexController extends Controller
{
public function index()
{
// Add your header assets here
$this->assets
->collection('header')
->addCss('test.css');
// Add your footer assets here
$this->assets
->collection('footer')
->addJs('test.js');
}
}
Now your view should look like this:
<?php echo $this->tag->getDoctype() ?>
<html>
<head>
<?php $this->assets->outputCss('header') ?>
</head>
<body>
<?php $this->assets->outputJs('footer') ?>
</body>
</html>

Categories