Datatable error 404 with Codeigniter

0

I have a system made with codeigniter

The system is mounted on SuSE Server and I am using VirtualHost

The problem is that when I make requests to a controller to load a table through datatable with server side processing, the system throws me a 404 error.

This is the Virtual Host configuration

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName directorio
    ServerAlias directorio
    DocumentRoot /srv/www/htdocs/directorio

    # if not specified, the global error log is used
    ErrorLog /var/log/apache2/directorioTelefonico-error_log
    CustomLog /var/log/apache2/directorioTelefonico-access_log combined

<Directory "/srv/www/htdocs/directorio">

        #
        # Possible values for the Options directive are "None", "All",
        # or any combination of:
        #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
        #
        # Note that "MultiViews" must be named *explicitly* --- "Options All"
        # doesn't give it to you.
        #
        # The Options directive is both complicated and important.  Please see
        # http://httpd.apache.org/docs/2.4/mod/core.html#options
        # for more information.
        #
        Options Indexes FollowSymLinks

        #
        # AllowOverride controls what directives may be placed in .htaccess files.
        # It can be "All", "None", or any combination of the keywords:
        #   Options FileInfo AuthConfig Limit
        #
        AllowOverride None

        #
        # Controls who can get stuff from this server.
        #
        <IfModule !mod_access_compat.c>
            Require all granted
        </IfModule>
        <IfModule mod_access_compat.c>
            Order allow,deny
            Allow from all
        </IfModule>
    </Directory>
</VirtualHost>

Configuring the base_url in the config.php file

$ config ['base_url'] = 'http: //'.$_SERVER [' SERVER_NAME '];

Configuring my Escrip js

//Server side processing

$(document).ready(function(){
      $('#tblcontactos').DataTable({
          //'paging'      : true,
          //'lengthChange': false,
          //'searching'   : true,
          //'ordering'    : true,
          //'info'        : true,
          "lengthMenu": [[15, 50, 100, 500], [15, 50, 100, 500]],
          "autoWidth"   : false,
          "stateSave"   : true, // mantiene la busqueda cuando se recarga la pagina
          "processing"  : true,
          "serverSide"  : true,
          "ajax":{
                        "url": rutaContactosSP,
                        "type": "POST",
		                    "data":{ get_csrf_token_name : get_csrf_hash }
		       },
          "columns": [
                      //{ "data": "id" },
                      { "data": "nombre" },
                      { "data": "empresa" },
          	          { "data": "departamento" },
                      { "data": "extension" },
                      { "data": "email" }
          ],
    }) // fin de $('#tblcontactos').DataTable({
}) // fin de document.ready.function

Configuring my View

    // impresion de variable para uso en Scrip contactos
    var rutaContactosSP     ="<?php echo base_url('ControllerContactos/posts');?>";
    var base_url            ="<?php echo base_url();?>";
    var get_csrf_token_name ="<?php echo $this->security->get_csrf_token_name();?>";
    var get_csrf_hash       ="<?php echo $this->security->get_csrf_hash();?>";
<div class="row">
     <div class="col-xs-12">
          <div class="box">
               <div class="box-body">
                    <table id="tblcontactos" class="table table-bordered"  style="font-size:11px;font-family:Comic Sans MS,arial,verdana">
                          <thead>
                              <tr>
                                  <th style="width: 20%;background-color: #006699; color: white;">Contacto</th>
                                  <th style="width: 20%;background-color: #006699; color: white;">Empresa</th>
                                  <th style="width: 20%;background-color: #006699; color: white;">Departamento</th>
                                  <th style="width: 2%;background-color: #006699; color: white;">Extension</th>
                                  <th style="width: 5%;background-color: #006699; color: white;">Email</th>
                              </tr>
                          </thead>
                   </table>
              </div>
        </div>
    </div>
</div>

CONTROLLER CONTACTS

ControllerContacts.php

<?php
//  Controlador de la vista principal es decir del Index
defined('BASEPATH') OR exit('No direct script access allowed');

