How to properly insert a Bootstrap navbar in a Codeigniter view? - codeigniter

I'm learning to develop with CodeIgniter and would like a help to know how to properly insert a navbar in a view. I need to know which directory to save the navbar file and how to call this file in a view.
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title><?php echo $produto['nome']; ?></title>
<!-- link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" -->
<link rel="stylesheet" href="<?php echo base_url("assets/css/bootstrap.min.css"); ?>">
</head>
<body>
I need navbar here (This is a home view)
<div class="container">
<div class="row">
<div class="col-md-12">
<?php echo $produto['nome']; ?>
<?php echo $produto['preco']; ?>
<?php echo $produto['descricao']; ?>
</div>
</div>
</div>
</body>
</html>

You can try create a template folder inside views folder and put some files like header.php, nav.php, footer.php. Inside your main view you can use like $this->load->view('template/nav);.
UPDATED
This is the typical of header.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
...
<title>Put_your_title_here</title>
<link rel="stylesheet" href="<?php echo base_url('css/bootstrap.min.css'); ?>">
...
</head>
<body>
<!-- depends on your template design -->
<div class="dashboard-wrapper">
<div class="main-content">
<?php $this->load->view('template/nav.php'); ?>
footer.php
<footer>Some footer content</footer>
</div><!-- /.main-content -->
</div><!-- /.dashboard-wrapper -->
<!-- Core Scripts - Include with every page -->
<script src="<?php echo base_url('js/jquery.min.js'); ?>"></script>
<script src="<?php echo base_url('js/bootstrap.min.js'); ?>"></script>
</body>
</html>
nav.php
<div class="navbar navbar-default" role="navigation">
...
</div>
Let say that your Controller (in this case Welcome.php) load a view like this:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function home()
{
$data['message'] = 'Welcome to My Website';
$this->load->view('welcome', $data);
}
}
welcome.php
<?php $this->load->view('template/header'); ?>
<p><?php echo $message; ?></p>
<?php $this->load->view('template/header'); ?>
NOTE Avoid echoing something directly from controller except some particular situation that force you to do so

Related

why Laravel #yield and #section not wokring?

I have Master as a main page where I load dynamic pages.
Master
<!DOCTYPE html>
<html lang="en">
<head>
#include('backend.includes.header')
#yield('style')
</head>
<body>
#include('backend.includes.navbar')
<div class="mobile-menu-overlay"></div>
#yield('content')
#yield('script')
</body>
</html>
Dashboard
#extends('backend.master.master')
#section('style')
<link rel="stylesheet" href="{{ asset('backend/css/apexcharts.css') }}">
#stop
#section('content')
// Dashboard Code here
#endsection
#section('script')
<script src="{{ asset('backend/js/dashboard.js') }}"></script>
#endsection
It doesn't render #yield('style') and #yield('script')
Also my controller:
public function index(){
return view('backend.pages.home.dashboard');
}

how to get the parameter value from the query string in codigniter

I am new to codeigniter. I am passing a id in a href tag. I want this id to be diplayed in the controller. can any one please help me out. I have seen the similar question in stack overflow and I have tried the all the ways but none is working. can anyone help me out please.
Mycontroller
<?php
/**
*
*/
class Url extends CI_Controller
{
public function menu1( $product_id;)
{
echo $product_id;
// $data1 = $this->uri->segment(4);
// $id['data'] =$data1;
// $this->load->view('menu1',$id);
//$this->input->get('id', TRUE);
}
public function menu2()
{
$this->load->view('menu2');
}
public function menu3()
{
$this->load->view('menu3');
}
}
?>
View file
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="<?php echo base_url('assets/lib/bootstrap/css/bootstrap.min.css'); ?>" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-4">
<ul class="">
<?php $id=1;
?>
<li>menu1</li>
<li>menu2</li>
<li>menu3</li>
</ul>
</div>
<div class="col-md-4">
<div id="body" class="col-lg-12" >
</div>
</div>
</div>
</div>
</body>
<script type="text/javascript" src="<?php echo base_url('assets/lib/jquery/jquery-1.11.2.min.js'); ?>"></script>
<script type="text/javascript" src="<?php echo base_url('assets/lib/bootstrap/js/bootstrap.min.js'); ?>"></script>
<script>
$(function()
{
$('.update').click(function(event)
{
event.preventDefault();
//$('.update').removeClass("active");
//$(this).addClass("active");
$('#body').load($(this).attr('href'));
});
});
</script>
</html>
menu1.php
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php echo $data;
?>
</body>
</html>
View:
<li>menu1</li>
Controller:
public function menu1()
{
$data['product_id'] = $this->input->get('id');
// echo $product_id;
$this->load->view('menu1',$data);
}
In order to display the product_id in menu1.php:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php echo $product_id; ?>
</body>
</html>

