Is there ways to show a logo in many pages php? - php

I already write a code logo/img on header.php
but, when I going to refresh, a logo doesn't want to show up.
Is there a solution?
I used a bootstrap 4, simple html and css. I've tried many times but always fail.
In any features, a logo already show, but in "tambahalternatif" doesn't want to show
and here is my controller :
<?php
class Alternatif extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('Alternatif_model');
$this->load->library('form_validation');
}
public function index()
{
$data ['judul'] = 'Isi Alternatif';
$data ['alternatif'] = $this->Alternatif_model->getAllAlternatif();
if($this->input->post('key')){
$data['alternatif'] = $this->Alternatif_model->cariDataAlternatif();
}
$data['hasil'] = $this->Hitung(); //Manggil fungsi Hitung()
$this->load->view('templates/header',$data);
$this->load->view('alternatif/index', $data);
$this->load->view('templates/footer' );
}
public function tambahalternatif()
{
$data['judul'] = 'Form Tambah Data Alternatif';
// $this->form_validation->set_rules('idclient','ID','required|numeric');
$this->form_validation->set_rules('namaalt','NAMA','required');
if ($this->form_validation->run() == FALSE) {
$this->load->view('templates/header', $data);
$this->load->view('alternatif/tambahalternatif');
$this->load->view('templates/footer');
} else {
$this->Alternatif_model->tambahDataAlternatif();
$this->session->set_flashdata('flash','Berhasil');
redirect('alternatif');
}
header view
<nav class="navbar navbar-expand-lg navbar-light bg-light navbar-fixed-top ml-right">
<div class="container"><a class="navbar-brand" href="<?=base_url(); ?>" ><img class="logo" src="./img/logo.png" height="28px;" padding="2px 10px;></a>
i expect a image(logo) will show in "tambahalternatif", but image(logo) only show in "alternatif" only

Try this code in the header
<body>
<img src="<?php echo base_url();?>imag/logo.png" height="28px" alt="">
</body>

Use base bath instead of absolute path.
replace
<img class="logo" src="./img/logo.png" height="28px;" padding="2px 10px;>
with below line
<img class="logo" src="<?php echo base_url(); ?>img/logo.png" height="28px;" padding="2px 10px;>
So that when you change your view's path, the logo's path will no need to change.

***Try this one & let us know is it ok now.
Thanks.***
<nav class="navbar navbar-expand-lg navbar-light bg-light navbar-
fixed-top ml-right">
<div class="container">
<a class="navbar-brand" href="<?= base_url(); ?>" >
<img class="logo" src="<?= base_url().'img/logo.png'; ?>"
height="28px" padding="2px 10px">
</a>
</div>
</nav>

Related

If condiction in HTML with URL

I'm trying to do an if condiction in my HTML file in codeigniter that checks the URL and if it contains part of the URL it does one thing if doesnt it does something else
For example:
My URL is
localhost/index.php/cart/galery1
and when I click a photo it applies a filter with this URL
localhost/index.php/cart/galery1/2
the thing is that when I click in a photo after the filter it goes to something like
localhost/index.php/cart/galery1/2/2
There's a way I can do an if condiction checking the URL in my controler or my html ?
My code is something like that right now
HTML
<div id="top-industries" class="gallery">
<div class="container">
<h3 class="tittle">As Nossas Casas</h3>
<div class="gallery-bottom">
{foreach $products as $product}
<div class="view view-ninth">
<a href="galery1/{$product.cat_id}" class="b-link-stripe b-animate-go swipebox" title="Image Title"><img src="{$product.image}" alt="" class="img-responsive" width="330" height="219" target="_blank">
<div class="mask mask-1"></div>
<div class="mask mask-2"></div>
<div class="content">
<h2>CASA 1</h2>
<!--<p>A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart.</p>-->
</div></a>
</div>
{/foreach}
<div class="clearfix"> </div>
</div>
</div>
</div>
Controler
if($cat_id){
$data['catID'] = $cat_id;
$data['products'] = $this->Cart_model->get_casa($cat_id);
}
else{
$data['products'] = $this->Cart_model->get_products();
}
you have to set base_url(); here
application\config\config.php
$config['base_url'] = 'www.yoursite url.com';
and then use this base_url() in link like this
<a href="<?php echo base_url()?>galery1/{$product.cat_id}" class="b-link-stripe b-animate-go swipebox" title="Image Title"><img src="{$product.image}" alt="" class="img-responsive" width="330" height="219" target="_blank">
i think it will solve your problem
To get the segment from URL you should use CI's built-in library URI Class.
$this->uri->segment(n);
// your url - localhost/index.php/cart/galery1/2/3
$this->uri->segment(1); // returns conrtoller ie cart
$this->uri->segment(2); // returns function ie gallery1
$this->uri->segment(3); // returns 1st segment ie 2
$this->uri->segment(4); // returns 2nd segment ie 3
// you can also return default value when a uri segment is not available
$this->uri->segment(5, 0); // returns 0 because there is no 5th segment. Comes handy in condition -- will definitely help you here
// you can also use
uri_string(); // returns complete uri as a string ie cart/galery1/2/3
For more info read here.
Hope it helps you. :)
Create a new .tpl igual as the other one only changing what you want to change and then change the controller to
if($cat_id){
$data['catID'] = $cat_id;
$data['products'] = $this->Cart_model->get_casa($cat_id);
$this->smarty->view('fotos_galeria.tpl', $data);
}
else{
$data['products'] = $this->Cart_model->get_products();
$this->smarty->view('galeria.tpl', $data);
}

