style.css does not load correctly - codeigniter

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') ?>

Related

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:

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

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

echo form_open('user_authentication/new_user_registration'); rendered wrong url

I have problem about the form_open or any url in my site, maybe this is the new update of codeigniter or what. when I use its rendered a confusing syntax like http://::1/ and my form not working correctly or take me to a blank page. also my css dont work.
here is my php code.
<html>
<?php
if (isset($this->session->userdata['logged_in'])) {
header("location: http://localhost/login/index.php/user_authentication/user_login_process");
}
?>
<head>
<title>Login Form</title>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/style.css">
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro|Open+Sans+Condensed:300|Raleway' rel='stylesheet' type='text/css'>
</head>
<body>
<?php
if (isset($logout_message)) {
echo "<div class='message'>";
echo $logout_message;
echo "</div>";
}
?>
<?php
if (isset($message_display)) {
echo "<div class='message'>";
echo $message_display;
echo "</div>";
}
?>
<div id="main">
<div id="login">
<h2>Login Form</h2>
<hr/>
<?php echo form_open('user_authentication/user_login_process'); ?>
<?php
echo "<div class='error_msg'>";
if (isset($error_message)) {
echo $error_message;
}
echo validation_errors();
echo "</div>";
?>
<label>UserName :</label>
<input type="text" name="username" id="name" placeholder="username"/><br /><br />
<label>Password :</label>
<input type="password" name="password" id="password" placeholder="**********"/><br/><br />
<input type="submit" value=" Login " name="submit"/><br />
To SignUp Click Here
<?php echo form_close(); ?>
</div>
</div>
</body>
</html>
then here is the view page source. im using google chrome browser
<html>
<head>
<title>Login Form</title>
<link rel="stylesheet" type="text/css" href="http://::1/login/css/style.css">
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro|Open+Sans+Condensed:300|Raleway' rel='stylesheet' type='text/css'>
</head>
<body>
<div id="main">
<div id="login">
<h2>Login Form</h2>
<hr/>
<form action="http://::1/login/index.php/user_authentication/user_login_process" method="post" accept-charset="utf-8">
<div class='error_msg'></div> <label>UserName :</label>
<input type="text" name="username" id="name" placeholder="username"/><br /><br />
<label>Password :</label>
<input type="password" name="password" id="password" placeholder="**********"/><br/><br />
<input type="submit" value=" Login " name="submit"/><br />
To SignUp Click Here
</form> </div>
</div>
</body>
</html>
as you can see the url of css and form are rendered a wrong url. href="http://::1/login/css/style.css"> instead of href="css/style.css">. also the form_open(). whats wrong with this?
Its because of your base_url is empty
How to set base_url()??
In config/config.php set $config['base_url'] = ''; the project URL.
Keeping base_url() empty any harm??
When you in local its ok and fine. But when you host that just add your site URL to it.
$config['base_url'] = 'www.stackoverflow.com';
Take look at this answer
and Possible duplicate of This Question

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.

Codeigniter form_open not submitting

I've got the following simple search page. 3 fields (one with fixed value) and submit button. When I click submit nothing happens at all. not even reload or anything. the button does nothing. Ignore the arabic in there, I have a feeling it got to do with arrangements of divs or placement of form_open.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>منزلي</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>support/css/main.css" media="screen" />
</head>
<body>
<div id="header">
<div id="logo">
منزلي
</div>
<ul id="list-nav">
<li>للإتصال بنا </li>
<li>عن الموقع</li>
<li>منازل للبيع</li>
<li>منازل للإيجار</li>
<li>الرئيسية</li>
</ul>
</div>
<?
$this->load->helper('form');
form_open('search/search_properties'); ?>
<div id="center">
المدينة:
<select name="city">
<option>الخبر</option>
<option>الدمام</option>
<option>الظهران</option>
</select>
<br><br>
Type: <input type="text" value="flat" name="propertyType"/> <br><br>
حدود السعر:
<select name="range">
<option> <20000 </option>
<option>20000-30000</option>
<option>30000-40000</option>
<option>40000-50000</option>
<option> >500000 </option>
</select>
<br><br>
<input type="submit" value="بحث"/>
</form>
</div>
<div id="footer">
<p>2012 منزلي ©</p>
</div>
</body>
</html>
Any idea why this is happening?
thanks all for support
<?
$this->load->helper('form');
form_open('search/search_properties'); ?>
should be
<?
$this->load->helper('form');
echo form_open('search/search_properties'); ?>

Resources