style.css does not load correctly

This is my code. I wonder why the style sheet does not load up correctly?
admin/views/login.php
<html>
<head>
<meta charset="UTF-8">
<title>CodePen - Log-in</title>
<link rel='stylesheet' href='http://codepen.io/assets/libs/fullpage/jquery-ui.css'>
<link rel="stylesheet" href="<?php echo base_url(''); ?>assets/style.css" media="screen" type="text/css" />
</head>
<body>
<br><br><br><br><br><br>
<?php $this->load->library('form_validation'); ?>
<?php echo validation_errors(); ?>
<?php echo form_open('cpages/ceklogin'); ?>
<div class="login-card">
<center><?php //echo $warning; ?>
<?php echo $this->session->flashdata('warning'); ?>
</center>
<h2>Gionda CMS Login</h2><br>
<form>
<div class="login"><input type="text" name="username" placeholder="Username"></div>
<div class="login"><input type="password" name="password" placeholder="Password"></div>
<br>
<input type="submit" name="login" class="login login-submit" value="login">
</form>
<div class="login-help">
Register • Forgot Password
</div>
</div>
<!-- <div id="error"><img src="https://dl.dropboxusercontent.com/u/23299152/Delete-icon.png" /> Your caps-lock is on.</div> -->
<script src='http://codepen.io/assets/libs/fullpage/jquery_and_jqueryui.js'></script>
admin/config/config.php
$config['base_url'] = 'http://localhost/masterlinkci2/admin/';
1.Load url helper in application/config/autoload.php.
$autoload['helper'] = array('url');
2.Then set base_url to url as your root folder.
$config['base_url'] = 'http://localhost/masterlinkci2/';
3.And link your css like this.
<link rel="stylesheet" href="<?php echo base_url('assets/style.css');?>" media="screen" type="text/css" />
Hope it works..
Hey you need to add the path into your baseurl function parameters and not by appending path to it.
<?php echo base_url('') ?>
Instead use the following to add css:
<?php echo base_url('assets/style.css') ?>

How to include bootstrap template in codeigniter

I want to include a bootstrap template on codeigniter code, so i included the template in views folder and then i called it in controller but i can't see the template in my page
Here's my code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootsrtap Free Admin Template - SIMINTA | Admin Dashboad Template</title>
<!-- Core CSS - Include with every page -->
<link href="plugins/bootstrap/bootstrap.css" type="text/css" rel="stylesheet" />
<link href="font-awesome/css/font-awesome.css" type="text/css" rel="stylesheet" />
<link href="plugins/pace/pace-theme-big-counter.css" type="text/css" rel="stylesheet" />
<link href="css/style.css" type="text/css" rel="stylesheet" />
<link href="css/main-style.css" type="text/css" rel="stylesheet" />
</head>
<body class="body-Login-back">
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4 text-center logo-margin ">
<img src="img/logo.png" alt=""/>
</div>
<div class="col-md-4 col-md-offset-4">
<div class="login-panel panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Please Sign In</h3>
</div>
<div class="panel-body">
<form role="form">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="E-mail" name="email" type="email" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" name="password" type="password" value="">
</div>
<div class="checkbox">
<label>
<input name="remember" type="checkbox" value="Remember Me">Remember Me
</label>
</div>
<!-- Change this to a button or input when using this as a form -->
Login
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- Core Scripts - Include with every page -->
<script src="plugins/jquery-1.10.2.js"></script>
<script src="plugins/bootstrap/bootstrap.min.js"></script>
<script src="plugins/metisMenu/jquery.metisMenu.js"></script>
</body>
</html>
this is login.php (in views folder)
---------------
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootsrtap Free Admin Template - SIMINTA | Admin Dashboad Template</title>
<!-- Core CSS - Include with every page -->
</head>
Controller
<?php if ( ! defined('BASEPATH')) exit('No direct access allowed');
class Login extends CI_Controller
{
public function index()
{
$this->load->view('login');
}
}
and this is login.php (in controllers folder)
please help me with this problem
Well first off you should all ways have your assets out side of your application folder.
Because the .htaccess file that is inside the application folder blocks that
project >
project > application
project > assets
project > system
project > index.php
project > .htaccess <!-- use a htaccess here for removing index.php
Second set your base_url in config > config.php
// You are recommend to do so in CI 3 + versions
$config['base_url'] = 'http://localhost/yourprojectname/';
Third Auto load the url helper config > autoload.php
$autoload['helper'] = array('url');
Controller Make sure your class and file name first letter only upper
case
As said here http://www.codeigniter.com/user_guide/general/controllers.html#let-s-try-it-hello-world
Filename Example.php
<?php
class Example extends CI_Controller {
public function index() {
$this->load->view('header');
$this->load->view('example');
$this->load->view('footer');
}
}
Then create a header.php and footer.php and example.php view
http://www.codeigniter.com/user_guide/general/views.html#loading-multiple-views
header.php view
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/bootstrap/css/bootstrap.css');?>">
</head>
<body>
example.php view
Any content you need
footer.php view
<script type="text/javascript" src="<?php echo base_url('assets/bootstrap/js/bootstrap.js');?>"></script>
</body>
</html>
This is an example. Make a folder, that called is assets, paste all style, js resources into it.
Please show you console log tab. Example:

Include php, css and js files from subdomain

so I need to include a couple of files from a subdomain from the main domain (my subdomain is admin.mydomain.com and targets to => mydomain.com/admin/), but I can't get to.
My public_html structure is
-admincp (empty, this is the subdomain)
-css
-js
-includes
-fonts
-images
I need to include all the css, js and some php files (which are in /includes/) in the subdomain index but for some reason it retrieves nothing using "/css/xxx.css".
I've tried using "/home/user/public_html/includes" (or css, or js) and actually worked, but the problem then is the file I need to include (the header for example) is like this:
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="es-ar">
<head>
<meta charset="utf-8" />
<meta name="description" content="<?php echo $meta_description ?>" />
<meta name="author" content="Gaspar Dip" />
<title><?php echo $page_title ?></title>
<link rel="shortcut icon" href="/images/favicon.ico">
<link rel="stylesheet" href="/css/metro-bootstrap.min.css">
<link rel="stylesheet" href="/css/metro-bootstrap-responsive.min.css">
<link rel="stylesheet" href="/css/iconFont.min.css">
</head>
<body class="metro">
<nav class="navigation-bar light">
<div class="navigation-bar-content">
<span class="icon-stats-2"></span> Estudio Benintendi
<span class="element-divider"></span>
<a class="pull-menu" href="#"></a>
<ul class="element-menu">
<li>Inicio<li>
<li>Acerca del estudio<li>
<li>Enviar curriculum<li>
<li>Contactenos</li>
</ul>
<div class="no-tablet-portrait">
<span class="element-divider"></span>
<div class="element input-element">
<form>
<div class="input-control text">
<input type="text" placeholder="Buscar...">
<button class="btn-search"></button>
</div>
</form>
</div>
<?php if(!isset($_SESSION["username"])){ ?>
<ul class="element-menu place-right">
<li>Iniciar sesión</li>
<li>Registrarse</li>
</ul>
<?php }else{ ?>
<div class="element place-right">
<a class="dropdown-toggle" href="#">
<span class="icon-cog"></span>
</a>
<ul class="dropdown-menu place-right" data-role="dropdown">
<li>Products</li>
<li>Download</li>
<li>Support</li>
<li>Salir</li>
</ul>
</div>
<span class="element-divider place-right"></span>
<button class="element place-right">
<span class="icon-user-3"></span>
<?php echo $_SESSION["username"]; ?>
</button>
<?php } ?>
<span class="element-divider place-right"></span>
</div>
</div>
</nav>
<div class="container">
So those links targetting the .css files actually go to admincp.mydomain.com/css/xxx.css instead of mydomain.com/css/xxx.css
Did I explain myself?
Possibly giving the absolute path can make difference.
I mean full path to the css link something like
<link rel="stylesheet" href="<?php echo FULL_PATH_TO_CSS; ?>/css/xxx.css"/>
Can you try this?
<link rel="stylesheet" href="../css/xxx.css"/>
This is not tested.

Resources