how do i make an image to zoom in bootstrap in codeigniter view when click on image?

<h5>
<a href="<?php echo base_url(); ?>/vendor/home/projects" >Back to Projects</a>
<h5>
<div>
<div class="container">
<div class="row">
<?php
foreach ($projects as $value) {
?>
<?php
$project_images = json_decode($value['project_gallery'],true);
$i=0;
foreach ($project_images as $project_image_value) {
$i++;
?>
<div class="col-md-2">
<img src="<?= base_url() ?>assets/uploads/projects/<?=$project_image_value['fname']?>" onclick="openModal(<?= $i?>)" class="img-thumbnail img-responsive " />
<div><?=$project_image_value['title']?></div>
</div> <?php
}
?>
<?php
}
?>
</div>
</div>
this is my codeigniter view to display images. How can i Apply light box so that when you click image, only that image should be zoomed
There are so many easy to use JQuery plugins available for image zoom kind of functionality. Use any of the following:
There use is as simple as:
$(document).ready(function(){
$('a.photo').zoom({url: 'photo-big.jpg'});
});
Reference
Some more reference:
https://i-like-robots.github.io/EasyZoom/
http://www.jqueryscript.net/tags.php?/image%20zoom/
http://www.jqueryscript.net/demo/Simple-jQuery-Magnifying-Glass-Image-Zoom-Plugin-magnify-js/

bootstrap php navigation bar highlight active

I have a problem with highlighting using php include.
Here's my navigation bar:
<?php
echo '
<link rel="stylesheet" href="css/index-css.css" type="text/css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<div class="container">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="/womsy/index.php">Womsy</a>
</div>
<ul class="nav navbar-nav">
<li <?php echo $active[1] ?>Home</li>
<li <?php echo $active[2] ?>Blog</li>
<li <?php echo $active[3] ?>Projects</li>
<li <?php echo $active[4] ?>Contact</li>
<li class="active">About</li>
</ul>
</div>
</nav>';
$active[$current] = "class=active";
?>
I made this with bootstrap, and am trying to highlight via this: http://webdevjunk.com/coding/css/17/php-menu-includes-with-css-style-to-highlight-active-page-link/
<?php
$current = 1;
include 'php/menu.php';
?>
This is what I use on the page, but it doesn't highlight, but when I change the class in the <li> it does work.
Can someone help me figure this out?
function setActive($pageName)
{
if (stripos($_SERVER['REQUEST_URI'], $pageName)) {
echo 'class="active"';
}
}
//$pageName will be home ,blog,projects and contacts
Declare page variable at the very top of each individual page.
Example: <? $page="home";?> goes at top of homepage and <? $page="blog";?> would go on top of blog page, etc.
For each list item in your menu add if statement with corresponding variable and active class.
Example: <ul><li class="<?if($page=="home"){?>active<?}?>"><b>Home</b></li><li class="<?if($page=="blog"){?>active<?}?>"><b>Blog</b></li></ul>
What this does is assign each page a variable. The variable is compared in the if statements in the nav bar to determine which li gets the active class.

Codeigniter + Boostrap : split tab-content in multiple files

first of all I'm a newbie in web development so...
I don't know if there is a way to do the following (neither if it's a best practice).
I have a CodeIgniter + Angularjs application where there is a view contains a Bootstrap tab (which is also a angular app):
[view_general_params.php]
<!DOCTYPE html>
<html lang="it">
<head>
</head>
<body ng-controller="HouseController">
<div class="container">
<ul class="nav nav-tabs" id="myTab">
<li class="active">Home</li>
<li>Profile</li>
<li>Messages</li>
<li>Settings</li>
</ul>
<div class="tab-content">
</div>
</div>
</body>
</html>
Now, since each tab must contains a lot of controls (Textboxes etc..) I'm asking myself if there is a way to split it in different files loaded by the controller in this way:
public function details($house_id)
{
$user = $this->session->userdata('user');
if (is_null($user)) {
$this->session->sess_destroy();
redirect('login/index');
}
else {
$data = $this->create_data_array($user);
$data['house'] = $this->houses_model->get_house($house_id);
$data['title'] = "House details";
$this->load->view('head_navbar', $data);
$this->load->view('house_details_view', $data);
$this->load->view('view_general_params', $data);
$this->load->view('view_house_params', $data);
$this->load->view('view_panel_params', $data);
$this->load->view('view_statistics', $data);
}
}
where each others views contain data for a single tab-page:
[view_general_params.php]
<!DOCTYPE html>
<html lang="it">
<head>
</head>
<body>
<div class="container">
<div class="tab-content">
<div class="tab-pane active" id="general">
general controls...
</div>
</div>
</div>
</body>
</html>
Yes you can. In Codeigniter you can use a view as a template. Take these steps:
create a folder in your views directory, call it "Templates".
application\views\templates\
create each template the way you want and place it inside the templates folder:
application\views\templates\head_navbar.php
application\views\templates\house_details_view.php
application\views\templates\view_general_params.php
In your controller, you want to call these templates with a third paramater set to TRUE, then passing this to as an array value. This array will then be sent to your main view, like this:
public function details($house_id) {
$user = $this->session->userdata('user');
if (is_null($user)) {
$this->session->sess_destroy();
redirect('login/index');
} else {
$data = $this->create_data_array($user);
$data['house'] = $this->houses_model->get_house($house_id);
$data['title'] = "House details";
$data_to_final_view = array(
"view1" => $this->load->view('head_navbar', $data, TRUE),
"view2" => $this->load->view('house_details_view', $data, TRUE),
"view3" => $this->load->view('view_house_params', $data, TRUE),
"view4" => $this->load->view('view_panel_params', $data, TRUE),
"view5" => $this->load->view('view_statistics', $data, TRUE)
);
$this->load->view('view_general_params', $data_to_final_view);
}
}
Now, in your view_general_params view, you can place the template's content anywhere you want:
<div class="container">
<ul class="nav nav-tabs" id="myTab">
<li class="active">Home</li>
<li>Profile</li>
<li>Messages</li>
<li>Settings</li>
</ul>
<div class="tab-content1">
<?= $view1 ?>
</div>
<div class="tab-content2">
<?= $view2 ?>
</div>
... etc..
</div>

using jQuery to load php files into a div not working

so I have my main layout as such:
<div class="menu">
<?php include('/menu.php'); ?>
</div>
<div class="main" id="content">
<?php include('/home.php'); ?>
</div>
In the menu.php I have 4 divs set up as such:
<div class="link current">
<a href="#" class="home">
Home
</a>
</div>
<div class="link">
<a href="#" class="about">
About
</a>
</div>
<div class="link">
<a href="#" class="forums">
Forums
</a>
</div>
<div class="link">
<a href="#" class="contact">
Contact
</a>
</div>
And I'm including this .js file in the head of the index page
$(function () {
$('div.link a').click(function () {
$('div.link').removeClass('current');
$(this).closest('div.link').addClass('current');
if($('div.link a').hasClass('home')) {
$('#content').load('/home.php');
} else if($('div.link a').hasClass('about')) {
$('#content').load('/about.php');
} else if($('div.link a').hasClass('forums')) {
$('#content').load('/forums.php');
} else if($('div.link a').hasClass('contact')) {
$('#content').load('/contact.php');
} else return false;
});
});
But it doesn't work.
I'm new to all of this and have pieced this code together using varied sources on the internet, after trying it myself and not being able to figure it out, I've come for help.
The hierarchy of the site is as such.
-/
-res/
-css/
-default.css
-imgs/
-scripts/
-jquery.js
-load.js (this is the one shown above)
-index.php
-menu.php
-home.php
-about.php
-forums.php
-contact.php
If anyone can provide help, it will be greatly appreciated.
The first condition in your if statements is checking to see if any "div.link a" has the class "home". Therefore the first if condition is always true and you're always loading /home.php into #content. What you want to do is check to see if the link that was clicked has the class.
You should use if($(this).hasClass('home')) { ...
Also, if you want to clean things up a bit, I would suggest:
$('div.link a').click(function () {
$('div.link').removeClass('current');
$(this).closest('div.link').addClass('current');
$('#content').load('/' + $(this).attr('class') + '.php');
});
This way you don't have to maintain the if statements. Though, if you end up adding more classes to those links, this will break. Perhaps use a data-* attribute? <a href="#" data-load="contact">...

Categories