Welcome Guest, Not a member yet? Register   Sign In
I can't solve my bug (2 days on) pleade help
#1

I have this controller, all work fine.
But the problem is in the public function add_equipe_do()

in this line
if ($this->form_validation->run() == FALSE)
            {
                $this->load->view('admin_header');
                $data['error_upload']='';
                $this->load->view('equipe_add_display',$data);
                $this->load->view('admin_footer');
                exit;
            }

When there is a error in the form, nothing is displayed without php or codeigniter error.
In the reste of code the tree view is displayed correctly, but not here.

Complete controller :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Admin extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
        //$this->load->helper('form'); put in autoload
        $this->load->model('types');
        $this->load->model('projets');
        $this->load->model('equipe');
        $this->load->library('form_validation');
        $this->load->library('session');
        
        
    }
    
    public function index()
    {
        if ($this->session->aut != 1)
        {
             $this->load->view('auth_form');
        }
        else
        {
            $this->load->view('admin_header');
            $this->load->view('admin_footer');
        }
    }
    public function login_do()
    {
        $login=$this->input->post('login');
        $password=$this->input->post('password');
        if ($login=="zobert73" && $password=="archis")
        {
            $this->session->aut=1;
            $this->load->view('admin_header');
            $this->load->view('admin_footer');
        }
        else
        {
            $this->load->view('auth_form');
        }
            
            
        
    }
    public function types()
    {
        if ($this->session->aut != 1) exit;
        $this->load->view('admin_header');
        $data['types']=$this->types->get_all_types();
        $this->load->view('types_display',$data);
        $this->load->view('admin_footer');
    }
    public function add_types()
    {
                if ($this->session->aut != 1) exit;

        $this->load->view('admin_header');
        $nom=$this->input->post('newtypes');
        $this->types->add_types($nom);
        $data['types']=$this->types->get_all_types();
        $this->load->view('types_display',$data);
        $this->load->view('admin_footer');
    }
    //suppression et modification du carburant
    public function mod_types()
    {
                if ($this->session->aut != 1) exit;

        $this->load->view('admin_header');
        $supprimer=$this->input->post('supprimer');
        if ($supprimer=='supprimer')
        {
            $id=$this->input->post('id');
            $this->types->delete_types($id);
        }
        else
        {
            $id=$this->input->post('id');
            $nom=$this->input->post('modtypes');
            $this->types->mod_types($id,$nom);
        }
        $data['types']=$this->types->get_all_types();
        $this->load->view('types_display',$data);
        $this->load->view('admin_footer');
    }
    
    // gestion des annonces
    public function projets()
    {
                if ($this->session->aut != 1) exit;

        $this->load->view('admin_header');
        $data['projets']=$this->projets->get_all_projets_join();
        $data['error_upload']='';
        $this->load->view('projets_display',$data);
        $this->load->view('admin_footer');
    }
    public function ajoutprojets()
    {
                if ($this->session->aut != 1) exit;

        $this->load->view('admin_header');
        $data['types']=$this->types->get_all_types();
        $data['projets']='';
        $this->load->view('projets_add_display',$data);
        $this->load->view('admin_footer');
    }
    public function add_projets_do()
    {
                if ($this->session->aut != 1) exit;

        $this->form_validation->set_rules('titre', 'Titre', 'required');
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('admin_header');
            $data['types']=$this->carburant->get_all_types();
            $this->load->view('projets_add_display',$data);
            $this->load->view('admin_footer');
        }
        else
        {
            //traitement du formulaire
            $titre=$this->input->post('titre');
            $prix=$this->input->post('prix');
            $ville=$this->input->post('ville');
            $description=$this->input->post('description');
            $mo=$this->input->post('mo');
            $latitude=$this->input->post('latitude');
            $types_id=$this->input->post('types_id');
            $longitude=$this->input->post('longitude');
            $id=$this->projets->add_projets($types_id,$prix,$description,$titre,$mo,$longitude,$latitude, $ville);
            //Ajout des images
            $cpt=sizeof($_FILES['userfile']['name']);
            $file=$_FILES;
            if ($file['userfile']['name'][0]!="")
            {
                for ($i=0;$i<$cpt;$i++)
                {
                                //traitement des images
                                //config multiple upload
                            $_FILES['userfile']['name']=$file['userfile']['name'][$i];
                            $_FILES['userfile']['type']= $file['userfile']['type'][$i];
                            $_FILES['userfile']['tmp_name']= $file['userfile']['tmp_name'][$i];
                            $_FILES['userfile']['error']= $file['userfile']['error'][$i];
                            $_FILES['userfile']['size']= $file['userfile']['size'][$i];
                            //**************************
                            $config['upload_path'] = './assets/images_annonce';
                            $config['allowed_types'] = 'gif|jpg|png|jpeg';
                            $this->load->library('upload', $config);
                            if (!$this->upload->do_upload())
                            {
                                $data['error_upload']=$this->upload->display_errors('<div class="error">', '</div>');
                                $data['projets']=$this->projets->get_projets_by_id($id);
                                $data['photo']=$this->projets->get_photo_by_id($id);
                                $data['types']=$this->types->get_all_types();
                                $this->load->view('admin_header');
                                $data['error_upload']='';
                                $this->load->view('projets_modif_display',$data);
                                $this->load->view('admin_footer');
                            }
                            else
                            {
                                //mise a l'echelle
                                //image resize and rename
                                $nomoriginale=$this->upload->data('file_name');
                                $this->load->library('image_lib');
                                $config['image_library'] = 'gd2';
                                $config['source_image'] = "./assets/images_annonce/$nomoriginale";
                                $config['create_thumb'] = FALSE;
                                $config['maintain_ratio'] = TRUE;
                                $config['master_dim']='height';
                                $config['width'] = "300";
                                $config['height']= "200";
                                $config['new_image'] = "./assets/images_annonce/thumb/$nomoriginale";
                                $this->image_lib->initialize($config);
                                $this->image_lib->resize();
                                $config['height'] = "600";
                                $config['width'] = "800";
                                $config['new_image'] = "./assets/images_annonce/grande/$nomoriginale";
                                $this->image_lib->initialize($config);
                                $this->image_lib->resize();
                                unlink("./assets/images_annonce/$nomoriginale");
                                //ecriture dans la base de données
                                $defaut=($i==0)?'oui':'non';
                                $this->projets->add_photo($id,$defaut,$nomoriginale);
                            }
                    
                }
            }
            $this->load->view('admin_header');
            $data['projets']=$this->projets->get_all_projets_join();
            $data['error_upload']='';
            $this->load->view('projets_display',$data);
            $this->load->view('admin_footer');
        }
    }
    
        
        public function delete_projets()
        {
                    if ($this->session->aut != 1) exit;

            $id= $this->uri->segment(3);
            $this->projets->delete_projets($id);
            $this->load->view('admin_header');
            $data['projets']=$this->projets->get_all_projets_join();
            $data['error_upload']='';
            $this->load->view('projets_display',$data);
            $this->load->view('admin_footer');
        }
        public function modif_projets()
        {
                    if ($this->session->aut != 1) exit;

            $id= $this->uri->segment(3);
            $data['id']=$id;
            $data['projets']=$this->projets->get_projets_by_id($id);
            $data['photo']=$this->projets->get_photo_by_id($id);
            $data['types']=$this->types->get_all_types();
            $this->load->view('admin_header');
            $data['error_upload']='';
            $this->load->view('projets_modif_display',$data);
            $this->load->view('admin_footer');
        }
        public function mod_annonce_do()
        {
                    if ($this->session->aut != 1) exit;

            $this->form_validation->set_rules('titre','Titre', 'required');
            
            if ($this->form_validation->run() == FALSE)
            {
                $data['id']=$this->input->post('id');
                $id=$data['id'];
                $data['projets']=$this->projets->get_projets_by_id($id);
                $data['photo']=$this->projets->get_photo_by_id($id);
                $data['types']=$this->types->get_all_types();
                $this->load->view('admin_header');
                $data['error_upload']='';
                $this->load->view('projets_modif_display',$data);
                $this->load->view('admin_footer');
            }
            else
            {
                //traitement du formulaire
                $id=$this->input->post('id');
                $types_id=$this->input->post('types_id');
                $titre=$this->input->post('titre');
                $prix=$this->input->post('prix');
                $ville=$this->input->post('ville');
                $description=$this->input->post('description');
                $mo=$this->input->post('mo');
                $latitude=$this->input->post('latitude');
                $longitude=$this->input->post('longitude');
                //var_dump($id,$types_id,$prix,$description,$titre,$mo,$longitude,$latitude,$ville);
                $this->projets->mod_projets($id,$types_id,$prix,$description,$titre,$mo,$longitude,$latitude,$ville);
                //Ajout des images
                $cpt=sizeof($_FILES['userfile']['name']);
                $file=$_FILES;
                if ($file['userfile']['name'][0]!="")
                {
                    for ($i=0;$i<$cpt;$i++)
                    {
                                    //traitement des images
                                    //config multiple upload
                                $_FILES['userfile']['name']=$file['userfile']['name'][$i];
                                $_FILES['userfile']['type']= $file['userfile']['type'][$i];
                                $_FILES['userfile']['tmp_name']= $file['userfile']['tmp_name'][$i];
                                $_FILES['userfile']['error']= $file['userfile']['error'][$i];
                                $_FILES['userfile']['size']= $file['userfile']['size'][$i];
                                //**************************
                                $config['upload_path'] = './assets/images_annonce';
                                $config['allowed_types'] = 'gif|jpg|png|jpeg';
                                $this->load->library('upload', $config);
                                if (!$this->upload->do_upload())
                                {
                                    $data['error_upload']=$this->upload->display_errors('<div class="error">', '</div>');
                                    $data['id']=$this->input->post('id');
                                    $data['annonce']=$this->annonce->get_annonce_by_id($id);
                                    $data['photo']=$this->annonce->get_photo_by_id($id);
                                    $data['marque']=$this->marque->get_all_marque();
                                    $data['carburant']=$this->carburant->get_all_carburant();
                                    $this->load->view('admin_header');
                                    $this->load->view('annonce_modif_display',$data);
                                    $this->load->view('admin_footer');
                                }
                                else
                                {
                                    //mise a l'echelle
                                    //image resize and rename
                                    $nomoriginale=$this->upload->data('file_name');
                                    $this->load->library('image_lib');
                                    $config['image_library'] = 'gd2';
                                    $config['source_image'] = "./assets/images_annonce/$nomoriginale";
                                    $config['create_thumb'] = FALSE;
                                    $config['maintain_ratio'] = TRUE;
                                    $config['master_dim']='height';
                                    $config['width'] = "300";
                                    $config['height']= "200";
                                    $config['new_image'] = "./assets/images_annonce/thumb/$nomoriginale";
                                    $this->image_lib->initialize($config);
                                    $this->image_lib->resize();
                                    $config['height'] = "600";
                                    $config['width'] = "800";
                                    $config['new_image'] = "./assets/images_annonce/grande/$nomoriginale";
                                    $this->image_lib->initialize($config);
                                    $this->image_lib->resize();
                                    unlink("./assets/images_annonce/$nomoriginale");
                                    //ecriture dans la base de données
                                    $defaut=($i==0)?'oui':'non';
                                    echo
                                    $this->annonce->add_photo($id,'non',$nomoriginale);
                                }
                        
                    }
                }
                //suppression photo et changement defaut
                $photo=$this->projets->get_photo_by_id($id);
                if (sizeof($photo) >0)
                {
                    for ($i=0; $i< sizeof($photo); $i++)
                    {
                        $tab=$photo[$i];
                        $delete=$this->input->post("delete".$tab['id']);
                        if ($delete=="oui")
                        {
                            $tab=$photo[$i];
                            $nom_image=$tab['nom_image'];
                            unlink("./assets/images_annonce/grande/$nom_image");
                            unlink("./assets/images_annonce/thumb/$nom_image");
                            $this->projets->delete_photo($tab['id']);
                        }
                        
                    }
                }
                $photo=$this->projets->get_photo_by_id($id);
                if (sizeof($photo) >0)
                {
                        $defaut=$this->input->post("defaut");
                        $this->projets->change_defaut($id,$defaut);
                }
                //************************************
                $this->load->view('admin_header');
                $data['projets']=$this->projets->get_all_projets_join();
                $data['error_upload']='';
                $this->load->view('projets_display',$data);
                $this->load->view('admin_footer');
            }
        }
        
        public function equipe()
        {
            if ($this->session->aut != 1) exit;
            $this->load->view('admin_header');
            $data['equipe']=$this->equipe->get_all_equipe();
            $this->load->view('equipe_display',$data);
            $this->load->view('admin_footer');
        }
        public function add_equipe()
        {
            if ($this->session->aut != 1) exit;
            $this->load->view('admin_header');
            $data['equipe']=$this->equipe->get_all_equipe();
            $this->load->view('equipe_add_display');
            $this->load->view('admin_footer');
        }
        public function add_equipe_do()
        {
        if ($this->session->aut != 1) exit;
        //traitement formulaire
        $data['nom']=$this->input->post('nom');
        $data['prenom']=$this->input->post('prenom');
        $data['fonction']=$this->input->post('fonction');
        $data['diplome']=$this->input->post('diplome');
        $data['description']=$this->input->post('description');
        $data['email']=$this->input->post('email');
        //$data['photo']=$this->input->post('userfile');
        
        //var_dump($data);
        $this->form_validation->set_rules('nom','Nom', 'required');
        $this->form_validation->set_rules('prenom','Prénom', 'required');
        $this->form_validation->set_rules('userfile','Photo','file_required||file_allowed_type[image]', array('file_required' => 'Image Obligatoire','file_allowed_type[image]'=>'Une image est nécessaire'));
        $this->form_validation->set_rules('email', 'Email', 'trim|valid_email');
        
        if ($this->form_validation->run() == FALSE)
            {
                $this->load->view('admin_header');
                $data['error_upload']='';
                $this->load->view('equipe_add_display',$data);
                $this->load->view('admin_footer');
                exit;
            }

        $config['upload_path'] = './assets/images_equipe';
        $config['allowed_types'] = 'gif|jpg|png';
        $this->load->library('upload', $config);
        $this->upload->do_upload();
        $nomoriginale=$this->upload->data('file_name');
        $data['error_upload']=$this->upload->display_errors('<div class="error">', '</div>');
        if ($data['error_upload']=="")
        {
            //Enregistrement des données
            $this->equipe->add_equipe($data['nom'],$data['prenom'],$data['fonction'],$data['diplome'],$data['description'],$nomoriginale,$data['email']);
            //image resize and rename
            $nom_image=$nomoriginale;
            $this->load->library('image_lib');
            $config['image_library'] = 'gd2';
            $config['source_image'] = "./assets/images_equipe/$nomoriginale";
            $info= getimagesize("./assets/images_equipe/$nomoriginale");
            $config['master_dim']=($info[0]>$info[1])?'height':'width';
            $config['create_thumb'] = FALSE;
            $config['maintain_ratio'] = TRUE;
            $config['height'] = "250";
            $config['width'] = "250";
            var_dump($config);
            $config['new_image'] = "./assets/images_equipe/$nomoriginale";
            //echo $config['new_image'];
            $this->image_lib->initialize($config);
            if (!$this->image_lib->resize())
            {
                    echo $this->image_lib->display_errors();

                    exit;
            }
            else
            {
                //image croping center
                $info= getimagesize("./assets/images_equipe/$nomoriginale");
                $width_image=$info[0];
                $margin=($width_image/2)-125;
                
                $config['maintain_ratio'] = FALSE;
                $config['source_image'] = "./assets/images_equipe/$nomoriginale";
                $config['new_image'] = "";
                $config['x_axis']=$margin;
                $config['y_axis']=0;
                $this->image_lib->initialize($config);
                var_dump($config);
                if (!$this->image_lib->crop())
                {
                    echo $this->image_lib->display_errors();

                    exit;
                }
            
            }
        }
        $this->load->view('admin_header');
        $data['equipe']=$this->equipe->get_all_equipe();
        $this->load->view('equipe_display',$data);
        $this->load->view('admin_footer');
    }

    
    public function delete_equipe()
        {
            if ($this->session->aut != 1) exit;

            $id=$this->uri->segment(3);
            $this->equipe->delete_equipe($id);
            $this->load->view('admin_header');
            $data['projets']=$this->projets->get_all_projets_join();
            $data['error_upload']='';
            $data['equipe']=$this->equipe->get_all_equipe();
            $this->load->view('equipe_display',$data);
            $this->load->view('admin_footer');
        }

}
Reply
#2