class ControllerContactos extends CI_Controller{

	 function __construct(){
			parent::__construct();
			$this->load->model('ModelContacto');
	 }

	// Carga la vista principal de las Empresa que en este caso es un listado de Empresas
		public function index(){
			$datos['titulo']	= 'Directorio Telefonico';
    			$datos['header']	= 'template/header';
			$datos['menu'] 		= 'template/menu';
			$datos['formulario'] 	= 'contactos/index'; // Listado de Empresas
			$datos['footer'] 	= 'template/footer';
			$datos['menu2'] 	= 'template/menu2';
			$datos['piedepagina'] 	= 'template/pieDePagina';
			$datos['modulo']  	= 'Contactos';
			$datos['accion']	= 'Listado de Contactos';
			$this->load->view('template/template',$datos);
	 }

	 // procesando server side processing
	 public function posts(){
		$columns = array(
			 0 =>'nombre',
			 1 =>'empresa',
			 2=> 'departamento',
			 3=> 'extension',
			 4=> 'email',
		 );
	
 		$limit		= $this->input->post('length');
		$start		= $this->input->post('start');
		$order 		= $columns[$this->input->post('order')[0]['column']];
		$dir   		= $this->input->post('order')[0]['dir'];
		$totalData 	= $this->ModelContacto->allposts_count();
                $totalFiltered 	= $totalData;

		 if(empty($this->input->post('search')['value'])) {
 			$posts = $this->ModelContacto->allposts($limit,$start,$order,$dir);
		 }else {
	 		$search = $this->input->post('search')['value'];
			$posts =  $this->ModelContacto->posts_search($limit,$start,$search,$order,$dir);
			$totalFiltered = $this->ModelContacto->posts_search_count($search);
		 }

		 $data = array();
		 if(!empty($posts)){
			 foreach ($posts as $post){
				 $nestedData['id'] 			 			= 	$post->id;
				 $nestedData['nombre'] 				=		$post->nombre;
				 $nestedData['empresa']  			= 	$post->empresa;
				 $nestedData['departamento']	=		$post->departamento;
				 $nestedData['cargo']					=		$post->cargo;
				 $nestedData['extension']			=	  $post->extension;
 			 	 $nestedData['email']					=		$post->email;
				 $nestedData['estado']				=		$post->estado;
				 $nestedData['idemp']					=		$post->idemp;
				 
				 $data[] = $nestedData;

			 }
		 }

		 $json_data = array(
					 "draw"            => intval($this->input->post('draw')),
					 "recordsTotal"    => intval($totalData),
					 "recordsFiltered" => intval($totalFiltered),
					 "data"            => $data
			      );

		 echo json_encode($json_data);
	}
}
?>

MODEL CONTACT

ModelContact.php

<?php

class ModelContacto extends CI_Model{



    // ##################### metodos server side processing ####################

    // se omiten los usuarios que no estan activos
    public function getAll(){ //getEmpresas
        $this->db->select('c.id,c.nombre as cnombre, e.nombre as enombre,e.dim, c.departamento, c.cargo, c.extension, c.celular, c.email,c.estado,e.id as idemp');
        $this->db->from('contactos c, empresas e');
        $this->db->where('c.estado = 1');
        $this->db->where('c.empresa = e.id');

        $r = $this->db->get();

        return $r->result();
    }



    function allposts_count(){
        $query = $this->db
                          ->where("estado = 1")
                          ->get("contactos");

        return $query->num_rows();
    }

    function allposts_count(){
        $query = $this->db
                          ->where("estatus = 1")
                          ->get("contactos");

        return $query->num_rows();
    }

    function allposts($limit,$start,$col,$dir){
          $where1 = "(c.estado =1 and c.estatus = 1)";

          $this->db->select('c.id,c.nombre as nombre, empresas.nombre as empresa, c.departamento, c.cargo, c.extension, c.email,c.estado,c.empresa as idemp');
          $this->db->from('contactos c');
          $this->db->join('empresas', 'c.empresa = empresas.id', 'Inner');
          $this->db->where($where1);
          $this->db->limit($limit,$start);
          $this->db->order_by($col,$dir);

          $r = $this->db->get();

          if($r->num_rows()>0){
              return $r->result();
          }else{
              return null;
          }
    }


    function posts_search($limit,$start,$search,$col,$dir){
        $where1 = "(c.estado =1 and c.estatus = 1)";
        $where2 = "(  c.nombre 		 like '%".$search."%'";
        $where2.= "or c.cargo 		 like '%".$search."%'";
        $where2.= "or c.extension        like '%".$search."%'";
        $where2.= "or c.email 		 like '%".$search."%'";
        $where2.= "or empresas.nombre 	 like '%".$search."%')";

        $this->db->select('c.id,c.nombre as nombre, empresas.nombre as empresa, c.departamento, c.cargo, c.extension, c.email,c.estado,c.empresa as idemp');
        $this->db->from('contactos c');
        $this->db->join('empresas', 'c.empresa = empresas.id', 'Inner');
        $this->db->where($where1);
        $this->db->where($where2);
        $this->db->limit($limit,$start);
        $this->db->order_by($col,$dir);

        $r = $this->db->get();

        if($r->num_rows()>0)
        {
            return $r->result();
        }
        else
        {
            return null;
        }
    }


    function posts_search_count($search){
        $where1 = "(c.estado =1 and c.estatus = 1)";
        $where2 = "(  c.nombre 		  like '%".$search."%'";
        $where2.= "or c.cargo 		  like '%".$search."%'";
        $where2.= "or c.extension         like '%".$search."%'";
        $where2.= "or c.email 		  like '%".$search."%'";
        $where2.= "or empresas.nombre 	  like '%".$search."%')";

        $this->db->select('c.id,c.nombre as nombre, empresas.nombre as empresa, c.departamento, c.cargo, c.extension, c.email,c.estado,empresas.id as idemp');
        $this->db->from('contactos c');
        $this->db->join('empresas', 'c.empresa = empresas.id', 'Inner');
        $this->db->where($where1);
        $this->db->where($where2);

        $r = $this->db->get();

        if($r->num_rows()>0){
              return $r->num_rows();
        }else{
              return 0;
        }
    }
    // fin de metodos server side processing
}

 ?>

** NOTE I'M USING CODEIGNITER AND BOOSTRAB ADMIN TEMPLATE, MODEL METHODS **

Now showing all this I tell you that the system works perfectly on a local host, that is when I develop the system on my PC.

and this is the base_url configuration on my local machine $ config ['base_url'] = ' link

This is the configuration of my .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) directorio/$1$2 [R=301,NE,L]

# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ directorio/index.php/$1 [L]
</IfModule>

ERROR IMAGES

I hope I have been as specific as possible, I would appreciate any help, everything points to the wrong configuration of the base_url, but I am not 100% sure ..

For English speakers, I would also appreciate your help. I do not have problems speaking in English.

    
asked by Domingo Gonzalez 02.03.2018 в 16:04
source

1 answer

0

for those who have this problem, I commented that it was due to the configuration of the .htacces and the configuration of the virtualhost

.htaccess file

<IfModule mod_rewrite.c>
        RewriteEngine On
       
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [QSA,L]
       
</IfModule>

Virtual Host

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName directorio
    ServerAlias directorio
    DocumentRoot /srv/www/htdocs/directorio

    # if not specified, the global error log is used
    ErrorLog /var/log/apache2/directorio-error_log
    CustomLog /var/log/apache2/directorio-access_log combined

    <Directory "/srv/www/htdocs/directorio">
	 Options Indexes FollowSymLinks MultiViews
         AllowOverride All
         Require all granted
         #Allow from all ->> he aqui un problema
    </Directory>
</VirtualHost>
    
answered by 19.03.2018 в 18:58