• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getting started

I just got started with CI today and I have to say I quite like it. (started with Cake, but it didn't quite work for me). I find that above all, it's SIMPLE. My experience has been the simpler something is, the more versatile. (applies to frameworks more than apps)

anyway, I'm also quite new to php and so I might have questions that are php and not CI related.

anyhow, here I go.

I'm trying to do a few things (at once of courseSmile I want to build a simple app to get to know the interaction of database php and CI. So I'm building a simple time management app. Really simple, but maybe not the simplest possible.

I've created some tables in MySql, but I don't know how to create the 1 to Many relations in PHP. I'm guessing I don't really need to anyway as my entries table creates a many to many relationship.

but I have 4 tables

So the Client can have multiple Projects, which Can have multiple Task
(at the moment I don't care for one task to be in two Projects but that would be nice too)

I could just populate all the stuff right in the entries, but I'm trying to learn here...

so instead of having the client, project and task name, I want to use their ids in the database, and show the names associated.

so to some of my code
$data['clients'] = $this->db->get('clients')->result_array();

<? echo form_dropdown('Client', $clients[0]);?>

each array is a row from the table, so obviously $clients[0] doesn't work.

is there a way to grab the columns?

in fact, I'm sure there is a better way of doing this, as I want to use the ID as the data passed and the name shown in the drop down. or is that not the way to go?

scorche, Welcome to Code Igniter. Please have a look CI user guide database section.

Moreover, try to use model as much as possible.

By the way, display data in view for resutl_array() is
<?php if ($clients)
  foreach($clients as $row):
   echo $row['client_info'];

[eluser]Colin Williams[/eluser]
Basically, when one object is requested, all referenced objects should be attached to the returned object in some fashion. Usually this means using JOINs in your query, then iterating through the result to put together the object in a usable fashion. This is what your model does: query the database then construct the object (or objects) based on the result.

This worked
$clients = $this->db->get('clients')->result_array();

        foreach ($clients as $cRow){
            $data['clientNames'][$cRow['ClientID']] = ($cRow['ClientName']);


@Sumon, That's (db in userguide) what I've been looking at for that last 2 hours
I will need to look into the model part of it

@Colin Williams, I guess I had this romantic Idea that I just plug and play with the database

[eluser]Colin Williams[/eluser]
Ha! That romance you are seeking is what some people call ORM. An ORM (object-relational mapping) library uses database table naming conventions and configuration to automatically structure objects and their relatives (typically at the expense of extraneous database queries). Search these boards for "DataMapper" or "IgnitedRecord," a few decent written-for-CI ORM libraries.

ORM is typically something you will do in all your applications; you just need to decide whether to buy into the conventions of an ORM library or roll it your own way.

well, I don't know what ORM is, but I'm looking forward to a romantic evening

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.