solved,

I don't know why, but it's not possible to use exit;
subtlety of object programming... 
If some one can give me complete explanation.

So I used an else to include the rest of my function.

if ($this->form_validation->run() == FALSE)
            {
                $this->load->view('admin_header');
                $data['error_upload']='';
                $this->load->view('equipe_add_display',$data);
                $this->load->view('admin_footer');
            }
else
{
.........
}
Reply
#3

(09-14-2016, 09:00 AM)nunenthal Wrote: I have this controller, all work fine.
But the problem is in the public function add_equipe_do()

in this line
if ($this->form_validation->run() == FALSE)
            {
                $this->load->view('admin_header');
                $data['error_upload']='';
                $this->load->view('equipe_add_display',$data);
                $this->load->view('admin_footer');
                exit;
            }

When there is a error in the form, nothing is displayed without php or codeigniter error.
In the reste of code the tree view is displayed correctly, but not here.

Don't use exit. If you want to finalize the controller use return;
Code:
if ($this->form_validation->run() == FALSE)
{
              $this->load->view('admin_header');
              $data['error_upload']='';
              $this->load->view('equipe_add_display',$data);
              $this->load->view('admin_footer');
              //exit;//Remove this line
              return; //Use return
}

Reply
#4

(09-14-2016, 10:39 AM)nunenthal Wrote: solved,

I don't know why, but it's not possible to use exit;
subtlety of object programming... 
If some one can give me complete explanation.

So I used an else to include the rest of my function.

if ($this->form_validation->run() == FALSE)
            {
                $this->load->view('admin_header');
                $data['error_upload']='';
                $this->load->view('equipe_add_display',$data);
                $this->load->view('admin_footer');
            }
else
{
.........
}

The framework hasn't stop just after the loading of views. There is some staff to do after the loading of views so do not terminate. I had noticed that you used a lot of exit in your controller. Just use return or the else that you have made.
[Just a programmer] Cool [/Just a programmer]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB