Codeigniter 404 Page not founds - codeigniter

i'm new to codeigniter. I'm making crud from a tutorial, whenever I run it.
It links to..http://localhost/gis-crud/
and it show error 404
i think it's just a problem on the uri or pagination of the controllers. What would be the problem?
apps.php - controller
class Apps extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model('m_data_lokasi','lokasi');
}
function index(){
$data['q']=$this->lokasi->semua()->result();
$this->tampil->display('apps/index.php',$data);
}
Tampil.php - libraries
function __construct(){
$this->_CI=&get_instance();
}
function display($tampil,$data=null){
$data['_content']=$this->_CI->load->view($tampil,$data,true);
$data['_header']=$this->_CI->load->view('tampil/header',$data,true);
$data['_footer']=$this->_CI->load->view('tampil/footer',$data,true);
$this->_CI->load->view('/tampil.php',$data);
}
Tampil.php - view
<html>
<head>
<meta charset="utf-8">
<title>CRUD-GIS</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes"/>
<link href="<?php echo base_url(); ?>/assets/jquery.mobile-1.4.4.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?php echo base_url(); ?>/assets/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>/assets/jquery.mobile-1.4.4.min.js"></script>
<style>
#map-page, #map-canvas { width: 100%; height: 100%; padding: 0; }
</style>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
</head>
<body onLoad="Initialize()">
<?php echo $_header;?>
<div role="main" class="ui-content">
<?php echo $_content;?>
</div>
<?php echo $_footer;?>
</div>
</body>
</html>
config.php
$config['base_url'] = 'http://localhost/gis-crud/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

save this code as .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
In your config folder
look for routes.php change the
default controller
$route['default_controller'] = 'welcome';
To your Controller named Apps
$route['default_controller'] = 'apps';
once you call your $config['base_url'] = 'http://localhost/gis-crud/'; it will execute the default_controller above.

Related

CSS files load but doesnt apply to my page codeignter 3

I am new to codeigniter, i am still learning about it. My problem it's that the css file is not applying on the page, it is linked, I can seet it but it doesnt work.
My header file.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Proyectos makers</title>
<link rel="stylesheet" type="text/css" src="<?php echo base_url('assets/estilos.css'); ?>">
</head>
<body>
My css file:
body{
background-color: #CC00CC;
}
In my config/autoload.php I load the url helper
$autoload['helper'] = array('url');
I have yet removed my index.php page in config.php
And this is my .htacces file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
When i view the source code, the css file is linked. I clic on it and shows me the code of the css file. But doesn´t change the aspect of my site.
I have found my error. It is not src, it is href in my link.
Bad:
<link rel="stylesheet" type="text/css" src="<?php echo base_url('assets/estilos.css'); ?>">
Good:
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/estilos.css'); ?>">

Adding Twitter Bootstrap to CodeIgniter?

