codeigniter require no such file or directory [duplicate] - php

This question already has an answer here:
Codeigniter include not working?
(1 answer)
Closed 9 years ago.
I just got a very frustating error. I always use require 'file_name' when i tried to load a view (ex : header).
Im using CI now and i tried to do something like this : <?php require 'header_v.php';?> in my home_v.php but it always give me the No such file or directory error.
This is header_v.php :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Backend-Vihara Dharma Bhakti</title>
<link href="../../../style/style_backend.css" rel="stylesheet" type="text/css">
<link href="<?php echo base_url(); ?>style/style_backend.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="<?php echo base_url(); ?>jquery/jquery-ui-1.10.2.custom/css/ui-lightness/jquery-ui-1.10.2.custom.min.css" />
<script language="javascript" type="text/javascript" src="<?php echo base_url(); ?>jquery/jquery-ui-1.10.2.custom/js/jquery-1.9.1.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo base_url(); ?>jquery/jquery-ui-1.10.2.custom/js/jquery-ui-1.10.2.custom.min.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
$(function() {
$( "#tabs" ).tabs();
});
</script>
<div id="header"><h1>HEADER</h1></div>
<div id="tabs">
<ul>
<li>Daftar Umat</li>
<li>Daftar Pengurus</li>
<li>Absensi</li>
</ul>
</div>
</head>
And this is home_v.php (the one that require header_v.php) :
<body>
<link rel="stylesheet" href="<?php echo base_url(); ?>jquery/jquery-ui-1.10.2.custom/css/ui-lightness/jquery-ui-1.10.2.custom.min.css" />
<script language="javascript" type="text/javascript" src="<?php echo base_url(); ?>jquery/jquery-ui-1.10.2.custom/js/jquery-1.9.1.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo base_url(); ?>jquery/jquery-ui-1.10.2.custom/js/jquery-ui-1.10.2.custom.min.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
<?php require 'header_v.php';?>
<div id="form_search">
<?php echo form_open('backend/index') ?>
<p>
<?php echo form_dropdown('ddl_search', $data_search, 'id="ddl_search"');?>
</p>
<p>
Kelas :
<?php echo form_dropdown('ddl_kelas1', $list_kelas, 'id="ddl_kelas1"');?> -
<?php echo form_dropdown('ddl_kelas2', $list_kelas, 'id="ddl_kelas2"');?>
</p>
<p>
Nama : <?php echo form_input('txt_nama');?>
Alamat : <?php echo form_input('txt_alamat');?>
Tanggal Lahir : <input type="text" id="datepicker" />
</p>
<?php echo form_submit('btn_search', 'Search');?>
<?php echo form_close(); ?>
</div>
<div>
<?php echo $table ?>
<?php echo $pagination ?>
</div>
</body>
</html>
What am i missing?Does it has something to do with config.php, routes.php or other CI's settings?Because i have use this way so many time and its always working except now.
Thanks for your help :D
NOTE : The file name is right, header_v and home_v is in the same folder(views).

The correct way to load a view file is this:
$this->load->view('file-in-views-folder')

To use the require function in CI, you have to type the full path of that file.
Like:
<?php require '/var/www/main/application/views/header_v.php';?>
But, the correct way using CI, is to load the view in your controller.
$this->load->view("header_v");
and then
$this->load->view("home_v"); //remove the require function from your code.

Why don't you load in your controller file?
$this->load->view('header_v');
$this->load->view('home_v');

if you want to output somenthing use
echo $this->load->file('/path/to/myfile');
if it's a view
echo $this->load->view('myviewname');
if it's a php library or an helper (so you haven't to output somenthing but just require or include classes and methods):
$this->load->helper();
$this->load->library();
Remember
views has to stay under /application/views folder
libraries under /application/libraries
helpers under /application/helpers
general files types can stay where you want since you use to load them with the enteire path to them /path/to/my/file

Related

PHP not running in iFrame

