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>
Related
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>
I'm not getting how to do this codeignitor concept.
How to redirect one page to another page if I click the link?
Main1.php
<?php
class Main1 extends CI_Controller {
public function index() {
//Load the URL helper
$this->load->helper('url');
//Redirect the user to some site
redirect('http://localhost/CodeIgniter/index.php/Main');
$this->load->view('test1');
}
}
?>
test1.php
<!DOCTYPE html>
<html>
<head>
<title>view page</title>
</head>
<body style="padding-top:50px; padding-left:300px">
<h1 style="color:red"> Without Extension </h1>
Visit With Extension Example
</body>
</html>
Main.php
<?php
class Main extends CI_Controller {
public function index() {
$this->load->view('test.html');
}
}
?>
test.html
<!DOCTYPE html>
<html>
<head>
<title>view page</title>
</head>
<body style="padding-top:50px; padding-left:300px">
<h1 style="color:red"> With Extension </h1>
</body>
</html>
You can use redirect(); something like given below.
redirect('controllerName/methodName','refresh');
OR
if you want to redirect in same controller.
$this->methondName;
Your code should be like this
<?php
class Main1 extends CI_Controller {
public function index() {
//Load the URL helper
$this->load->helper('url');
//Redirect the user to some site
redirect('Main/index','refresh');
}
}
?>
in your Main1.php index function , loading view after redirecting. It is not possible.
Main1.php
class Main1 extends CI_Controller {
public function index() {
//Load the URL helper
$this->load->helper('url');
//display test1 page
$this->load->view('test1');
}
}
?>
test1.php
<!DOCTYPE html>
<html>
<head>
<title>view page</title>
</head>
<body style="padding-top:50px; padding-left:300px">
<h1 style="color:red"> Without Extension </h1>
Visit With Extension Example
</body>
</html>
Main.php
load->view('test.html');
}
}
?>
test.html
<!DOCTYPE html>
<html>
<head>
<title>view page</title>
</head>
<body style="padding-top:50px; padding-left:300px">
<h1 style="color:red"> With Extension </h1>
</body>
</html>
It is a small error..keep going with codeigniter
you can use either
redirect('controllerName/methodName','refresh'); in your controller or if you want to just load the previous page you can use redirect($_SERVER['HTTP_REFERER']);
Suppose you want to redirect from Controller Main1 to Main. Main1 loads the test1.php view, and it should contain a means to redirect from one view to another, like a button or a link. You should have a .php extension instead of .html to utilize php. Consider this as a best practice and you should avoid calling controllers within a controller as a normal practice to conform with MVC in general.
Test1.php
<!DOCTYPE html>
<html>
<head>
<title>view page</title>
</head>
<body style="padding-top:50px; padding-left:300px">
<h1 style="color:red"> With Extension </h1>
Visit With Extension Example
</body>
</html>
If you call Main then the controller will be processed. No need for you to use redirect inside the controller.
<?php
class Main extends CI_Controller {
public function index() {
$this->load->view('test');
}
}
?>
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
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>
I'm developing a web app and I'm having a problem with the templating fase. The problem concerns the generation o html code in a php object. The code is as follows:
<?php class abcHtml {
function prepare() { ?>
<!DOCTYPE html>
<html>
<head>
<?php echo $this->meta; ?>
</head>
<body>
<div id="bg">
<div id="container_wrapper">
<?php echo $this->cont; ?>
</div>
</div>
</body>
</html>
<?php }} ?>
The goal is to have a php file with the cleanest html code possible(Don't want to use any framework).
<?php
class abc extends abcHtml
{
protected $meta;
protected $cont;
public function render(){
return parent::prepare();
}
public function setMeta($meta){
$this->meta = $meta;
return $this;
}
?>
This class inherites abcHtml to make possible to add diferent html modules. The problem is that when calling render(), the returned html code is note in the right order, the html code in the $meta and $cont variables appear before the html that is inside the prepare function.
For example:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="public/css/base_style.css"/>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="bg">
<div id="container_wrapper">
</div>
</div>
</body>
</html>
This problem obviously means that php is running the php code first and then attaching the html. Is there a solution to fix this?