I have developed website using CodeIgniter that uses MySQL to populate a results page. I would now like to improve all the pages appearances and most places recommend using Bootstrap. I have tried to add Bootstrap to my CodeIgniter project but with no success.
Does anyone know of an up-to-date guide I could follow to complete this?
Thanks
A simple way would be to use Bootstrap CDN. For CSS, simply include this line in the <head> section of every webpage (somewhere in your view files, depending on how you have structured them):
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
Bootstrap's plugins depend on jQuery, so you'll need to include jQuery before Bootstrap's JavaScript:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
Simple example page:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Your great site!</title>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="jumbotron">
<div class="container">
<h1>Hello, world!</h1>
</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</body>
</html>
Alternatively you could host the files on your web server. Upload the relevant files to a publicly accessible directory. I'm going to assume that they are in an assets folder, in your web root, like this:
+-- public_html
| +-- index.php
| +-- assets
| | +-- css
| | | +-- boostrap.css
| | +-- js
| | | +-- bootstrap.js
| | | +-- jquery.js
| (other files/directories...)
To include them in your view files, you can link them like this:
<link rel="stylesheet" href="<?php echo base_url("assets/css/bootstrap.css"); ?>">
<script type="text/javascript" src="<?php echo base_url("assets/js/jquery.js"); ?>"></script>
<script type="text/javascript" src="<?php echo base_url("assets/js/bootstrap.js"); ?>"></script>
You'll need to have loaded the URL Helper to use the base_url() function.
First time using PHP CodeIgniter , Bootstrap and Bitnami mampstack.
( All develope code in local notebook)
1. To extract the file CodeIgniter 3.x and Boostrap 3.x(Twitter)
Here my directory :
/Applications/mampstack-5.4.26-2/apache2/htdocs/TestCoceIginter_Bootstra
/Applications/mampstack-5.4.26-2/apache2/htdocs/TestCoceIginter_Bootstrap/application
/Applications/mampstack-5.4.26-2/apache2/htdocs/TestCoceIginter_Bootstrap/assets
2.Modification (Add)
a. application/controller/Welcome.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller
{
public function __construct() {
parent::__construct();
$this->load->helper('url');
public function index(){
$this->load->view('welcome_message');
}
}
b.application/views/welcome_message.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to CodeIgniter</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="<?php echo base_url("assets/css/bootstrap.css"); ?>">
<script type="text/javascript" src="<?php echo base_url("assets/js/jquery.min.js"); ?>"></script>
<script type="text/javascript" src="<?php echo base_url("assets/js/bootstrap.js"); ?>"></script>
</head>
If you tried to remove the 'index.php' from url like in the official example then you should try this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]
</IfModule>
Open the config.php in /CodeIgniter/application/config directory,
And edit it as:
$config['base_url'] = 'http://localhost/your_folder/';

uncaught exception: Call to StartUpload failed in uploadify integration with codeigniter

i have integrated uploadify with codeigniter.i can't able select images while clicking the select photos.
MY View file
<!DOCTYPE HTML>
<html lang="en-GB">
<head>
<meta charset="UTF-8">
<title>Uploadify V3 & CodeIgniter</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="Capsone-System2" >
<!-- Styles -->
<link href="/assets/bootstrap/css/bootstrap.min.css" type="text/css" media="screen" rel="stylesheet"/>
<link href="<?php echo base_url;?>assets/js/jquery/uploadify_31/uploadify.css" type="text/css" media="screen" rel="stylesheet"/>
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<!-- Main Content -->
<div class="container">
<h1 class="page-header">Uploadify V3 & CodeIgniter</h1>
<p>This is a simple tutorial demo showing Uploadify V3 working with CodeIgniter 2.1.2</p>
<?php echo form_open_multipart(); ?>
<ul class="unstyled">
<li>
<?php echo form_upload('userfile','','id="userfile"'); ?>
<?php echo (isset($error)) ? $error : ''; ?>
</li>
<li>
<?php echo form_button(array('content'=> 'Upload', 'id'=>'upload-file', 'class'=>'btn btn-large btn-primary')); ?>
</li>
</ul>
<?php echo form_close(); ?>
</div>
<!-- End Of Main Content -->
<!--<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>-->
<!--<script>window.jQuery || document.write('<script src="<?php echo base_url;?>assets/js/jquery/jquery-1.8.0.min.js"></script>')</script>-->
<script src="<?php echo base_url;?>assets/js/jquery/uploadify_31/jquery.uploadify-3.1.min.js" type="text/javascript"></script>
<!--<script src="<?php echo base_url;?>assets/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>-->
<script type="text/javascript">
$(document).ready(function () {
var base_url = '<?php echo base_url; ?>';
alert(base_url);
$('#upload-file').click(function (e) {
e.preventDefault();
$('#userfile').uploadify('upload', '*');
alert(base_url);
});
$('#userfile').uploadify({
'debug':true,
'auto':false,
'swf': base_url + 'assets/js/jquery/uploadify_31/uploadify.swf',
'uploader': base_url + 'uploadify_v3/do_upload',
'cancelImg': base_url + 'assets/javascript/jquery/uploadify_31/uploadify-cancel.png',
'fileTypeExts':'*.jpg;*.bmp;*.png;*.tif',
'fileTypeDesc':'Image Files (.jpg,.bmp,.png,.tif)',
'fileSizeLimit':'2MB',
'fileObjName':'userfile',
'buttonText':'Select Photo(s)',
'multi':true,
'removeCompleted':false,
'onUploadError' : function(file, errorCode, errorMsg, errorString) {
alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
}
});
});
</script>
</body>
</html>
My Controller File
I have error uncaught exception: Call to StartUpload failed
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* #property CI_Upload $upload
*/
class Uploadify_v3 extends CI_Controller
{
public $view_data = array();
private $upload_config;
function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->helper(array('url', 'form'));
$this->load->view('uploadify_v3', $this->view_data);
}
public function do_upload()
{
$this->load->library('upload');
$image_upload_folder = FCPATH . '/uploads';
if (!file_exists($image_upload_folder)) {
mkdir($image_upload_folder, DIR_WRITE_MODE, true);
}
$this->upload_config = array(
'upload_path' => $image_upload_folder,
'allowed_types' => 'png|jpg|jpeg|bmp|tiff',
'max_size' => 2048,
'remove_space' => TRUE,
'encrypt_name' => TRUE,
);
$this->upload->initialize($this->upload_config);
if (!$this->upload->do_upload()) {
$upload_error = $this->upload->display_errors();
echo json_encode($upload_error);
} else {
$file_info = $this->upload->data();
echo json_encode($file_info);
}
}
}
/* End of file uploadify_v3.php */
/* Location: ./application/controllers/uploadify_v3.php */
I have spent more time..still now i can't fix this error..please help me.
I too had the same problem, it was a security issue because I was hosting the flash .swf file on a separate domain eg: static.mysite.com
Make sure your swf file and post handler script are hosted on the same domain that you are accessing the site from.
Or if you need to add cross domain posting then see here:
http://www.adobe.com/devnet/adobe-media-server/articles/cross-domain-xml-for-streaming.html

