My controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Calendar extends MX_Controller
{
function index()
{
$this -> display( $year=null, $month=null);
}
function display($year=null,$month=null)
{
if( ! $this->bitauth->logged_in())
{
$this->session->set_userdata('redir', current_url());
redirect('access/login');
}
$data['header']=Modules::run('header/header/index');
$data['footer']=Modules::run('footer/footer/index');
$conf=array(
'start_day'=>'monday',
'day_type'=> 'long',
'show_next_prev'=>true,
'next_prev_url'=>'http://datacentral.demo/calendar/'
);
$this->load->library('calendar',$conf);
$this->load->view('calendar',$data);
}
}
My views
<?php echo $this->calendar->generate($this->uri->segment(3), $this->uri->segment(4)); ?>
When I change the month, the url looks normal eg. http://example.com/calendar/2017/06 but I keep getting this 404 error not found page.
No route specified in my config file. What am I missing?
I believe you will need to create a route liek below:
$route['calendar/(:any)/(:any)'] = 'calendar/display';
Try this route link:
$route['calendar/(:any)/(:any)'] = 'calendar/display/$1/$2';
Related
I'm a very happy user of XCRUD V 1.6. I want to integrate it in Codeigniter 3 but when I use the codeigniter session-library in for my XCRUD-pages I get an error in XCRUD: "The verification key is out of date". When the session-library from codeigniter is not being used, XCRUD is working fine. Is there anyone who can tell me how to fix? I need the codeigniter session-library in my xcrud pages for user-details.
This is my current controller: (the session library is loaded in the login_model)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cms extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('url');
include('cms/xcrud/xcrud.php');
$this->load->model("login_model");
}
public function nieuws()
{
$xcrud = Xcrud::get_instance();
$xcrud->table('nieuws');
$output['output'] = $xcrud->render();
$this->_cms_output($output);
}
function useAuthorID($post_array) {
$post_array['afdeling_id'] = $this->login_model->id();
return $post_array;
}
function useCatID($post_array) {
$post_array['nieuwscat_afdeling_id'] = $this->login_model->id();
return $post_array;
}
function _cms_output($output = null)
{
$this->load->view('beheer/default',$output);
}
}
Assuming that you are using xcrud's CI integration examples, you may try the following in xcrud_config.php:
Use the same session name that your CI installation is using, if it differs from "PHPSESSID".
Use alternative session.
defined('BASEPATH') OR exit('No direct script access allowed');
require('application/libraries/REST_Controller.php');
use Restserver\Libraries\REST_Controller;
class demo extends REST_Controller {
function __construct(){
parent::__construct();
}
public function demo1_get()
{
echo 'demo 1';
}
}
Error Image
enter image description here
This is My REST_Controller
enter image description here
Hi, I m getting Error for making Codeigniter RESTful API. Please Help me to solve this problem.
It should be like this :
Make sure you have REST_Controller.php in your libraries folder
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . '/libraries/REST_Controller.php';
class Demo extends REST_Controller
{
function __construct(){
parent::__construct();
}
public function demo1_get()
{
echo 'demo 1';
}
}
You need to follow the link https://itsolutionstuff.com/post/codeigniter-3-restful-api-tutorialexample.html
and then after you run the code you will get a small error Unable to load the requested language file: language/english/rest_controller_lang.php
The problem is that codeigniter can't find the rest_controller translations. You just need to create this file /application/languages/english/rest_controller_lang.php
Then copy & paste this code inside:
<?php
/*
* English language
*/
$lang['text_rest_invalid_api_key'] = 'Invalid API key %s'; // %s is the REST API key
$lang['text_rest_invalid_credentials'] = 'Invalid credentials';
$lang['text_rest_ip_denied'] = 'IP denied';
$lang['text_rest_ip_unauthorized'] = 'IP unauthorized';
$lang['text_rest_unauthorized'] = 'Unauthorized';
$lang['text_rest_ajax_only'] = 'Only AJAX requests are allowed';
$lang['text_rest_api_key_unauthorized'] = 'This API key does not have access to the requested controller';
$lang['text_rest_api_key_permissions'] = 'This API key does not have enough permissions';
$lang['text_rest_api_key_time_limit'] = 'This API key has reached the time limit for this method';
$lang['text_rest_ip_address_time_limit'] = 'This IP Address has reached the time limit for this method';
$lang['text_rest_unknown_method'] = 'Unknown method';
$lang['text_rest_unsupported'] = 'Unsupported protocol';
Hope this helps
Hi i have this data passed in the url
http://www.test.com/dashboard/john-doe
i want to get the page when i enter http://www.test.com/dashboard/john-doe
john doe is a name from the database i retrieve when the users can login.
so dashboard is a controller then how will i able to get the page if i passed a data john-doe next to dashboard controller? can someone help me figured this thing out? Any help is muchly appreicated this is my controller below
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Dashboard extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('users_model', 'um');
$sessionData = $this->session->userdata('loggedIn');
$this->data['id'] = $sessionData['userID'];
if(!$this->session->userdata('loggedIn')){
redirect('login');
}
}
public function index($slug){
echo $slug; exit;
$this->data['title'] = 'Dashboard | test';
$this->data['menu'] = 'dashboard';
//get CustomerInfo
$this->data['getCustomerInfo'] = $this->um->getCustomerInfo($this->data['id']);
$this->template_lib->set_view('templateLogIn', 'dashboard', $this->data,'',$this->data);
}
}
The index function is loaded by default if the second segment of the URI is empty. If you have parameters you need to define a route:
$route['dashboard/(:any)'] = "dashboard/index/$1";
I want to know how can I write a component in codeigniter
I have worked with symfony1.4 and there there is something include_component("name",dataarray()) that we can load a component ( it's actually an action ).
I already know that we have $this->load->view('admin/template/login') for loading a view, But I want to know is there any way to call an action like this?
this->load(news/list,array('date'=>xxx-xx-xx))
thanks anyways
you can this through the use of libraries, helpers or plugins.
an example of using a library class in application/library called LoadNews.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class LoadNews {
public function showList($date_array) {
// do stuff with date array
}
}
/* End of file LoadNews.php */
/* Location: ./application/libraries/LoadNews.php */
then in your controller, you call
$this->load->library('LoadNews');
$this->loadnews->showList(array('date'=>'2014-12-19'));
Yes, you can do this from CI 3.
In your Controller or View just call $this->load->view(view, data);
Example:
<?php
defined('BASEPATH') or die('No direct script allowed');
class PageController extends CI_Controller
{
public function index()
{
$data = [
'names' => ['john', 'doe'],
'ages' => ['24', '30']
];
$this->load->view('index', $data);
}
}
?>
And in your view you can access 'names' and 'ages' as $names and $ages respectively.
You can do this in your view:
<?php
echo '<pre>';
print_r($names);
print_r($ages);
echo '</pre>';
?>
The result:
Array (
[0] => john
[1] => doe
)
Array (
[0] => 24
[1] => 30
)
I have blueimp file upload working well with codeigniter. I use the UploadHandler library as is. But I want to extend it to replace two functions that create the unique filename. The code for this is in the BlueImp Github wiki.
I created an extended library thus:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_UploadHandler extends UploadHandler {
public function __construct() {
parent::__construct();
$CI =& get_instance();
$CI->load->library('UploadHandler');
}
protected function upcount_name_callback($matches) {
$index = isset($matches[1]) ? intval($matches[1]) + 1 : 1;
$ext = isset($matches[2]) ? $matches[2] : '';
return '-'.$index.''.$ext;
}
protected function upcount_name($name) {
return preg_replace_callback(
'/(?:(?:-([\d]+))?(\.[^.]+))?$/',
array($this, 'upcount_name_callback'),
$name,
1
);
}
}
When I try to run it, I get an 'unable to load UploadHandler' error. If I remove my MY extension, the original code runs. What is wrong with my extension code? Isn't this the proper way to extend CI libraries?
And, yes, the filename for my file is MY_UploadHandler.php
Thanks!
I noodled over this for a while and finally figured it out. To extend a custom library, you need to 'require once' the file it is extending, prior to the definition of the class.
EX:
require_once("UploadHandler.php");
class MY_UploadHandler extends UploadHandler
{
}
Hopefully that helps.