Jump to content


elanouar

Member Since 24 Jan 2013
Offline Last Active Feb 16 2014 09:05 AM
-----

Topics I've Started

.:::Functional in my local server and disfunctional in the distant server

15 February 2014 - 04:30 PM

Hi everyone,
I developed a class in which i have to display a form. Thus I inserted the following lines in my form to unlist records.

try{
		 
            $output =$this->grocery_crud->render();
           } catch(Exception $e)
		   {
            if($e->getCode() == 14)  
           {
	
            redirect(strtolower(__CLASS__).'/'.strtolower(__FUNCTION__).'/add') ; 
            }
              else
               {
               show_error($e->getMessage());
                }
           }


this form is functional 100% in my local machine . Unfortunately when i tried to host it in the web the system  inform me that the page is not found (error 404 ) . I have tried to debug the code and i found that the bugging line is :

    redirect(strtolower(__CLASS__).'/'.strtolower(__FUNCTION__).'/add') ; 

Could you help me to resolve this pb plz !!

 

 

Below the total class :

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class UserAdmin extends CI_Controller {
 
    function __construct()
    {
        parent::__construct();
		session_start();
 
   
        $this->load->database();
        $this->load->helper('url'); 
        $this->load->library('grocery_CRUD');
	
 
    }                       
 
    public function index()
    {}   
 
     public function personne()
    {
		 
		$this->session->set_userdata('sectionName', 'Personne');
	
        $this->grocery_crud->set_table('personne');
		$this->grocery_crud->set_relation('idGroupe','groupe','nomGroupe'); 
		
		$this->grocery_crud->columns('cin',  'prenom', 'nom','numTel','dateNaissance','email','Sexe','idGroupe');
		$this->grocery_crud->fields('cin',  'prenom', 'nom','numTel','dateNaissance','email','Sexe','idGroupe');		
		$this->grocery_crud->required_fields('cin', 'prenom', 'nom','numTel','dateNaissance','Sexe');		 
		  
     	        $this->grocery_crud->display_as('cin','CIN');
		$this->grocery_crud->display_as('prenom','pr&eacute;nom');
		$this->grocery_crud->display_as('Nom','Nom');
		$this->grocery_crud->display_as('numTel','Tel');
		$this->grocery_crud->set_subject('personne');

		
		$this->grocery_crud->display_as('dateNaissance','Date de Naissance');				
	        $this->grocery_crud->set_rules('email', 'Email', 'trim|required|valid_email');
		$this->grocery_crud->display_as('idGroupe','Groupe');			
		 
		$this->grocery_crud->callback_field('numTel',array($this ,'edit_numTel'));
		$this->grocery_crud->callback_after_insert(array($this, 'after_insert')); 
				
	        $this->grocery_crud->set_theme('datatables');
		$this->grocery_crud->unset_back_to_list();
		
	 
	try{
		 
            $output =$this->grocery_crud->render();
           } catch(Exception $e)
		   {
            if($e->getCode() == 14)  
           {
	
            redirect(strtolower(__CLASS__).'/'.strtolower(__FUNCTION__).'/add') ; 
            }
              else
               {
               show_error($e->getMessage());
                }
           }	 
 
              $this->load->view('tbo/index.html',$output);        
    }	

}
 ?>

Redirection PB

18 July 2013 - 05:18 PM

I created a Crud in which i have to send an Email to a group but before sending the email i have to check if the sender has reached the limit number of emails. If the user reached the max number he will be redirected to an information page and if it s not the case the mail will be sent and the user will be redirected to a second page.

Thus as figured below in the code i 'm using the 'callback_before_insert' in which i will try to make my tests and based on the results i will redirect the user to a specific page. Unfortunately the redirect function is dysfunctional.


public function email()
    {    
	 	$this->grocery_crud->set_table('email');					
 
		$this->grocery_crud->columns('source','sujet','contenu','groupe');
		$this->grocery_crud->fields('source','sujet','contenu' ,'groupe');		
		$this->grocery_crud->callback_before_insert(array($this,'checking_and_sending'));		
        $output = $this->grocery_crud->render(); 
        $this->_example_output($output);        
    }	
				 
	
	function checking_and_sending($post_array)
    {  
                .
                .
                .
		if ($h==0)    
		{
			redirect('/Bilelou/index.php/communication/func','location');
		}
			
		else
		{
			
			redirect('/Bilelou/index.php/communication/fun','location');
		}

    
   }


After  verification  I noted that the 'grocery_crud->render()' function overwrite the redirect function and force it to still in the main page.
Is there any solution that could overpass this problem.
Thank you for your help in advance.


.:: fulfillment of a Drop Down list

18 July 2013 - 02:48 AM

To fulfill a specific need i created a CRUD in which i have a dropdown list.
 I have to fulfill the dropdown list with data, and the value of each element would be fixed by my own code.
