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>
Related
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 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 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>