Codeigniter routing help, backlinking to previous directories - php

the site in question is http://www.ziplinegolive.com/
I have built this in CI and currently there is 2 "views" folders
-pages
and
-news
I want to make a news directory to organize my posts and not have them interfere with the other pages. My problem that im having though is once i enter http://www.ziplinegolive.com/news/home I noticed that when i check my header links...all the urls acquire the news/ directory...which doestn allow me to go back.... does anyone know how i can fix this? i currently have one routes config files and 2 controllers.
first here is my routes.php
$route['news/(:any)'] = 'news/view/$1';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';
here is my standard pages controller
<?php
class Pages extends CI_Controller {
public function view($page = 'home')
{
if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
and here is my news controller
<?php
class News extends CI_Controller {
public function view($page = 'home')
{
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('news/'.$page);
$this->load->view('templates/footer', $data);
}
}
ive been busting my head in to try and figure this out.... any help is GREATLY appreciated!
thank you!
UPDATE: ADDED HEADER.PHP - as you can see the css and js files are static linked because of this routing debacle....
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<title>ZipLineā„¢</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="HandheldFriendly" content="true" />
<meta name="apple-touch-fullscreen" content="yes" />
<!-- All Animations CSS -->
<link href="http://www.ziplinegolive.com/css/animate.css" rel="stylesheet" type="text/css">
<!-- Image Lightbox CSS-->
<link rel="stylesheet" href="http://www.ziplinegolive.com/css/imagelightbox.css" type="text/css" media="screen">
<!-- Theme styles and Menu styles -->
<link href="http://www.ziplinegolive.com/css/style.css" rel="stylesheet" type="text/css">
<link href="http://www.ziplinegolive.com/css/mainmenu.css" rel="stylesheet" type="text/css">
<!-- Call Fontawsome Icon Font from a CDN -->
<link href="http://netdna.bootstrapcdn.com/font- awesome/4.1.0/http://www.ziplinegolive.com/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="js/jquery.fancybox.css" type="text/css" media="screen">
<!--FlexSlider -->
<link rel="stylesheet" href="js/woothemes-FlexSlider-06b12f8/flexslider.css" type="text/css" media="screen">
<!--Isotope Plugin -->
<link rel="stylesheet" href="js/isotope/http://www.ziplinegolive.com/css/style.css" type="text/css" media="screen">
<!--Simple Text Rotator -->
<link href="http://www.ziplinegolive.com/css/simpletextrotator.css" rel="stylesheet" type="text/css">
<!--Modernizer Custom -->
<script type="text/javascript" src="js/modernizr.custom.48287.js"></script>
<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="apple-touch-icon-114x114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="apple-touch-icon-72x72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="apple-touch-fa-57x57-precomposed.png">
<link rel="shortcut icon" href="favicon.png">
</head>
<body class="sticky_header">
<div class="overflow_wrapper">
<header>
<div class="container">
<div class="logo"><a class="brand" href="index.html"><img src="http://www.ziplinegolive.com/images/logo.png" alt="optional logo"></a></div>
<!-- MAIN MENU -->
<div id="mainmenu" class="menu_container">
<label class="mobile_collapser">MENU</label>
<!-- Mobile menu title -->
<ul>
<li class="active">Home</li>
<li>About Us
<div class="dmui_dropdown_block">
<ul class="dmui-submenu">
<li>The Company</li>
<li>Media</li>
<li>Partners</li>
</ul>
</div>
</li>
<li>Products and Services</li>
<li>News</li>
<li>Contact</li>
</ul>
</div>
<!-- /MAIN MENU -->
<div class="triangle-up-left"></div>
<div class="triangle-up-right"></div>
</div>
</header>

Change your links.
For example
<li>The Company</li>
=>
<li>The Company</li>
And also, you can link to css/js files like this:
<link href="<?php echo base_url('assets');?>/css/mainmenu.css" rel="stylesheet" type="text/css">
This of course expects that you have your css files in project/assets/css

Related

How can I change title using php?

I have my index.php in which I am including the header. But the problem is that I want a different header title as I am including it in other pages well. I want it to change dynamically according to page like if its other page like shop then title should be Toys - Shop like this. I am new to PHP can anyone please help me with how to do it? Index.php:
<?php include'headernav.php';?>
<div class="header-outs" id="home">
<div class="header-bar">
<div class="info-top-grid">
<div class="info-contact-agile">
<ul>
<li>
<span class="fas fa-phone-volume"></span>
<p>+(000)123 4565 32</p>
</li>
<li>
<span class="fas fa-envelope"></span>
<p>info#example1.com</p>
</li>
<li>
</li>
</ul>
</div>
</div>
</div>
</div>
Headernav.php:
<!DOCTYPE html>
<html lang="zxx">
<head>
<title>Toys-Home</title>
<!--meta tags -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="keywords" content="" />
<link href="css/style.css" rel='stylesheet' type='text/css' media="all">
<!--//stylesheets-->
<link href="//fonts.googleapis.com/css?family=Sunflower:500,700" rel="stylesheet">
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,600,700" rel="stylesheet">
</head>
<body>
You can do something like this:
index.php:
<?php
$pagename = 'Toys-Home';
include ('headernav.php');?>
<div class="header-outs" id="home">
<div class="header-bar">
<div class="info-top-grid">
<div class="info-contact-agile">
<ul>
<li>
<span class="fas fa-phone-volume"></span>
<p>+(000)123 4565 32</p>
</li>
<li>
<span class="fas fa-envelope"></span>
<p>info#example1.com</p>
</li>
<li>
</li>
</ul>
</div>
</div>
</div>
</div>
headernav.php
<!DOCTYPE html>
<html lang="zxx">
<head>
<title><?php print $pagename; ?></title>
<!--meta tags -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="keywords" content="" />
<link href="css/style.css" rel='stylesheet' type='text/css' media="all">
<!--//stylesheets-->
<link href="//fonts.googleapis.com/css?family=Sunflower:500,700" rel="stylesheet">
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,600,700" rel="stylesheet">
</head>
<body>
You'd have to set the $pagename variable on each page if that's something you're looking for. Each page would have the title you've set in that variable.
#Loupeznik's accepted answer provides a solution. An alternative is to use functions in include files and call them from the main PHP. You will have to write a bit more code, but you will get more flexibility. E.g. you will be able to add different css or js files on different pages letter or use a single include file for both header and footer or other common PHP code.
The way to do this is to add a function called writeHeaderNav() or something similar and then call it from index.php with $pagename as an argument.
headernav.php
<?php
function writeHeaderNav($pagetitle){
echo"<!DOCTYPE html>
<html lang='zxx'>
<head>
<title>$pagetitle</title>
<!--meta tags -->
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<meta name='keywords' content='' />
<link href='css/style.css' rel='stylesheet' type='text/css' media='all'>
<!--//stylesheets-->
<link href='//fonts.googleapis.com/css?family=Sunflower:500,700' rel='stylesheet'>
<link href='//fonts.googleapis.com/css?family=Open+Sans:400,600,700' rel='stylesheet'>
</head>
<body>";
}
//you can have other PHP code here if needed
function writeFooter(){
//echo html for common footer
}
?>
index.php
<?php
$pagename = 'Toys-Home';
include ('headernav.php');
writeHeaderNav($pagename);
// or you can use writeHeaderNav('Toys-Home');
?>
<div class="header-outs" id="home">
<!--rest of code-->
You can put a variable like this in your Headernav.php file and have it defined before your include
< title> < ?php echo "$my_title"; ?>
This variable can be changed by the way you get it
from your url ($_GET)
from a sql query
from a session variable
...

Materialize disappear when I will use codeigniter url

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

when i normally run html bootstrap enabled code, it shows proper output but when i load it using codeigniter view it shows different output

This is my directory:
miuse/application
miuse/application/views/templates/header.php
miuse/bootstrap/css
miuse/bootstrap/js
miuse/bootstrap/fonts
This is my controller code:
<?php
class page extends CI_controller{
public function view($page= 'home')
{
if(!file_exists(APPPATH.'views/pages/'.$page.'.php'))
{
show_404();
}
$data['title']='Moodlist home';
$this->load->view('templates/header', $data);
}
}
?>
This is my view code:
<!DOCTYPE html>
<html lang="en">
<head>
<title>
<?php echo $title; ?>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" href="http://localhost/miuse/bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="header.css" type="text/css">
</head>
<body>
<header class="container">
<div class="row">
<h1 class="col-sm-4">List</h1>
<nav class="col-sm-8 text-right">
<p>Home</p>
<p>Category</p>
<p>About us</p>
</nav>
</div>
</header>
</body>
</html>
when i run my view normally in a browser it shows proper output but when i load it with codeigniter view then it shows different output which i dont want.
I guess your header.css file is not being loaded.
Put the header.css file in miuse/bootstrap/css directory.
And change your code from,
<link rel="stylesheet" href="header.css" type="text/css">
to
<link rel="stylesheet" href="http://localhost/miuse/bootstrap/header.css" type="text/css">
When loading css and other stuff I would recommend using base_url() in your head area
<head>
<link rel="stylesheet" type="text/css" href="<?php echo base_url('bootstrap/css/bootstrap.css');?>">
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/css/header.css');?>">
</head>
Make sure you have set the base url in config.php and autoload the url helper.

CSS not apply when move to other URL/route

1- Step one correct work
1 index.blade.php page
<nav class="navigation">
<ul class="sf-menu">
<li>Home
</li>
<li>About Us</li>
<li>Category
<ul class="dropdown">
<li>Buy and Sell</li>
<li>Car and Vehicles</li>
<li>Real Estate</li>
<li>Pets</li>
<li>Jobs</li>
<li>Community</li>
<li>Resumes</li>
</ul>
</li>
2 Route code
Route::resource('/', 'BasicController');
Route::resource('about', 'BasicController#about');
Route::resource('contact', 'BasicController#contact');
Route::resource('grid', 'BasicController#grid');
3 BasicController code
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class BasicController extends Controller
{
public function index()
{
return view('index');
}
public function about()
{
return view('about');
}
public function contact()
{
return view('contact');
}
public function grid()
{
return view('buy-and-sell/grid');
}
public function create()
{
//
}
}
4 view image for help
5 correct work
2- In this step css not work
please help in this step
1 index.blade.php page. grid/1 pass to url and equal to if or elseif statement
<nav class="navigation">
<ul class="sf-menu">
<li>Home
</li>
<li>About Us</li>
<li>Category
<ul class="dropdown">
<li>Buy and Sell</li>
<li>Car and Vehicles</li>
<li>Real Estate</li>
<li>Pets</li>
<li>Jobs</li>
<li>Community</li>
<li>Resumes</li>
</ul>
</li>
2 Route code
Route::resource('/', 'BasicController');
Route::resource('about', 'BasicController#about');
Route::resource('contact', 'BasicController#contact');
Route::resource('grid', 'BasicController#grid');
3 BasicController code
class BasicController extends Controller
{
public function index()
{
return view('index');
}
public function about()
{
return view('about');
}
public function contact()
{
return view('contact');
}
public function grid(Request $request, $id)
{
if ($id == 1) {
return view('buy-and-sell/grid');
}
elseif ($id == 2) {
return view('car-and-vehicels/grid');
}
elseif ($id == 3) {
return view('country/grid');
}
else{
return view('other/grid');
}
}
public function create()
{
//
}
}
4 image for your help
css is not work
Change your scrip src and link href as folloing
<link href="{{ URL::to('/')}}/template/css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="{{ URL::to('/')}}/template/css/style.css" rel="stylesheet" type="text/css">
<link href="{{ URL::to('/')}}/template/plugins/prettyphoto/css/prettyPhoto.css" rel="stylesheet" type="text/css">
<link href="{{ URL::to('/')}}/template/plugins/owl-carousel/css/owl.carousel.css" rel="stylesheet" type="text/css">
<link href="{{ URL::to('/')}}/template/plugins/owl-carousel/css/owl.theme.css" rel="stylesheet" type="text/css">
<link href="{{ URL::to('/')}}/template/css/custom.css" rel="stylesheet" type="text/css"><!-- custom css apply -->
<!--[if lte IE 9]><link rel="stylesheet" type="text/css" href="{{ URL::to('/')}}/css/ie.css" media="screen" /><![endif]-->
<!-- Color Style -->
<link href="{{ URL::to('/')}}/template/colors/color1.css" rel="stylesheet" type="text/css">
<!-- SCRIPTS
================================================== -->
<script src="{{ URL::to('/')}}/template/js/modernizr.js"></script><!-- Modernizr -->
When you move to another route, your href can't find the css files.
Also you need to Update your route from
Route::resource('grid', 'BasicController#grid');
to
Route::resource('grid/{$id}', 'BasicController#grid');
so that your grid(Request $request, $id) function can receive the $id from the url.
index.blade.php page
<!DOCTYPE HTML>
<html class="no-js">
<head>
<!-- Basic Page Needs
================================================== -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Real Spaces - #yield('title')</title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="">
<!-- Mobile Specific Metas
================================================== -->
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
<meta name="format-detection" content="telephone=no">
<!-- CSS
================================================== -->
<link href="template/css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="template/css/style.css" rel="stylesheet" type="text/css">
<link href="template/plugins/prettyphoto/css/prettyPhoto.css" rel="stylesheet" type="text/css">
<link href="template/plugins/owl-carousel/css/owl.carousel.css" rel="stylesheet" type="text/css">
<link href="template/plugins/owl-carousel/css/owl.theme.css" rel="stylesheet" type="text/css">
<link href="template/css/custom.css" rel="stylesheet" type="text/css"><!-- custom css apply -->
<!--[if lte IE 9]><link rel="stylesheet" type="text/css" href="css/ie.css" media="screen" /><![endif]-->
<!-- Color Style -->
<link href="template/colors/color1.css" rel="stylesheet" type="text/css">
<!-- SCRIPTS
================================================== -->
<script src="template/js/modernizr.js"></script><!-- Modernizr -->
</head>
<html>
<head>
This is my Master header in laravel for all page

missing designs in a navigated page developed in codeigniter

I am very new in codeigniter and I am facing lots of problems while I develop my website with it. I am facing basic navigation problem. First of all I've to say where my files are situated. My css,js and image file are situated at the root folder, that is where the application folder is situated. And my other files which contains html, php, js code are situated in view folder . My controller is like that:
<?php
class Saffron extends CI_Controller
{
function index()
{
$this->load->view('header');
$this->load->view('index');
$this->load->view('footer');
}
function book_table()
{
$this->load->view('book_table');
}
}
?>
I am trying to navigate to my 'book_table.php' page from my home page. Now see my nevigation.php page from where I am navigating my webpages (just showing the basic header part and anchor tags):
<!DOCTYPE html>
<html lang="en">
<head>
<title>Home</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" media="screen" href="css/reset.css">
<link rel="stylesheet" type="text/css" media="screen" href="css/style.css">
<link rel="stylesheet" type="text/css" media="screen" href="css/slider.css">
<link rel="stylesheet" type="text/css" media="screen" href="css/book.css">
<!--<link href='http://fonts.googleapis.com/css?
family=Great+Vibes' rel='stylesheet' type='text/css'>-->
<script src="js/jquery-1.7.min.js"></script>
<script src="js/jquery.easing.1.3.js"></script>
<script src="js/tms-0.4.1.js"></script>
<script src="js/vpb_script.js"></script>
<script src="js/pop.js"></script>
<!--start popup window ref-->
<link href="css/colorbox.css" rel="stylesheet" type="text/css" media="all" />
<script src="js/jquery_002.js"></script>
<script>
$(document).ready(function(){
$(".image_show").colorbox({rel:'image_show', transition:"fade"});
});
</script>
<!--end popup window ref-->
<script>
$(document).ready(function(){
$('.slider')._TMS({
show:0,
pauseOnHover:true,
prevBu:false,
nextBu:false,
playBu:false,
duration:700,
preset:'fade',
pagination:true,
pagNums:false,
slideshow:8000,
numStatus:false,
banners:false,
waitBannerAnimation:false,
progressBar:false
})
});
</script>
<style type='text/css'>
/*This will work for chrome */
#vpb_general_button{
padding:5px 2px 4px 2px;
}
/*This will work for firefox*/
#-moz-document url-prefix() {
#vpb_general_button{
padding:5px 2px 6px 2px;
}
}
</style>
<!--[if lt IE 8]>
<div style=' clear: both; text-align:center; position: relative;'>
<a href="http://windows.microsoft.com/en-US/
internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode">
<img src="http://storage.ie6countdown.com/assets/100/images/
banners/warning_bar_0000_us.jpg" border="0" height="42"
width="820" alt="You are using an outdated browser.
For a faster, safer browsing
experience,
upgrade for free today." />
</a>
</div>
<![endif]-->
<!--[if lt IE 9]>
<script type="text/javascript" src="js/html5.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="css/ie.css">
<![endif]-->
</head>
<body>
<div class="nav_b">
<nav>
<ul class="menu">
<li ><a href="index.html">
Online Order
</a>
</li>
<li>
<a href="<?php echo base_url(); ?>
index.php/saffron/book_table">Book Table
</a>
</li>
<li><a href="#">
Gallery
</a>
</li>
<li>
<a href="#">
About Us
</a>
</li>
<li>
<a href="#">
Awards
</a>
</li>
<li>
<a href="#">
Contact Us
</a>
</li>
</ul>
<div class="clear"></div>
</nav>
</div>
</body>
Now the problem is that I can navigate my Book table page but without the design. It's loading just like a basic html page, I can't understand why it's happening, because it doesn't find the css, js and images, isn't it? But my home page finds all and is fine, then why not the page(Book table) i am nevigating not finding the css,js and images?
In this scenario make use of base_url();. In application/config/config.php specify $config['base_url'] = 'http://www.yoursite.com';
Then in view change the link href and script src
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo(base_url());?>css/reset.css">
<script src="<?php echo(base_url());?>js/jquery-1.7.min.js"></script>

Categories