Welcome Guest, Not a member yet? Register   Sign In
[Error] Undefined property: Accueil::$db
#1

[eluser]Unknown[/eluser]
Hello !

I am trying to reproduce the basic CI Tutorial where you produce a blog and change it a little bit so that it maches the project I am working on. Unfortunately I keep getting the same error :


Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Accueil::$db

Filename: controllers/accueil.php

Line Number: 15

My controller goes like this :

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Accueil extends CI_Controller {
function __construct() {
  parent::__construct();
  $this->load->library('doctrine');
  $this->load->helper('html');
  $this->load->helper('url');
  
}

public function index()
{
  $em = $this->doctrine->em;
  $data['query'] = $this->db->get('lien');
}
}

My Controller_view goes like this :

Code:
<div id='box_lien'>
&lt;?php foreach($query->result() as $row):?&gt;
<h3>&lt;?=$row->titre?&gt;</h3>
<p>&lt;?=$row->description?&gt;</p>
<hr>

&lt;?php endforeach; ?&gt;

I hope you can help me understand why CI will not let me use the db->get function like I would want to. After googling this error, it seems to be related to Doctrine.
Things I have tried :

-Reinstalling Doctrine ORM as a plugin.
-Reinstalling Doctrine ORM as a helper.
-Adding doctrine to config/autoload.php as (librarie/plugin/helper etc...)
-Adding database to config/autoad as a librarie.
-Following these setup instructions :
http://www.phpandstuff.com/articles/code...-and-setup
http://www.joelverhagen.com/blog/2011/05...right-way/
-
And that is pretty much it !
I really hope you guys can help me out !
#2

[eluser]Aken[/eluser]
You're using a standard CodeIgniter Active Record way of accessing the database on this line:
Code:
$data['query'] = $this->db->get('lien');

The error is because you haven't loaded the database through CI. But it seems like you should be using Doctrine methods to retrieve info, not CI's active record...
#3

[eluser]Unknown[/eluser]
Hi !
Thank you for such a quick awnser.
You are right, I didn't realize I was trying to use a Active Record way. I will use Doctrine methods such as :

Code:
&lt;?php
// $em instanceof EntityManager
$user = $em->getRepository('MyProject\Domain\User')->find($id);

I found most ways here :
http://docs.doctrine-project.org/project...rimary-key

Have a great day,
Aryahell




Theme © iAndrew 2016 - Forum software by © MyBB