Money Lending Example Contact


#1

Hello…

Im new here. want to try creating an app using agile
so im trying this new sample Money Lending

im stuck with contact.php

<?php
require'lib.php';
$app = new MyApp();
$app->layout->add('CRUD')->setModel($app->user->ref('Contact'));

when creating this i have an error

when i change

$app->layout->add('CRUD')->setModel($app->user->ref('Contact'));

to

$contact = new Contact($app->db);
$ref = $contact->addCondition('user_id', $_SESSION['user_id']);
$app->layout->add('CRUD')->setModel($ref);

it will not showing the user_id

but if i write it like this

$app->layout->add('CRUD')->setModel(new Contact($app->db))->addCondition('user_id', $_SESSION['user_id']);

the user_id is showing

  1. what is the function of ref? is it the same as addCondition?
  2. why the 2nd code and 3rd code have different result?

#2

Hi, most likely in Model User the reference to Contact is not defined, that’s why version 1 fails.

Ref() traverses to another model, like from User to Contact. User->ref(‘Contact’) returns a Contact Model with, depending on how the reference is defined, some conditions.

Hope this helps you a bit, am on mobile, hard to type code here :slight_smile: