Welcome Guest, Not a member yet? Register   Sign In
Object : Class not found
#11

[eluser]TDSPower[/eluser]
And last, mode Mvisiteur
Code:
<?php

    class Mvisiteur extends Model {
        
        function Mvisiteur(){
            parent::Model();
        }
        
        /**
         * Renvoie un tableau des différents visibilité du profil autorisées
         *
         */
        function getVisibiliteProfil(){
            $query = $this->db->query('SELECT * FROM visibiliteprofil ORDER BY intitule_visPro');
            
            $output = array('0' => '-------------');
            
            foreach ($query->result() as $row)
            {
                $output[$row->id_visPro] = $row->intitule_visPro;
            }
            return $output;
        }
        
        /**
         * Verification que le membre n'est pas déjà inscrit (Mail ou Login présent)
         *
         */
        function verificationExistanceMembre(){
            $query = $this->db->query('SELECT id_mem FROM membre WHERE
                                                                         login_mem LIKE ?
                                                                         OR email_mem LIKE ?',
                                       array($this->validation->username,
                                                $this->validation->email));
            if($query->num_rows() == 0){
                return TRUE;
            }
            else{
                return FALSE;
            }
        }
        
        
        /**
         * Insertion d'un membre
         *
         */
        function insertUtilisateur(){
            $sql = "INSERT INTO membre (login_mem,email_mem,mdp_mem,visibilite_mem)
                        VALUES (
                            ".$this->db->escape($this->validation->username).",
                            ".$this->db->escape($this->validation->email).",
                            ".$this->db->escape(md5($this->validation->password)).",
                            ".$this->db->escape($this->validation->visibilite)."
                        )";
            $this->db->query($sql);
        }
        
        /**
         * Verification que le couple login/mot de passe est valide
         *
         */
        function verificationConnection(){
            $query = $this->db->query('SELECT id_mem FROM membre WHERE login_mem LIKE ?
                                        AND mdp_mem LIKE ?',
                                        array($this->validation->username, $this->validation->password));
            if($query->num_rows() == 1){
                return TRUE;
            }
            else{
                return FALSE;
            }
        }
            
    }
?>

Thanks again,

François
#12

[eluser]xwero[/eluser]
What i find strange is that Visiteur and Membre both are controllers this means you are using them in an url like site.com/visiteur and once they logged on the url will change to site.com/membre if i get it right?

The second thing i find strange is why you want to add an object to a session. If you want to check if someone logged in you can add one variable, an id for example, if the session expires you won't have the id in the session and that is how you know the user isn't logged in.
#13

[eluser]TDSPower[/eluser]
Yes for the url, I think it is not very "strange", or disturbing.

For the second question, the answer is simple ! I have to use objects in my project because it is for school and teachers don't let me the choice ! Of course, it's easier to put a simple variable in the session...

Maybe, it would be easier, when the visitor is login to redirect him to membre/createSession, and create the object in this function ?

Thanks !
#14

[eluser]wiredesignz[/eluser]
Using a Controller extension looks perfectly ok, However you cannot instantiate a Controller inside another, ie: new Membre() will not work.


You may like to redirect() the application to the Membre Controller instead.

Each url may only have one Controller in CI. (which may be an extension of another of course)
#15

[eluser]TDSPower[/eluser]
Thanks too Wiredesignz,

The right solution would be :

1- I verify login & password in the visitor class
2- If it is ok, I redirect to Membre/CreateSession which will be able to create an object of himself (Membre).

And how should I do for example if I have two classes : Playlist and Music.
Music contains some arguments as title, artist...
A playlist is a table of Music.

Normally (in java for exemple) I would create a Playlist object and put in Playlist->Table[1] for exemple an Object Music.
How can I do in CI if I can't create an object of an external classe ?

Sorry for my noob question !

The project is a "Deezer Like", I will give my source when he will be finished, if it can be useful, why not !

Thanks.
#16

[eluser]m4rw3r[/eluser]
There is no problem with creating objects of external classes, that is only a limitation to classes extending Controller (only one controller is allowed to be instantiated per request).

The difference to Java is that CI is stateless, so you have to serialize the object and/or save the data in session or another type of cache.
#17

[eluser]xwero[/eluser]
If i get it right you want urls like site.com/visiteur/ecouteur_extrait and site.com/membre/ecouteur_extrait that is why you extend the classes right? It's not a common way to use controllers that's why i find it strange.

The problem is the parent class is not aware of his child. The inheritance goes down not up so if you want to add an object to the session it's best you do it in the child class.
I think adding the Membre class as a session variable isn't a good idea because there will be more data added than you will ever need or want. You could create a new object to add to the session data
Code:
$curmembre = new stdClass();
$curmembre->id_membre = $this->id_membre;
// ...
$this->session->userdata('membre',$crumembre);
#18

[eluser]wiredesignz[/eluser]
Yes, m4rw3r is absolutely correct, you may instantiate any class except a new Controller class.

xwero is forgetting that you may call a parent::method() or even $this->method() from a child class, so having the session in the parent class is totally acceptable.
#19

[eluser]TDSPower[/eluser]
I start to understand this logic !

And this class which canno't be instanciated is a library ? I'am right ? If not, where do I put it ?

Thanks !




Theme © iAndrew 2016 - Forum software by © MyBB