I can't load index.php file in view folder. The error displayed is
"Unable to load the requested file: calendar/index.php"
Here is the code
controller(Calendar.php):
*public function __construct() {
Parent::__construct();
$this->load->model("calendar_model");
}
public function index()
{
$this->load->view("calendar/index.php", array());
}*
model(Calendar_model.php):
*?php
class Calendar_Model extends CI_Model
{
}
?>*
view (index.php):
*<div class="container">
<div class="row">
<div class="col-md-12">
<h1>Calendar</h1>
<div id="calendar">
<script type="text/javascript">
$(document).ready(function() {
$('#calendar').fullCalendar({
});
});
</script>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
});
</script>*
Better rename your index.php like V_index.php
for this case remove .php from your code
public function __construct()
{
Parent::__construct();
$this->load->model("calendar_model");
}
public function index()
{
$this->load->view("calendar/index", array());
}
Related
Hi guys i am first time in coding codeigniter and my create CMS upload image and show in slider and my error is backtrace and this is my code View.php
<section class="home-slider owl-carousel">
<?php foreach($data as $row) { ?>
<div class="slider-item" style="background-image: url(); width: auto; background-repeat:no-repeat; background-size: contain; background-position:center;">
<div class="container">
<div class="row slider-text align-items-center">
</div>
</div>
</div>
<?php } ?>
model.php
<?php
class HomeModel extends CI_Model {
function __construct() {
parent::__construct();
}
public function selectAllData() {
$this->db->select("file_name,description");
$this->db->from('tbl_slider');
$query = $this->db->get();
return $query->result();
} }
controller.php
class Home extends CI_Controller {
function __construct() {
parent::__construct();
}
function index(){
$this->load->model('HomeModel');
$data['all_data'] = $this->HomeModel->selectAllData();
$this->templates('home_index', $data);
}
function templates($page) {
$this->load->view('templates/header');
$this->load->view($page);
$this->load->view('templates/navbar');
$this->load->view('templates/footer');
$this->load->view('templates/footer-js');
}
}
thank you for respond
You need to set some height and url of background image as below :
<section class="home-slider owl-carousel">
<?php foreach ($data as $row) { ?>
<div class="slider-item" style="background-image: url(demo.jpg); height: 200px; width: auto; background-repeat:no-repeat; background-size: contain; background-position:center;">
<div class="container">
<div class="row slider-text align-items-center">
</div>
</div>
</div>
<?php } ?>
</section>
I want to create a login with Facebook in my website. I found a code in the internet that made it simple loading the library of Facebook php sdk. I tried the code but it doesn't work in me. Please help me how to do login with facebook in codeigniter.
Here is the code :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once( APPPATH . 'libraries/facebook/src/facebook.php' );
class FacebookApp extends Facebook {
var $ci;
var $facebook;
var $scope;
public function __construct() {
$this->ci =& get_instance();
$this->facebook = new Facebook(array('appId' => $this->ci->config->item('app_id'),'secret' => $this->ci->config->item('app_secret'), 'cookie' => true));
$this->scope = 'public_profile';
}
public function login_url() {
$params = array('scope' => $this->scope);
return $this->facebook->getLoginUrl($params);
}
public function logout_url() {
return $this->facebook->getLogoutUrl(array('next' => base_url() .'logout'));
}
public function getFbObj(){
return $this->facebook;
}
public function get_user() {
$data = array();
$data['fb_user'] = $this->facebook->getUser();
if ($data['fb_user']) {
try {
$data['fb_user_profile'] = $this->facebook->api('/me');
return $data;
} catch (FacebookApiException $e) {
$this->facebook->destroySession();
$fb_login_url = $this->facebook->getLoginUrl(array('scope' => $this->scope));
redirect($fb_login_url, 'refresh');
}
}
}
here is my controller :
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class User_Authentication extends CI_Controller
{
function __construct() {
parent::__construct();
// Load user model
$this->load->model('auth/user_model');
$this->load->library('facebook/FacebookApp');
}
public function index(){
$obj_fb = new FacebookApp();
$fb_user_data = $obj_fb->get_user();
$data['fb_login_url'] = $obj_fb->login_url();
}
}
and here is my view:
<div class="modal fade" id="choose" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header btn-success">
<h3 class="modal-title">Connect with</h3>
</div><!-- modal-header -->
<div class="modal-body">
<div class="connectwith">
<form class="form-horizontal" id="payment">
<button onclick="<?php echo base_url()?>User_authentication" class="btn btn-primary"> Continue with Facebook </button>
</form><!-- form-horizontal -->
</div>
</div><!-- modal-body -->
</div><!-- modal-content -->
</div><!-- modal-dialog -->
</div><!-- choose -->
it shows no error when i check it on my console, i don't know what's happen, i am a beginner in adding libraries. Please help me with this. Thanks
First of all load url helper so you can use base_url().Load helper in controller...
function __construct() {
parent::__construct();
//Load Helper
$this->load->helper('url');
// Load user model
$this->load->model('auth/user_model');
$this->load->library('facebook/FacebookApp');
}
In your view replace
onclick="<?php echo base_url()?>User_authentication"
To
onclick="<?php echo base_url('user_authentication');?>"
Use this github https://github.com/bhawnam193/php-programs/tree/master/facebook-login for using fb login .
Firstly make a facebook app and replace the
$app_id ,$app_secret, $site_url
in file fbaccess.php.
I need to reload a content of my Yii widget via AJAX every XX seconds.
This is my widget code:
class UserOnlineWidget extends CWidget
{
public function init(){
}
public function run(){
$userOnline=User::getOnlineUser();
$this->render("userOnLineWidget", array('userOnline'=>$userOnline));
}
}
And this is the view userOnLineWidget.php:
<div class="userOnline">
<h5>User Online</h5>
<ul>
<?php
foreach($userOnline as $user) {
?>
<li>
<ul>
<li><?php echo CHtml::link($user['username'], array('/site/view/'.$user['id'])); ?></li>
<li><?php echo ($user['online'] != null)? 'online' : 'offline'; ?></li>
</ul>
</li>
<?php
}
?>
</ul>
</div>
How can I do this ? I use Yii 1.1.
Here a small example. I hope this help you. Widget which show time from server every second.
//SiteController
public function actionTest()
{
$this->render('my_view'); //just rendering view
}
public function actionContent()
{
$this->widget('time'); //return html of widget. use for ajax
}
//my_view.php
<script src="<?php echo $this->assetsBase ?>/js/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
setInterval(function() {
$.get('/site/content', {}, function(data) {
$('#widget').html(data);
});
}, 1000); //update widget content every second
});
</script>
<div id="widget">
<?php $this->widget('time'); // render widget ?>
</div>
//widget
class Time extends CWidget
{
public function init(){
}
public function run(){
$date = new DateTime();
$this->render("test", array('time'=>$date->format('H:i:s')));
}
}
//view for widget test.php
<p><?= $time ?></p>
I am calling an AJAX function from WordPress plugin through admin-ajax.php. But when the request is send, its destroying the session.
I have an array where data is saved on every request, but on every request previous data is destroyed.
AJAX code i am calling:
function cartbox()
{
var url = {
'action':'my_cart_action',
'rnd':Math.random(),
};
$.ajax({
type:'POST',
data:url,
url: "http://localhost/vmlogic/wp-admin/admin-ajax.php",
success : function(response)
{
$("#cartdiv").html(response);
}
});
}
On plugin index file i am calling this:
class cloud_calculator{
// Call a cation on link click
function cloud_calculator()
{
add_action('init' , array($this,'cloud_init'));
}
public function cloud_init()
{
add_action('wp_head' , array($this, 'plugin_jquery_func'));
add_action('admin_menu', array($this,'my_menu'));
add_shortcode('cloud_calculator', array($this,'my_calculator'));
add_action('the_content', array($this,'the_content_action'));
add_action( 'wp_ajax_my_unique_action', array($this,'my_unique_action_callback'));
add_action( 'wp_ajax_nopriv_my_unique_action', array($this,'my_unique_action_callback'));
add_action( 'wp_ajax_my_cart_action', array($this,'my_cart_action_callback'));
add_action( 'wp_ajax_nopriv_my_cart_action', array($this,'my_cart_action_callback'));
}
public function plugin_jquery_func()
{
$plugins_url = plugins_url().'/cloud-calculaor/';
?>
<script type="application/javascript">
var PluginUrlJs = '<?php echo $plugins_url ;?>';
</script>
<?php }
public function the_content_action($content)
{
$content = str_replace('[cloud_calculator]',do_shortcode('[cloud_calculator]') ,$content );
return $content;
}
// Menu call function
public function my_menu() {
add_menu_page('Cloud Calculator', 'Cloud Calculator', 'manage_options', 'cloud-calculaor/cloud-calculaor.php', array($this, 'my_function'));
}
// action to call on admin menu
public function my_function() {
wp_enqueue_style('style', '/wp-content/plugins/cloud-calculaor/style/admincalculator.css');
echo
'<div class="wrap">
<h2>Cloud Calculator</h2>
<div class="plugincode">
<div style=" padding:10px 10px 10px 50px;">
<p style="margin:5px 0px">
To Insert <strong>CLOUD CALCULATOR</strong> shortcode inside a page or post:<br>
<br>
Use: <code><strong>[cloud_calculator]</strong></code><br>
<br>
For more queries contact the administrator!<br>
</p>
</div>
</div>
</div>
';
}
I have write a some codeigniter code, when I click button add a data, and the table will ajax reload, not reload the page. How to modify my code? Thanks
This is my controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Big_category extends CI_Controller {
function __construct() {
...
}
function index() {
if($this->session->userdata('logged_in')) {
$this->page(0);
} else {
show_404('page');
}
}
function page($page) {
....
$data['pagelist']=$this->pagination->create_links();
$data["main_content"] = "big_category_view";
$this->load->view('template', $data);
}
This is my model
class Big_category_model extends CI_Model
{
...
function get_big_category($limit, $start)
{
$this->db->limit($limit, $start);
$query = $this->db->get_where('category1', array('c1_status' => 1)); //SELECT * FROM category1
return json_encode($query->result());
}
This is my view
...
<? $data = json_decode($all_big_category); ?>
<? foreach($data as $key => $value): ?>
<tr class="modify_tr">
<td><?=($key+1)?></td>
<td id="td_id_<?=$value->c1_id?>" class="modify_td">
<span id="c1_id_<?=$value->c1_id?>"><?=$value->c1_name?></span>
<form class="form-search td_id_<?=$value->c1_id?>">
<input type="text" name="input_c1_id" id="input_c1_id_<?=$value->c1_id?>">
<button class="btn modify" id="button_c1_id_<?=$value->c1_id?>" c1-id="<?=$value->c1_id?>" type="button"><i class="icon-edit"></i></button></td>
</form>
<td><button class="btn btn-danger"><i class="icon-remove-sign"></i></button></td>
</tr>
<? endforeach ?>
</table>
<?=$pagelist?>
...
Here is a simple technique of how you can achieve this.
Layout(Template)
<html>
<body>
<div><!--other stuff here--></div>
<div id = 'form_id'>
<?php echo $content?>
</div>
</body>
</html>
Controller
function index()
{
if($this->input->is_ajax_request()){
//load form here
$this->load->view('form');
}else{
//this will load the form for the first time
//pass third parameter as TRUE so it will returned as string
//assigned to index content which will be displayed in layout
$data['content'] = $this->load->view('form',$data , TRUE);
//load template here
$this->load->view('template', $data);
}
}
JQuery
$.ajax({
type : 'POST',
url : '<?php echo site_url('controllername/index')?>',
data : '' // query string
success : function(formagain){
$('#form_id').html(formagain);
//this will replace the content of div with new form
}
});