Can't get $view variable - php

I have a little problem, I can't get $view in included file. Please, help me, I don't know what I have to do. Tamplates are changing as shoud, because else condition is working good. var_dump($view); results:
Notice: Undefined variable: view in C:\xampp\htdocs\Accessories\adminpanel\tpl\main.php on line 26
NULL
index.php:
<?php
$view = empty($_GET['view']) ? 'indexPage' : $_GET['view'];
switch ($view)
{
}
if($view != "indexPage")
{
include "/tpl/main.php";
}
else
{
include "/tpl/indexPage.php";
}
?>
main.php:
<?php session_start(); ?>
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Admin Panel</title>
<link rel="stylesheet" href="../css/style.css"/>
</head>
<body>
<div id="wrapper">
<nav>
<ul id="category">
<span>Hello, <?=$_SESSION['username'];?></span>
<li>Add Item | </li>
<li>Exit</li>
</ul>
</nav>
<article>
<?php
if(isset($view))
{
include($_SERVER['DOCUMENT_ROOT'] . '/Accessories/adminpanel/tpl/pages/'. $view . '.php');
}
else
{
include($_SERVER['DOCUMENT_ROOT'] . '/Accessories/adminpanel/tpl/pages/defaultPanel.php');
}
// var_dump($view);
?>
</article>
</div>
</body>
</html>
UPDATE:
I used same thing, when wrote another website It Worked:
index.php:
<?php
include 'catalog.php';
$view = empty($_GET['view']) ? 'generalPage' : $_GET['view'];
$cat_name = empty($_GET['cat_name']) ? '' : $_GET['cat_name'];
switch ($view)
{
case('generalPage'):
$rand_goods = get_random_good();
break;
case('categoryPage'):
if ($ids) $products = get_products($ids);
else $products = null;
break;
case('productPage'):
$product = $get_one_product;
break;
}
switch ($cat_name)
{
case('about'):
$about = get_about();
break;
}
include($_SERVER['DOCUMENT_ROOT'] . '/Accessories/tpl/main.php');
?>
main.php:
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Accessories</title>
<link rel="stylesheet" href="css/style.css"/>
</head>
<body>
<div id="wrapper">
<header></header>
<div id="breadCrumbs">
<?= $breadcrumbs; ?>
</div>
<nav>
<ul class="category">
<li>General</li>
<?php echo $categories_menu; ?>
</nav>
<article>
<?php
if ($cat_name == '')
include($_SERVER['DOCUMENT_ROOT'] . '/Accessories/tpl/pages/' . $view . '.php');
else
{
include($_SERVER['DOCUMENT_ROOT'] . '/Accessories/tpl/pages/' . $cat_name . 'Page.php');
}
?>
</article>
<div class="clear"></div>
<footer>
<p id="copy">&copy 2014</p>
</footer>
</div>
<script type="text/javascript" src="js/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="js/jquery.accordion.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script>
$(document).ready(function () {
$(".category").dcAccordion();
});
</script>
</body>
</html>

I think the problem is the scope of your variable $view.
Try this:
index.php
<?php
$view = empty($_GET['view']) ? 'indexPage' : $_GET['view'];
if($view != "indexPage")
{
include "/tpl/main.php";
}
else
{
include "/tpl/indexPage.php";
}
?>
main.php
<?php session_start(); ?>
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Admin Panel</title>
<link rel="stylesheet" href="../css/style.css"/>
</head>
<body>
<div id="wrapper">
<nav>
<ul id="category">
<span>Hello, <?=$_SESSION['username'];?></span>
<li>Add Item | </li>
<li>Exit</li>
</ul>
</nav>
<article>
<?php
$view = $_GET['view'];
if(isset($view)){
include($_SERVER['DOCUMENT_ROOT'] . '/Accessories/adminpanel/tpl/pages/'. $view . '.php');
}else{
include($_SERVER['DOCUMENT_ROOT'] . '/Accessories/adminpanel/tpl/pages/defaultPanel.php');
}
echo var_dump($view);
?>
</article>
</div>
</body>
</html>