css,javascript path recognize in codeigniter

I am very new in Codeigniter...i have some basic ideas..but not sufficient.lets talk about the problem....
I have a static website..which will be dynamic soon.Now this static website contains css,css3 in a css forlder, javascript in javascript folder,image in images folder.Now i am wanting to set this static website into codeigniter.I copy paste the whole codes including index.php and other pages and the folders(css,javascript.images)into the view folder of codeigniter.for all of your kind information my index.php page is just like that...
<!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 href='http://fonts.googleapis.com/css?family=Great+Vibes'
rel='stylesheet' type='text/css'>-->
<script src="<?= base_url() ?>path/images/js/jquery-1.7.min.js"></script>
<script src="<?= base_url() ?>path/images/js/jquery.easing.1.3.js"></script>
<script src="<?= base_url() ?>path/images/js/tms-0.4.1.js"></script>
<script src="<?= base_url() ?>path/images/js/vpb_script.js"></script>
<script src="<?= base_url() ?>path/images/js/pop.js"></script>
<!--start popup window ref-->
<link href="css/colorbox.css" rel="stylesheet" type="text/css" media="all" />
<script src="<?= base_url() ?>path/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="bg-top">-->
<div class="bgr">
<!--==============================Wrapper=================================-->
<div class="wrapper">
<?php
include_once('header.php');
include_once('navigation.php');
include_once('slider.php');
include_once('offers.php');
include_once('invite.php');
include_once('testimonial.php');
include_once('special_item.php');
include_once('footer.php');
include_once('popup.php');
?>
and my conroller is like that...
<?php
class Site extends CI_Controller
{
function home()
{
$this->load->view('index');
}
}
?>
the problem is that my webpage is loading but without the design,may b its not finding the javascript or css
i know i am making a mistake here..bur i can't fix it out,please help me to fix it out..
usually we put all files like that into an "assets" folder in the application root, and then make sure to use an Asset_Helper to point to those files. This is what CodeIgniter suggests
The folders (css, javascript, images) should NOT be pasted into the views folder, but in the folder where your Code Igniter's index.php is. (Usually, the parent folder of the application folder, i.e., your site public root.)
You can add <?= base_url() ?> to all your css link.
<link rel="stylesheet" type="text/css" media="screen"
href="<?= base_url() ?>path/to/css/reset.css">
There is a more comprehensive answer here. You may want to consider permissions issues that could be going on as a result of placing your css dir within the application/views dir.
Create an assets dir outside the application dir and use the URL helper by loading it into your controller like this.

