Get 500 his page isn’t working when run migrate codeigniter2 - codeigniter-2

I get a 500 page isn’t working when run migrate codeigniter2. I am new here and it's take me days from this bug
Migate controller
<?php
class Migrate extends CI_Controller
{
public function index()
{
$this->load->library('migration');
if ($this->migration->current() === FALSE)
{
show_error($this->migration->error_string());
}
}
}
Config database
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'passw';
$db['default']['database'] = 'first_app';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
Migration file
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Migration_Add_blog extends CI_Migration {
public function up()
{
$this->dbforge->add_field(array(
'blog_id' => array(
'type' => 'INT',
'constraint' => 5,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'blog_title' => array(
'type' => 'VARCHAR',
'constraint' => '100',
),
'blog_description' => array(
'type' => 'TEXT',
'null' => TRUE,
),
));
$this->dbforge->add_key('blog_id', TRUE);
$this->dbforge->create_table('blog');
}
public function down()
{
$this->dbforge->drop_table('blog');
}
}
and when I tried to find buss using echo, the following line cannot run:
$this->load->library('migration');
I don't know why?
Please help me .

Related

file uploading multiple times in codeigniter

i am trying to upload files in codeigniter.but my files are uploading multiple times.this is my controller code.
public function savedocument() {
if (isset($_FILES) && !empty($_FILES)) {
$category_id = $_POST['category'];
$category_name = $_POST['category_name'];
$config = array();
$config['upload_path'] = 'uploadpath';
$config['allowed_types'] = 'gif|jpg|png|pdf|doc|docx';
$config['max_size'] = '20480';
$config['overwrite'] = FALSE;
$this->load->library('upload', $config);
$files = $_FILES;
for($i=0; $i< count($_FILES['files']['name']); $i++)
{
$_FILES['files']['name']= $files['files']['name'][$i];
$_FILES['files']['type']= $files['files']['type'][$i];
$_FILES['files']['tmp_name']= $files['files']['tmp_name'][$i];
$_FILES['files']['error']= $files['files']['error'][$i];
$_FILES['files']['size']= $files['files']['size'][$i];
$this->upload->initialize($config);
if (!$this->upload->do_upload('files')) {
$response['message'] = $this->upload->display_errors();
}
else {
$this->upload->do_upload('files');
$file_details = $this->upload->data();
//print_r($file_details);
$user_id = $this->session->userdata('user_id');
$uploaded_file_details = array(
'tmp_name' => $file_details["file_name"],
'file_name' => $file_details["orig_name"],
'size' => $file_details["file_size"],
'type' => $file_details["file_type"],
'category_name' => $category_name,
'category_id' => $category_id,
'upload_at' => date("Y-m-d H:i:s"),
'uploaded_by' => $user_id
);
$document_id = $this->document->CraeteNewDocument($uploaded_file_details);
}
redirect('admin/documents', 'refresh');
}
}
}
can anyone point out the issue.how to make if there is only one file to upload upload it once and if multiple files are selected.have to upload it.

Codeigniter Database Query Caching No Updating With New Data Or Removed Data

When I add new category to my database it insert fine. But the Codeigniter Database Query Cache does not update when add or remove
Question: Once I add a new category or delete a category how to make sure the codeigniter database cache query gets updated correct
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'community',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => TRUE,
'cachedir' => APPPATH . 'cache/database/',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Forum Model
public function getcategories() {
$this->db->cache_on(); // Cache On
$query = $this->db->select('*')
->order_by('name', 'asc')
->from('forum')
->get();
if ($query->num_rows() > 0) {
return $query->result_array();
} else {
return array();
}
}
public function add() {
$this->db->trans_start();
$this->db->trans_strict(FALSE);
$insert = array(
'name' => $this->input->post('title'),
'type' => $this->input->post('type'),
'pid' => $this->input->post('pid')
);
$this->db->insert($this->db->dbprefix . 'forum', $insert);
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
return FALSE;
} else {
$this->db->trans_commit();
return TRUE;
}
}
public function categories_for_deletion($fid) {
$this->db->where('fid', $fid);
$this->db->or_where('pid', $fid);
$query = $this->db->delete('forum');
$this->db->cache_delete('admin', 'category');
if ($query) {
return TRUE;
} else {
return FALSE;
}
}
Controller
<?php
class Category extends MX_Controller {
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
$this->load->library('forum');
$this->load->model('admin/forum/forum_model');
}
public function add() {
$this->form_validation->set_rules('title', 'title', 'required');
if ($this->form_validation->run() == TRUE) {
$this->forum_model->add();
redirect('admin/category');
}
$data['header'] = Modules::run('admin/common/header/index');
$data['footer'] = Modules::run('admin/common/footer/index');
$data['categories'] = $this->forum->generate_select();
$this->load->view('template/forums/category_add_view', $data);
}
public function edit($fid) {
$this->form_validation->set_rules('title', 'title', 'required');
if ($this->form_validation->run() == TRUE) {
}
$data['header'] = Modules::run('admin/common/header/index');
$data['footer'] = Modules::run('admin/common/footer/index');
$this->load->view('template/forums/category_edit_view', $data);
}
public function delete($fid) {
$delete = $this->forum_model->categories_for_deletion($fid);
if ($delete == TRUE) {
redirect('admin/category');
}
$this->index();
}
public function index() {
$data['categories'] = '';
if ($this->forum_model->getcategories()) {
$data['categories'] = $this->forum->set_categories_list($this->forum_model->getcategories());
}
$data['header'] = Modules::run('admin/common/header/index');
$data['navbar'] = Modules::run('admin/common/navbar/index');
$data['footer'] = Modules::run('admin/common/footer/index');
$this->load->view('template/forums/category_view', $data);
}
}
As kishor10d said, the queries will neither update, nor expire automatically or after any duration. You'll have to do it manually, but it doesn't require a cron job or anything. Codeigniter has a method for it.
After every update, you have to do a
$this->db->cache_delete('controller', 'method');
If you don't pass any parameters, it uses current URI to delete associated cache. When your query completes, the cache will be added again giving an effect of an update.
Reference: $this->db->cache_delete() on CodeIgniter Documentation