Hi I am trying to make a personal code playground... I am using Code Mirror to turn into looking like an IDE (I also plan to add features of an IDE later but...). My current code is basically..
HTML (index.html)
<html>
<head>
<link href="main.css" rel="stylesheet" type="text/css" />
<script src="http://codemirror.net/lib/codemirror.js"></script>
<link href="http://codemirror.net/lib/codemirror.css" rel="stylesheet" />
<script src="http://codemirror.net/mode/htmlmixed/htmlmixed.js"></script>
<script src="http://codemirror.net/mode/css/css.js"></script>
<script src="http://codemirror.net/mode/javascript/javascript.js"></script>
</head>
<body>
<div class="codewindow">
<form id="codePush" action="codePush.php" method="POST" target="codeResults">
<textarea id="htmlWindow"></textarea>
<textarea id="cssWindow"></textarea>
<textarea id="jsWindow"></textarea>
<input type="submit" />
</form>
<script class="code">
var htmlCodeMirror = CodeMirror(function(elt) {
htmlWindow.parentNode.replaceChild(elt, htmlWindow);
}, {value: "<!-- HTML goes here -->",
lineNumbers: true,
mode: "text"});
</script>
<script class="code">
var cssCodeMirror = CodeMirror(function(elt) {
cssWindow.parentNode.replaceChild(elt, cssWindow);
}, {value: "/* CSS goes here. */",
lineNumbers: true,
mode: "css"});
</script>
<script class="code">
var jsCodeMirror = CodeMirror(function(elt) {
jsWindow.parentNode.replaceChild(elt, jsWindow);
}, {value: "// JavaScript goes here.",
lineNumbers: true,
mode: "javascript"});
</script>
</div>
<div class="output">
<iframe id="codeResults" name="codeResults" target="codePush.php" width="100%" height="100%" frameBorder="0.5" scrolling="yes"></iframe>
</div>
</body>
PHP (codePush.php)
<!DOCTYPE html>
<html>
<head>
<style>
<?php
echo $_GET['cssWindow'];
?>
</style>
<script type="text/javascript">
<?php
echo $_GET['jsWindow'];
?>
</script>
</head>
<body>
<?php
echo $_GET['htmlWindow'];
?>
</body>
</html>
I have made sure the link to the iFrame works because when adding text to the PHP file in the body section it displays when submit is pressed.
I hope I have made it clear and would appreciate any help...
Just for reference I am a bit of a NOoB when it comes to PHP
I'm not entriely sure what you're trying to achieve with all the code you provided, but here's a simplified version that will fix the main issue of the code not processing in codePush.php:
<div class="codewindow">
<form id="codePush" action="codePush.php" method="POST" target="codeResults">
HTML:<textarea id="htmlWindow" name="htmlWindow"></textarea>
CSS:<textarea id="cssWindow" name="cssWindow"></textarea>
JS:<textarea id="jsWindow" name="jsWindow"></textarea>
<input type="submit" />
</form>
</div>
<div class="output">
<iframe id="codeResults" name="codeResults" target="codePush.php" width="100%" height="100%" frameBorder="0.5" scrolling="yes"></iframe>
</div>
CodePush.php
<!DOCTYPE html>
<html>
<head>
<style>
<?php
echo $_POST['cssWindow'];
?>
</style>
<script type="text/javascript">
<?php
echo $_POST['jsWindow'];
?>
</script>
</head>
<body>
<?php
echo $_POST['htmlWindow'];
?>
</body>
</html>
Note that CodePush.php uses 'POST' not 'GET' so that it is consistent with your form. You were also missing 'name' attributes on the textareas which is what is used in the post (not the ids).
You might want to consider adding in some checks if the fields aren't complete to avoid errors etc.

controlling codeigniter pagination url