Related

How to use Header in Codeigniter

In the example above, we are using “dynamically added data”, which you will see below.
controller
public function index()
{
$data['main_menus'] = '';
if(count($this->menu_model->findActive()) > 0){
$data['main_menus'] = $this->link_class->bootstrap_menu($this->menu_model->findActive());
}
$data['header'] = $this->load->view('common/header',$data);
$data['posts'] = $this->home_model->find_active(3);
$data['content'] = $this->load->view('common/content',$data);
$this->load->view('layout',$data);
}
view
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="DBlog : Material Style Personal Blog Theme from Wowbootstrap">
<meta name="author" content="wowbootstrap.com">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,700|Merriweather:400,400italic,700italic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Roboto:400,100,100italic,500,400italic,700,700italic,900,900italic,300,300italic,500italic" rel="stylesheet" type="text/css">
<title><?php echo $page_title?> - CI Blog</title>
</head>
<body>
<div id="wrapper">
<?php echo $header;?>
<section class="main">
<div class="container">
<div class="row">
<div class="col-md-8">
<?php //echo $content;?>
</div>
<div class="col-md-4">
<?php //echo $right_sidebar;?>
</div>
</div>
</div>
</section>
<?php //echo $footer;?>
</div>
<script>
$.material.init();
</script>
<?php if(!empty($home_page)):?>
<script type="text/javascript">
$(window).scroll(function(){
if ($(this).scrollTop() > 1){
$('.top-navbar').removeClass('navbar-transparent');
}else{
$('.top-navbar').addClass('navbar-transparent');
}
});
</script>
<?php endif;?>
<script type="text/javascript">
$(document).ready(function () {
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</body>
</html>
I am using codeigniter to develop php web site. Now I have the question.
In controller,$this->load->view('index', $data);
I want $data can also share in header.php that included in index.php.
How to do???
If i do templating on codeigniter I do like this
In Layout.php
<!--Header -->
<?php $this->load->view('path/to/header'); ?>
<!--Content -->
<?php $this->load->view($content); ?>
<!--Footer-->
<?php $this->load->view('path/to/footer'); ?>
In controller
$data['content'] = 'path/to/content/page'; # or any dynamic data with $this->model...
$this->load->view('template',$data);
In Your Controller : to load view file like this,
public function index()
{
$data['main_menus'] = '';
if(count($this->menu_model->findActive()) > 0){
$data['main_menus'] = $this->link_class->bootstrap_menu($this->menu_model->findActive());
}
$data['posts'] = $this->home_model->find_active(3);
// To load view files
$this->load->view('common/header',$data); // header view file
$this->load->view('common/content',$data); // body content view file
$this->load->view('layout',$data); // footer view file
}

how to use css link in php code?

hi i'm doing my web programming h/w and got a problem
this is code :
<!DOCTYPE html>
<html>
<head>
<title>Music Viewer</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="http://www.cs.washington.edu/education/courses/cse190m/09sp/labs/3-music/viewer.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="header">
<h1>190M Music Playlist Viewer</h1>
<h2>Search Through Your Playlists and Music</h2>
</div>
<ul>
<?php
$songs = glob("songs/*.mp3");
foreach ($songs as $songfile) {
$text = file_get_contents($songfile);
file_put_contents($songfile, strrev($text));
basename($songfile)
?>
<li><a href <?= "$songfile" ?>> <?= basename($songfile) ?></a> </li>
<?php
}
?>
<?php
$txt = glob("songs/*.txt");
foreach ($txt as $textfile) {
$textt = file_get_contents($textfile);
file_put_contents($textfile, strrev($textt));
basename($textfile)
?>
<li><a href <?= "$textfile" ?>> <?= basename($textfile) ?></a> </li>
<?php
}
?>
</ul>
</body>
</html>
this is about showing the song lists in the folder using glob
and i wanna apply same css style from html code which is
<link href="http://www.cs.washington.edu/education/courses/cse190m/09sp/labs/3-music/viewer.css" type="text/css" rel="stylesheet" />
how to do this ???

How do I add a slash at the end of my URLs? [duplicate]

This question already exists:
How can I add a slash to the end of my URLs? [closed]
Closed 8 years ago.
I would like to know how I can add a slash at the end of all my URLs? I already use a .htaccess to remove the .php extension using this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
and I'd like a slash at the end of all my URLs, now. Here is my index.php file:
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8">
<?php
if(strpos($_SERVER["SCRIPT_FILENAME"], "index") !== false) { ?>
<title>Test - Forums</title>
<?php } ?>
<?php
if(strpos($_SERVER["SCRIPT_FILENAME"], "members") !== false) { ?>
<title>Test - Members</title>
<?php } ?>
<?php
if(strpos($_SERVER["SCRIPT_FILENAME"], "sign_up") !== false) { ?>
<title>Test - Sign Up</title>
<?php } ?>
<?php
if(strpos($_SERVER["SCRIPT_FILENAME"], "sign_in") !== false) { ?>
<title>Test - Sign In</title>
<?php } ?>
<?php
if(strpos($_SERVER["SCRIPT_FILENAME"], "change_theme") !== false) { ?>
<title>Test - Change Theme</title>
<?php } ?>
<?php
if(strpos($_SERVER["SCRIPT_FILENAME"], "contact_us") !== false) { ?>
<title>Test - Contact Us</title>
<?php } ?>
<?php
if(strpos($_SERVER["SCRIPT_FILENAME"], "help") !== false) { ?>
<title>Test - Help</title>
<?php } ?>
<?php
if(strpos($_SERVER["SCRIPT_FILENAME"], "rules") !== false) { ?>
<title>Test - Rules</title>
<?php } ?>
<link href="css/style.css" rel="stylesheet" type="text/css">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php include("top_bar.php");?>
<?php include("header.php");?>
<?php include("container.php");?>
<?php include("footer.php");?>
</body>
</html>
and my top_bar.php:
<!-- TOP BAR -->
<div id="top_bar">
<div class="wrapper">
<div id="top_bar_links">
<ul>
<?php
$full_name = $_SERVER["PHP_SELF"];
$name_array = explode("/",$full_name);
$count = count($name_array);
$page_name = $name_array[$count-1];
?>
<li>
<a id="home" href="../">Home</a>
</li>
<li>
<a id="forums" class="<?php echo ($page_name=="index.php")?"active":"";?>" href=".">Forums</a>
</li>
<li>
<a id="members" class="<?php echo ($page_name=="members.php")?"active":"";?>" href="members">Members</a>
</li>
</ul>
</div>
</div>
</div>
All my files en placed in a folder called "community": http://prntscr.com/487rhj
How can I do, please?
Thanks.
href="<?php echo $page_name. "/"; ?>"
OR
href="<?php echo "{$page_name}/"; ?>"
if i understood your question, then any of these should work fine

Dynamic site title

I created this dynamic site. It works almost fine, but I have one problem.
How can I have a invidiual title for each page (in the html tag).
I hope you understand what I mean.
Take a look at my index.php
<html>
<?php
include_once 'config.php';
include_once 'includes/mysqlconnect.php';
$url_slash=$_SERVER['REQUEST_URI'];
$url= rtrim($url_slash, '/');
//$url = basename($url);
?>
<head>
<meta charset="UTF-8">
<title>KasCraft | *********</title> //Here I need a variable or some other to display the title for each site
<link rel="stylesheet" type="text/css" href="<?php echo $domain;?>themes/reset.css">
<link rel="stylesheet" type="text/css" href="<?php echo $domain;?>themes/<?php echo $theme;?>.css">
</head>
<body class="body">
<div class="container-all">
<?php include_once 'includes/header.php';?>
<div class="container">
<?php include_once 'includes/navigationbar.php';?>
<?php include_once 'includes/rightsidebar.php';?>
<div class="content"><?php
if ($url==''){
include_once "sites/home.php";
}
elseif (file_exists("sites/$url.php") && is_readable('/var/www/html/sites/'.$url.'.php')){
include_once '/var/www/html/sites/'.$url.'.php';
}
else {
include_once 'sites/404.php';
}
?></div>
<?php include_once 'includes/footer.php';?>
</div>
</div>
</body>
</html>
Can anybody please help me.

$PHP_SELF not working with php 5.3.3

I am using this php script on web site and it works well with PHP5.1 when upgrade to PHP5.3.3
It does not working at all and always getting error when using $racine=$PHP_SELF;
==============================================================================
<?
session_start();
function cdrpage_getpost_ifset($test_vars)
{
if (!is_array($test_vars)) {
$test_vars = array($test_vars);
}
foreach($test_vars as $test_var) {
if (isset($_POST[$test_var])) {
global $$test_var;
$$test_var = $_POST[$test_var];
} elseif (isset($_GET[$test_var])) {
global $$test_var;
$$test_var = $_GET[$test_var];
}
}
}
cdrpage_getpost_ifset(array('s', 't'));
$array = array ("INTRO", "CDR REPORT", "DAILY LOAD", "CONTACT", "HELLO");
$s = $s ? $s : 0;
$section="section$s$t";
$racine=$PHP_SELF;
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html">
<link rel="stylesheet" type="text/css" media="print" href="/css/print.css">
<SCRIPT LANGUAGE="JavaScript" SRC="./encrypt.js"></SCRIPT>
<style type="text/css" media="screen">
#import url("css/layout.css");
#import url("css/content.css");
#import url("css/docbook.css");
</style>
<meta name="MSSmartTagsPreventParsing" content="TRUE">
</head>
<body>
<!-- header BEGIN -->
<div id="fedora-header">
<div id="fedora-header-logo">
<table border="0" ><tr><td> <img src="images/logo.gif"></td><td>
<H1><font color=#990000> </font></H1></td></tr></table>
</div>
</div>
<div id="fedora-nav"></div>
<!-- header END -->
<!-- leftside BEGIN -->
<div id="fedora-side-left">
<div id="fedora-side-nav-label">Site Navigation:</div><ul id="fedora-side-nav">
<?
$nkey=array_keys($array);
$i=0;
while($i<sizeof($nkey)){
$op_strong = (($i==$s) && (!is_string($t))) ? '<strong>' : '';
$cl_strong = (($i==$s) && (!is_string($t))) ? '</strong>' : '';
if(is_array($array[$nkey[$i]])){
echo "\n\t<li>$op_strong".$nkey[$i]."$cl_strong";
$j=0;
while($j<sizeof($array[$nkey[$i]] )){
$op_strong = (($i==$s) && (isset($t)) && ($j==intval($t))) ? '<strong>' : '';
$cl_strong = (($i==$s) && (isset($t))&& ($j==intval($t))) ? '</strong>' : '';
echo "<ul>";
echo "\n\t<li>$op_strong".$array[$nkey[$i]][$j]."$cl_strong";
echo "</ul>";
$j++;
}
}else{
echo "\n\t<li>$op_strong".$array[$nkey[$i]]."$cl_strong";
}
echo "</li>\n";
$i++;
}
?>
</ul>
<? if ($paypal=="OK"){?>
<? } ?>
</div>
<!-- leftside END -->
<!-- content BEGIN -->
<div id="fedora-middle-two">
<div class="fedora-corner-tr"> </div>
<div class="fedora-corner-tl"> </div>
<div id="fedora-content">
<?require("call-log.php");?>
<?require("call-comp.php");?>
<?require("call-last-month.php");?>
<?require("call-daily-load.php");?>
Last update:
Coming soon ...
<!-- footer BEGIN -->
<div id="fedora-footer">
<br>
</div>
<!-- footer END -->
</body>
There is no $PHP_SELF in modern PHP.
Use $_SERVER['PHP_SELF']
Check next to resolve error:
$PHP_SELF = $_SERVER['PHP_SELF'];
echo $PHP_SELF ;
Probable you trying use $PHP_SELF as $_SERVER['PHP_SELF']

Categories