Welcome Guest, Not a member yet? Register   Sign In
Singleton Patern & Session problem
#1

[eluser]Neric[/eluser]
Hello,

I'm french dev, and I want to make a little site for me with Doctrine & CodeIgniter.
I got problem with your Singleton Pattern : Current_User

PasteBin : Singleton Current User

I want to create an article in my ArticleController (but I can't retrive the Username (or any attribut) of the user connected) :

Code:
$article = new Articles();
$article->title = $this->input->post('title');

$article->authorname = Current_User::user()->Username;

Quote:// ERROR :
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Articles::$session
Filename: models/Current_User.php
Line Number: 23
Fatal error: Call to a member function userdata() on a non-object in C:\wamp\www\nericV2\system\application\models\Current_User.php on line 23


I don't understand ?!
In any views, when I write : echo " Username: " . Current_User::user()->Username; I've no problem ...

I supposed there is a particularity with controller ?!

Thank a lot
Ps1 : $autoload['libraries'] = array('database','session'); autoload.php
Ps2 : sorry for my poor English ^^

Neric
#2

[eluser]Neric[/eluser]
up ?
#3

[eluser]danmontgomery[/eluser]
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined property: Articles::$session
Filename: models/Current_User.php
Line Number: 23
Fatal error: Call to a member function userdata() on a non-object in C:\wamp\www\nericV2\system\application\models\Current_User.php on line 23

This would be a good place to start...
#4

[eluser]Neric[/eluser]
In fact,

I've 2 functions in my controller :
- show form
- submit the form (insert in DB)
Code:
function create()
    {
         // [ ... ]
         echo "<pre>";
         $user = Current_User::user();
         echo $user->nom;  // OK no error
         echo "</pre>";
         // [ ... ] call view ($this->load->view...)
    }

    function createSubmit()
    {
         // [ ... ]
         echo "<pre>";
         $user = Current_User::user();
         echo $user->nom;  // ERROR
         echo "</pre>";
         // [ ... ] insert in database
    }

But I don't understand why ?! An idea ?
Thx




Theme © iAndrew 2016 - Forum software by © MyBB