can not finding the css,js and images

i am very new in codeigniter.I have a static web page.i just want to convert it into dynamic web page.First of all i pasted all the files in the view folder of the MVC of the codeigniter.Here i have css, javascript and images folder and my php files.
I have created a controller like this..
<?php
class Saffron extends CI_Controller
{
function index()
{
$this->load->view('home');
}
}
?>
and my home.php page is just like this..
<!DOCTYPE html>
<html lang="en">
<head>
<title>Home</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css"
media="screen" href="<?= base_url() ?>application/views/css/reset.css">
<link rel="stylesheet" type="text/css"
media="screen" href="<?= base_url() ?>application/views/css/style.css">
<link rel="stylesheet" type="text/css"
media="screen" href="<?= base_url() ?>application/views/css/slider.css">
<script src="<? echo base_url(); ?>application/views/js/jquery-1.7.min.js"></script>
<script src="<? echo base_url(); ?>application/views/js/jquery.easing.1.3.js"></script>
<script src="<? echo base_url(); ?>application/views/js/tms-0.4.1.js"></script>
<script src="<? echo base_url(); ?>application/views/js/vpb_script.js"></script>
<script src="<? echo base_url(); ?>application/views/js/pop.js"></script>
<!--start popup window ref-->
<link href="application/views/css/colorbox.css"
rel="stylesheet" type="text/css" media="all" />
<script src="<? echo base_url(); ?>application/views/js/jquery_002.js"></script>
<script>
$(document).ready(function(){
$(".image_show").colorbox({rel:'image_show', transition:"fade"});
});
</script>
<!--end popup window ref-->
<!--[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="bg-top">-->
<div class="bgr">
<!--==============================Wrapper=================================-->
<div class="wrapper">
<!-----------------------Header --------------------------->
<header>
<div class="head">
<h1>
<a href="index.html">
<img src="<?php echo base_url(); ?>application/views/images/logo.jpg" alt=""></a>
sign up
<a href="javascript:void(0);"
class="classname1" onClick="vpb_show_login_box();">login</a>
</h1>
</div>
<?php
include_once('navigation.php');
include_once('slider.php');
include_once('offers.php');
include_once('invite.php');
include_once('testimonial.php');
include_once('special_item.php');
include_once('footer.php');
include_once('popup.php');
?>
Now what the mistake there...or anyelse that i can't recognizing??...please hlp me.
Thanks in Advance...
You forgot to put echo on several places.
I can show you my solution for putting files in header. First I made a folder in the root and named it public, and in that folder I created folders for needed documents (css, img, js...). In constants.php I made this:
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
define('ABSOLUTE_PATH', str_replace('system/','', BASEPATH));
define('BASE', $root);
define('CSS', BASE . 'public/css/');
define('JS', BASE . 'public/js/');
define('IMG', BASE . 'public/img/');
So in the header you can do this:
<link rel="stylesheet" href="<?php echo CSS ?>reset.css">
This is a easy way to maintain and update your files.
Sasha gave a good solution, but to answer your question: all your CSS, images, JS should not reside inside the application folder, but in a folder on the same level as application. assetsis a common name for such a folder.
Try this:
in your config file, define the base_url() ex, base_url() = 'yoursite';
in root directory create a folder and name it resource and put all your css, js, img folders inside
in your html/php view file (ex. application/views/test.php) along with html code put these php codes, example
NOTE: don't worry about echoing the base_url in every js or css file that you link because base has been already defined.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Home</title>
<meta charset="utf-8">
<base href="<?php echo base_url(); ?>" />
<link rel="stylesheet" type="text/css" media="screen" href="resource/css/reset.css">
<link rel="stylesheet" type="text/css" media="screen" href="resource/css/style.css">
<link rel="stylesheet" type="text/css" media="screen" href="resource/css/slider.css">
<script src="resource/js/jquery-1.7.min.js"></script>
<script src="resource/js/jquery.easing.1.3.js"></script>
<script src="resource/js/tms-0.4.1.js"></script>
<script src="resource/js/vpb_script.js"></script>
<script src="resource/js/pop.js"></script>

Resources