Codeigniter- make an access denied if the user tried to enter a pass that belong to another user level

I have in controller Admin.php, Members.php, Atendementos.php and same in views added this folders, and there is script to redirect to each one depend on the user level.
What I need to make a secure path that if user is not an admin and tried to go to app/admin/access for example have to give him a massage that he can't access this page. how can i do that ? thank you.
this is my solution
application/libraries/My_auth.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Auth{
protected $CI;
public $sess_array = array();
public function __construct(){
$this->CI =& get_instance();
}
public function login_user( $usr = '', $psw = '', $where = NULL ){
$result = $this->CI->db->get_where('user', array($where => $usr, 'password' => $psw))->row();
return ($result) ? TRUE : FALSE;
}
public function create_session( $usr = '', $psw = '', $where = NULL ){
$result = $this->CI->db->get_where('user', array($where => $usr, 'password' => $psw))->row();
$language = $this->CI->session->userdata('language');
$this->CI->session->set_userdata('id', $result->id);
$this->CI->session->set_userdata('email', $usr);
$this->CI->session->set_userdata('username', $result->username);
$this->CI->session->set_userdata('level', $result->level);
$this->CI->session->set_userdata('language', $language);
$cookie = array(
'name' => 'elddenmedio_session',
'value' => '57',
'expire' => '86500',
'domain' => '.' . base_url(),
'path' => '/',
'prefix' => '',
'secure' => TRUE
);
$this->CI->input->set_cookie($cookie);
}
//
public function has_permission( $level = '' ){
if($this->get_level() != $level){
redirect(base_url(), 'refresh');
}
}
public function get_level(){
return ( empty($this->CI->session->userdata('level'))) ? LEVEL_PUBLIC : $this->CI->session->userdata('level');
}
//more methos
}
controller application/noram_user.php
class Normal_user extends CI_Controller{
var $user_id;
function __construct(){
parent::__construct();
$this->auth->has_permission('normal_user');
$this->user_id = $this->session->userdata('id');
}
}
application/admin.php
class Normal_user extends CI_Controller{
var $user_id;
function __construct(){
parent::__construct();
$this->auth->has_permission('admin');
$this->user_id = $this->session->userdata('id');
}
}

How to get the uploaded filename from upload.php page Codeigniter