First, i need to explain you what am i doing :
Note : This project is using codeigniter framework
I have a view for the header and the tabs :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Backend-Vihara Dharma Bhakti</title>
<link href="../../../style/style_backend.css" rel="stylesheet" type="text/css">
<link href="<?php echo base_url(); ?>style/style_backend.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="<?php echo base_url(); ?>jquery/jquery-ui-1.10.2.custom/css/ui-lightness/jquery-ui-1.10.2.custom.min.css" />
<script language="javascript" type="text/javascript" src="<?php echo base_url(); ?>jquery/jquery-ui-1.10.2.custom/js/jquery-1.9.1.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo base_url(); ?>jquery/jquery-ui-1.10.2.custom/js/jquery-ui-1.10.2.custom.min.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
$(function() {
$( "#tabs" ).tabs();
});
</script>
<div id="header"><h1>HEADER</h1></div>
<div id="tabs">
<ul>
<li>Daftar Umat</li>
<li>Daftar Pengurus</li>
<li>Absensi</li>
</ul>
</div>
</head>
Notice that i use the tabs to load different content(controller) below the header and tabs.
And the controller for the header and the tabs :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Backend_home extends CI_Controller {
public function index()
{
$this->load->view('template/header_v');
}
}
Then, i have another view to show the content (i will use the first link(backend/umat) for the example)
<body>
<link rel="stylesheet" href="<?php echo base_url(); ?>jquery/jquery-ui-1.10.2.custom/css/ui-lightness/jquery-ui-1.10.2.custom.min.css" />
<script language="javascript" type="text/javascript" src="<?php echo base_url(); ?>jquery/jquery-ui-1.10.2.custom/js/jquery-1.9.1.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo base_url(); ?>jquery/jquery-ui-1.10.2.custom/js/jquery-ui-1.10.2.custom.min.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
<div id="form_search">
<?php echo form_open('backend/index') ?>
<!--<p>
<?php echo form_dropdown('ddl_search', $data_search, 'id="ddl_search"');?>
</p>-->
<p>
Kelas :
<?php echo form_dropdown('ddl_kelas1', $list_kelas, 'id="ddl_kelas1"');?> -
<?php echo form_dropdown('ddl_kelas2', $list_kelas, 'id="ddl_kelas2"');?>
</p>
<p>
Nama : <?php echo form_input('txt_nama');?>
Alamat : <?php echo form_input('txt_alamat');?>
Tanggal Lahir : <input type="text" id="datepicker" />
</p>
<?php echo form_submit('btn_search', 'Search');?>
<?php echo form_close(); ?>
</div>
<div>
<?php echo $table ?>
<?php echo $pagination ?>
</div>
</body>
</html>
And its controller :
public function umat() {
//check authorization
if(!isset($_SESSION['username']))
redirect('backend');
//pagination
$config['base_url'] = site_url('/backend/umat/');
$config['total_rows'] = $this->backend_m->count_umat();
$config['per_page'] = 10;
$config['uri_segment'] = 3;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
//table
$data_umat = $this->backend_m->get_umat();
$this->table->set_heading(
'No',
'Nama',
'Kelas',
'Alamat',
'Sekolah',
'Nomor Telepon',
'Keterangan'
);
$no = 1;
foreach($data_umat as $list_temp)
{
$this->table->add_row(
$no++,
$list_temp->nama,
$list_temp->kelas,
$list_temp->alamat,
$list_temp->sekolah,
$list_temp->no_tlpn,
$list_temp->keterangan
);
}
//masukkan data dari DB ke DDL
$data_kelas = $this->backend_m->get_kelas();
$data['list_kelas'][0] = 'Pilih Kelas';
foreach($data_kelas as $row)
{
$data['list_kelas'][$row->kelas_id] = $row->kelas;
}
/*$data_search = array('kelas' => 'Kelas',
'nama' => 'Nama',
'alamat' => 'Alamat',
'bulan' => 'Bulan Lahir');*/
$data['table'] = $this->table->generate();
$this->load->view('backend/umat_v', $data);
}
Note that i use pagination in this controller.
Main Problem
Because i use 2 different view(html) in my page, the url will follow the header(tabs) one.
Its url is http://localhost/ci_gabdb/index.php/backend_home
Everything works fine until i click the second page of my pagination's index. The url will change to http://localhost/ci_gabdb/index.php/backend/umat/10 and it makes my page lost its css and header(tabs).
Screen shoot
Before i click any pagination (the pagination index is below, i dont include it so you can see the header and tabs) : (http://localhost/ci_gabdb/index.php/backend_home)
After i click the second page of my pagination's index : (http://localhost/ci_gabdb/index.php/backend/umat/10)
Sorry for the long post :D Please kindly help me if you have any solution to this problem, i dont mind to change my code a lot.
You need to rethink how you're doing your templates. I use templates too, what you need to do is pass the view to the template.
Basic example.
Template page:
$this->load->view('header');
$this->load->view('content',$main_content);
$this->load->view('footer');
Then in your controllers for each page you do this:
$data['main_content'] = 'umat';
$this->load->view('template',$data);
So essentially what you're going to do is EVERY page you load is going to load the template file, the specific page is going to pass to the correct place in that template via $data.
This way you don't have to try and pass multiple views from every controller function and you don't have to worry about things like the issue you have now where pagination requires a single url.
If I'm understanding your issue correctly reworking your pages to load like this should solve your problem.

jQuery TypeError: example("input#autocomplete").autocomplete is not a function

I have tried alot to remove this error but could not get success.When i am running this script on localhost its working fine but not working on Joomla frame work.
The code is below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<?php $viewFields=array('c++', 'java', 'php', 'coldfusion', 'javascript', 'asp', 'ruby'); ?>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
var example=jQuery.noConflict();
var arrayFromPHP = <?php echo json_encode($viewFields) ?>;
example(document).ready(function() {
example("input#autocomplete").autocomplete({
source: arrayFromPHP
});
});
</script>
</head>
<body>
<center>
<p><img src="<?php echo JURI::base(); ?>images/search_1.png" border="0" alt="" />
<img src="<?php echo JURI::base(); ?>images/business_2.png" border="0" alt="" />
<img src="<?php echo JURI::base(); ?>images/review_3.png" border="0" alt="" />
</p>
</center>
<input id="autocomplete" />
</body>
</html>
Its giving me this error:-
--
[08:30:24.870] Use of getAttributeNode() is deprecated. Use getAttribute() instead. # http://50.116.97.120/~amarhost/storage/media/system/js/mootools-core.js:343
[08:30:27.853] TypeError: example("input#autocomplete").autocomplete is not a function # http://50.116.97.120/~amarhost/storage/index.php/component/storage/?action=war&Itemid=105:210
Maybe noconflict clear everything that is added to jQuery. try to put noconflict just after the you load jQuery
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script>var example=jQuery.noConflict();</script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
var arrayFromPHP = <?php echo json_encode($viewFields) ?>;
example(document).ready(function() {
example("input#autocomplete").autocomplete({
source: arrayFromPHP
});
});
</script>
I would like to add that there could be multiple jquery file included. Maybe from other included php files. Remove this inclusion and keep only at one place. Best way is to include this js file in some php file and then
include in the required file using include_once('jquery_include.php');.
This will probably solve your problem. I had this same problem. This solved my problem.
Some thing like this.
jquery_include.php
<script src="scripts/jquery.js" type="text/javascript"></script>
then include this php file in required php files.
include_once('jquery_include.php');
Hope this help.

jQuery click event not working from php listing

I have a story uploading system on my webpage, which uploads stories in a specified folder, and from that it lists their content to the webpage. I made a split, so only 300 chars are shown of the text, when the user clicks it, the rest of it is shown.
Here is my code:
This one lists it:
<?php foreach($dataArray as $data) { ?>
<div class="visible">
<?php echo $data[0]; ?>
</div>
<div class="hidden">
<?php echo $data[1]; ?>
</div>
<?php } ?>
This is my jQuery:
$('.hidden').css('display', 'none');
$('.visible').click(function () {
$('.hidden').css('display', 'inline');
});
This page('tortenetek.php') is ajaxed to the main page ('blog.php'). I included Jquery in blog.php like this:
<link href='http://fonts.googleapis.com/css?family=Niconne&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="../css/stilus.css"/>
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../js/tinybox.js"></script>
<script type="text/javascript" src="../js/ajax.js"></script>
<link href="../css/lightbox.css" rel="stylesheet" />
<script src="../js/lightbox.js"></script>
<script src="../js/story.js"></script>
Story.js is the script file i'm using.
Thanks folks!
Use .on method to attach event to dynamically added elements.
Change it to
$('.visible').on('click',function () {
$('.hidden').css('display', 'inline');
});

Jquery color picker not working after ajax call

In my site I have added a jQuery color picker textbox as like:
http://www.eyecon.ro/colorpicker/
When loading page through ajax then this color picker is not working. That means color picker is not working after ajax call.
How can i solve this problem?
My site is a CodeIgniter site:
This is my index page source code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Rock website</title>
<link href="<?php echo base_url();?>style/style_user_admin.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>style/jquery-jvert-tabs-1.1.4.css" />
<script type="text/javascript" src="<?php echo base_url();?>/js/ajaxupload.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>js/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>js/colorpicker.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>js/eye.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>js/utils.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>js/layout.js?ver=1.0.2"></script>
<link rel="stylesheet" href="<?php echo base_url();?>css/colorpicker.css" type="text/css" />
<script type="text/javascript" src="<?php echo base_url();?>js/jquery-jvert-tabs-1.1.4.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>js/jquery.cleditor.css" />
<script type="text/javascript" src="<?php echo base_url();?>js/jquery.cleditor.js"></script>
<script type="text/javascript">
$(document).ready(function(){
page_setup();
});
</script>
<script type="text/javascript">
function page_setup()
{
$.ajax({
type: "POST",
url: "<?php echo base_url();?>index.php/super_admin/page_setup/",
success: function(msg){
//alert(msg);
$("#page_setup").html(msg).show();
}
});
}
</script>
</head>
<body>
<div class="wraper">
<div class="welcome_to_admin">
Super Admin Panel
</div>
<div class="admin_main">
<div id="vtabs1">
<div>
<ul>
<li>Page Setup</li>
</ul>
</div>
<div>
<div id="page_setup">
<!--
load the page_setup.php page here
-->
</div>
</div>
</div>
</div>
</div>
</body>
</html>
This is the super_admin controller code:
public function page_setup()
{
$this->load->view('super_admin/page_setup');
}
This is the page_setup.php page code:
<div class="tab1_rgt_part">
<div class="message_to_send_11">Color Settings</div>
<div class="tab1_main_part" style="margin-top:20px;">
<div class="tab1_left_part">Welcome Page Bg Color</div>
<input type="text" maxlength="6" size="6" id="colorpickerField1" value="00ff00" />
</div>
try adding the color picker after loading the html:
function page_setup()
{
$.ajax({
type: "POST",
url: "<?php echo base_url();?>index.php/super_admin/page_setup/",
success: function(msg){
//alert(msg);
$("#page_setup").html(msg).show();
$("#colorpickerField1").ColorPicker(
onChange: function (hsb, hex, rgb) {
$(this).val(hex);
}
);
}
});
}
$('#colorpickerField1, #colorpickerField2, #colorpickerField3,#colorpickerField4).ColorPicker({
onSubmit: function(hsb, hex, rgb, el) {
$(el).val("#"+hex);
//$(el).css("background-color","#"+hex);
$(el).ColorPickerHide();
},
onBeforeShow: function () {
$(this).ColorPickerSetColor(this.value);
}
})
I found the answer.Add this code in a script tag at the top of the view page

Categories