Thus I created a function in a model in which i have made some joines and return an array . The generated array is composed of 'values' and 'names' of  elements that will figure in the dropdown  list.

Example of a generated array :

12 , ESS,13,Est,110,CAB....

12 ---->will represent the id of ESS
13 ---->will represent the id of EST
110---->will represent the id of CAB

 

My model function :

     public  function groupes() 
   {
	  $datarray =array();
	  $this->db->select('g.idGroupe,g.nomGroupe');
	  $this->db->distinct();
          $this->db->from('groupe g, usertogroupe u');
          $this->db->where('u.idutilisateur', 25);
	  $this->db->join('usertogroupe', 'u.idgroupe=g.idGroupe');   	 
	 
      $query = $this->db->get();
	  
	 	  
	 foreach ($query->result() as $row)
        {
			array_push($datarray ,$row->idGroupe,$row->nomGroupe);
         } 
	 
		 return($datarray); 
}

Knowing that I use the 'field_type' function  and the function that figures in my model  I'm unable to create the dropdown list correctly due to third parameter of the field_type function that  requires an array  as a parameter!!!!
Would you help me to resolve this problem.
Best regards.


callback_before_insert and set_relation_n_n functions

04 July 2013 - 04:13 PM

Hi,
Before saving all information in the db I would like to get all information that figure into the ‘affectation’ field(generated by set_relation_n_n function).

I tried to use the callback_before_insert function but I have not found the right method to extract information from the array that figure into the callback function that would be called.

 I would appreciate it if you could help me!!


.::: Set_relation_n_n with a filter

29 June 2013 - 09:09 PM

I want to do something like this.

I have 3 tables:  utilisateur,groupe,usertogroupe :

CREATE TABLE IF NOT EXISTS `usertogroupe` 
(
  `idgroupe` bigint(8) NOT NULL,
  `idutilisateur` int(11) NOT NULL,
  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `idusertogroupe` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`idusertogroupe`)
) 
CREATE TABLE IF NOT EXISTS `groupe` (
  `nomGroupe` varchar(30) COLLATE utf8_bin NOT NULL,
  `idGroupe` bigint(8) NOT NULL AUTO_INCREMENT,
  `idSection` bigint(20) NOT NULL,
  `idperiode` bigint(20) NOT NULL,
  PRIMARY KEY (`idGroupe`),
  KEY `idGroupe` (`idGroupe`)
)  
CREATE TABLE IF NOT EXISTS `utilisateur` (
  `pseudo` varchar(10) COLLATE utf8_bin NOT NULL,
  `pwd` varchar(30) COLLATE utf8_bin NOT NULL,
  `role` enum('Utilisateur','Administrateur','Support') COLLATE utf8_bin NOT NULL,
  `id_utilisateur` int(11) NOT NULL AUTO_INCREMENT,
  `cinpersonne` varchar(8) COLLATE utf8_bin NOT NULL DEFAULT '00000000',
  `actif` enum('oui','non') COLLATE utf8_bin NOT NULL,
  `email` varchar(30) COLLATE utf8_bin NOT NULL,
  `signature` varchar(30) COLLATE utf8_bin NOT NULL,
  `pwdEmail` varchar(30) COLLATE utf8_bin NOT NULL,
  PRIMARY KEY (`id_utilisateur`)
)  

utilisateur-> groupe is a n:n relationship

I am using set_relation_n_n to establish the relationship between the ‘utilisateur’ table and the groupe table.  I   created a form in which it contains a list. The list contain a list of groups that refers, filtered, by  a ‘utilisateur’;  the ‘utilisateur’ manage one or many groups. I tried to create a set_relation_n_n and filtered by the ‘utilisateur’. Unfortunately I’m unable to generate the needed list.

Would you help us to under pass this pb?

 $this->grocery_crud->set_table('utilisateur');
		 
		$this->grocery_crud->set_relation_n_n('Affectation','usertogroupe', 'groupe', 'idutilisateur', 'idgroupe','nomGroupe',null,array('idgroupe'=>28));// I have to change the idgroupe to idutilisateur		
		$this->grocery_crud->set_table('email');				
		$this->grocery_crud->columns('source','destination','sujet','contenu','Affectation');
		$this->grocery_crud->fields('source','destination','sujet','contenu' ,'Affectation');
			      	
		$this->grocery_crud->set_rules('contenu', 'contenu', 'trim|required|min_length[10]|max_length[280]|xss_clean');		 
		
		$this->grocery_crud->unset_texteditor('contenu','contenu');		

		$this->grocery_crud->unset_edit();

		$this->grocery_crud->callback_after_insert(array($this->grocery_crud, 'after_insert_email'));
 
        $output = $this->grocery_crud->render();
 
        $this->_example_output($output);   

Thanks in advance.