I'm trying to display some images using the background url in CSS but is not working. I put this code in one of my CSS selector
background:url(../assets/images/teksture2.png);
and view code
<!doctype html>
<html lang="en">
<head>
<meta content-type: "text/css" charset="UTF-8">
<title>Aplikasi Inventori Barang</title>
<link rel="stylesheet" href="<?php echo base_url("assets/css/layout.css");?>">
</head>
<body>
<div id="header">
<div class="image"><img src="<?php echo base_url("assets/images/logo.png");?>" alt="logo"></div>
</div>
</body>
</html>
and in controller file is
<?php
/**
*
*/
class Home extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->helper('url');
$this->load->view('index');
}
}
?>
can you help me solve this problem?
Hope css and images folders exist inside the asset folder. Then in your css file, you have to use below code.
background:url(../images/teksture2.png);
Related
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 a strange problem. Im usining Codeigniter with MaterializeCSS. I want to create navs to create menu. The problem is when I use localhost/page everything works fine, navbars are visible, but When I'll use a site.url, page looks like materalize is not included. I don't know what to do. I can quess there is something with URL in browser
Controller:
class main extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->view('head');
$this->load->view('index');
}
public function index()
{
$this->load->model('quiz_model');
$data['result'] = $this->quiz_model->get_data();
$this->load->view('content/quiz', $data);
}
public function addquestion()
{
$this->load->view('content/addquestion');
}
}
index.php
<?php
$this->load->helper('html');
$this->load->helper('url');
?>
<nav>
<div class="nav-wrapper">
Logo
<ul id="nav-mobile" class="right hide-on-med-and-down">
<?php echo '<li>web page</li>' ?>
<?php echo '<li>Dodaj pytanie</li>' ?>
</ul>
</div>
</nav>
head.php
<!DOCTYPE html>
<html>
<head>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
<title>Strona</title>
</head>
<body>
<div class="container">
You need to set the base url you have IP showing in url.
config/config.php
$config['base_url'] = 'http://localhost/yourprojectname/';
You need to change few line :
Controller :
...
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('url'); // move url helper here, so it could be used on head view
$this->load->view('head');
$this->load->view('index');
}
...
head.php :
<!DOCTYPE html>
<html>
<head>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="<?php echo site_url() ?>css/materialize.min.css" media="screen,projection"/>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>js/materialize.min.js"></script>
<title>Strona</title>
</head>
<body>
<div class="container">
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>
When I go to :
codeigniter/index.php
Bootstrap styles load fine. Actually is the content from
codeigniter/application/views/frontpage.php :
<div class="container">
<div class="hero-unit">
<h2>CodeIgniter Bootstrap</h2>
<p>CodeIgniter Bootstrap kick starts the development process of the web development process by including Twitter Bootstrap into CodeIgniter. It also includes certain libraries such as AWS and Facebook in-case you are developing applications requiring those SDKs. So stop writing the same code over again and start working on your idea.</p>
<a class="btn btn-primary btn-large" href="https://github.com/sjlu/CodeIgniter-Bootstrap">View on Github</a>
</div>
</div>
The problem is that when I copy-paste the same content into my own file
codeigniter/application/views/index.php
It does not load correctly. My controller looks like this:
<?php
class Cart extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('cart_model'); // Load our cart model for our entire class
}
function index()
{
$data['products'] = $this->cart_model->retrieve_products(); // Retrieve an array with all products
$data['content'] = 'products'; // Select our view file that will display our products
$this->load->view('index', $data); // Display the page with the above defined content
}
}
/* End of file cart.php */
/* Location: ./application/controllers/cart.php */
and the frontpage controller is:
<?php if (!defined('BASEPATH')) die();
class Frontpage extends Main_Controller {
public function index()
{
$this->load->view('include/header');
$this->load->view('frontpage');
$this->load->view('include/footer');
}
}
/* End of file frontpage.php */
/* Location: ./application/controllers/frontpage.php */
Use base_url() like
<link href="<?php echo base_url();?>assets/css/bootstrap.css" rel="stylesheet">
I solved by including header and footer in the index() method of controller:
function index()
{
$data['products'] = $this->cart_model->retrieve_products(); // Retrieve an array with all products
$data['content'] = 'products'; // Select our view file that will display our products
$this->load->view('include/header');
$this->load->view('index', $data); // Display the page with the above defined content
$this->load->view('include/footer');
}
include/header.php adds all the bootstrap stuff
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="">
<title>Car application</title>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
<link href="//netdna.bootstrapcdn.com/font-awesome/3.1.1/css/font-awesome.min.css" rel="stylesheet">
<link href="<?php echo base_url('assets/css/custom.css') ?>" rel="stylesheet">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.2.1/lodash.min.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
<script src="<?php echo base_url('assets/js/custom.js') ?>"></script>
</head>
<body>
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?