I have Upload.php page as follows=>
<?php
class Upload extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper(array('form', 'url'));
}
public function index() {
$this->load->view('upload_form', array('error' => ' ' ));
}
public function do_upload() {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pgn';
$config['max_size'] = 0;
//$config['max_width'] = 1024;
//$config['max_height'] = 768;
$config['detect_mime'] = TRUE;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else {
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
}
?>
and the Hesaplama.php controller as =>
$upload_data = $this->upload->data(); //(line 51) Should return array of containing all of the data related to the file you uploaded.
$file_name = $upload_data['file_name'];
$file = fopen("<?php echo site_url('uploads/$file_name'); ?>", "r");
while(! feof($file))
{...
However I get the following error =>
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Hesaplama::$upload
Filename: controllers/Hesaplama.php
Line Number: 51
Backtrace:
File: D:\wamp\www\proje\application\controllers\Hesaplama.php
Line: 51
Function: _error_handler
File: D:\wamp\www\proje\application\controllers\Hesaplama.php
Line: 249
Function: pgn_oku
File: D:\wamp\www\proje\application\controllers\Welcome.php
Line: 28
Function: pozisyon_tutma
File: D:\wamp\www\proje\index.php
Line: 292
Function: require_once
How can we remedy that and get the file name of the newly uploaded file?
I personally think that the program does not recognize the data in another page(controller).
Thank you...
Sorry i can't comment yet, so i write it here. I think the library for
$this->upload->data();
wasn't loaded.
if you want to get only the filename, maybe you can try using session.
in Upload controller:
$data = $this->upload->data();
$this->session->set_userdata('filename', $data['file_name']);
in Hesaplama :
$filename = 'uploads/'.$this->session->userdata('filename');
$file = fopen("<?php echo site_url('$filename'); ?>", "r");
hope this help.
to get the filename and extention file to save it in a db you can use tis
<?php
class Upload extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper(array('form', 'url'));
}
public function index() {
$this->load->view('upload_form', array('error' => ' ' ));
}
public function do_upload() {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pgn';
$config['max_size'] = 0;
$config['detect_mime'] = TRUE;
$this->load->library('upload', $config);
if( ! $this->upload->do_upload('userfile')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else {
$upload_data = $this->upload->data();
/*
Array
(
[file_name] => mypic.jpg
[file_type] => image/jpeg
[file_path] => /path/to/your/upload/
[full_path] => /path/to/your/upload/jpg.jpg
[raw_name] => mypic
[orig_name] => mypic.jpg
[client_name] => mypic.jpg
[file_ext] => .jpg
[file_size] => 22.2
[is_image] => 1
[image_width] => 800
[image_height] => 600
[image_type] => jpeg
[image_size_str] => width="800" height="200"
)
*/
$this->model->save_img_info($upload_data['file_name']);
$data = array('upload_data' => $upload_data );
$this->load->view('upload_success', $data);
}
}
}
?>

404 not found on Codeigniter

I am trying to access my page 'login', and I'm using Codeingiter.
I'm using TAL php too, for templates.
I just defined my routes like this:
$route['default_controller'] = "site";
$route['404_override'] = '';
$route['login'] = 'login';
$route['signup'] = 'login';
$route['success'] = 'login';
And here is my 'login' controller :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_controller{
public function __construct(){
parent::__construct();
$this->tal->setOutputMode(PHPTAL::HTML5);
if($this->session->userdata('loggedIn') == true){
$this->tal->template = 'admin';
$this->tal->login = true;
}else{
$this->tal->template = 'main';
$this->tal->login = false;
}
$this->load->model('membership_model');
}
public function index(){
$requestPage = $this->uri->segment(1);
switch($requestPage){
case 'login':
$this->tal->title = 'Connexion';
$this->tal->display('login.php');
break;
case 'signup':
$this->tal->title = 'Inscription';
$this->tal->display('signup.php');
$this->createMember();
break;
case 'success':
$this->tal->title = 'Inscription validée!';
$this->tal->display('messagePage/signupSuccess.php');
break;
}
}
function validateCredentials(){
$query = $this->membership_model->validate();
if($query){
$userdata = array(
'username' => $this->input->post('username'),
'password' => md5($this->input->post('password')),
'loggedIn' => true
);
$this->session->set_userdata($userdata);
redirect('backoffice/profile/#');
}
$this->index();
}
function createMember(){
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Nom', 'trim|required');
$this->form_validation->set_rules('forename', 'Prénom', 'trim|required');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('adress', 'Adresse', 'trim|required');
$this->form_validation->set_rules('zipcode', 'Code Postal', 'trim|is_natural|required');
$this->form_validation->set_rules('city', 'Ville', 'trim|required');
$this->form_validation->set_rules('country', 'Pays', 'trim|required');
$this->form_validation->set_rules('username', 'Pseudo', 'trim|required|callback_usernameCheck');
$this->form_validation->set_rules('password', 'Mot de passe', 'trim|required|min_length[4]|max_length[32]');
$this->form_validation->set_rules('password2', 'Confirmation du mot de passe', 'trim|required|matches[password]');
$this->form_validation->set_rules('captcha', 'Captcha');
$data = array(
'firstname' => $this->input->post('name'),
'forename' => $this->input->post('forename'),
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'adress' => $this->input->post('adress'),
'zipcode' => $this->input->post('zipcode'),
'city' => $this->input->post('city'),
'country' => $this->input->post('country'),
'password' => $this->input->post('password'),
'passwordHashed' => md5($this->input->post('password'))
);
if($this->form_validation->run() == false){}
else{
$result = $this->membership_model->usernameCheck();
var_dump($result);
switch($result){
case false:echo 'false';
$this->form_validation->set_message('', 'Désolé mais ce nom d\'utilisateur et / ou cet email sont déjà pris');
break;
case true:echo 'true';
$this->membership_model->createMember($data);
redirect('success');
break;
}
}
}
function logout(){
$this->session->sess_destroy();
redirect('/');
}
}//this ends class
My local URL is : http://localhost/dist.
And when I try to access it, with the URL http://localhost/dist/login, I just get '404 Page Not Found : The page you requested was not found.'
I don't understand why. All is ready.
Try accessing the url http://localhost/dist/index.php/login. It doesn't appear that you have removed the index.php in the config file. Here is how to do that.
Have you tried debugging it?
If you don't have any routes defined, do you still get the 404 error?
I would bet that the issue is because you're routing a path to itself, but I don't know for sure.
Take out all of the routes and make sure that the path works. Then, add one at a time until it stops working.

Resources