Welcome Guest, Not a member yet? Register   Sign In
i just started using codeigniter...
#1

[eluser]crwtrue[/eluser]
I have been making a new version of my old php program with codeigniter and so far so good but i would like to know couple of things how they are normally done:

First thing is that in my program i make query to database to get one row which is now in codeigniter version readed in to a array. I also need the fields of that table cause i am using that query to fill a form where you can update the information. So now it is like this:

$data[0] = $q-list_fields();
$data[1] = $q->row_array();

does that look a normal solution?

Also in the form i had javascript code to validate the form(i had also code in php for later Wink) and now it is in the view like this

[Javascript tag]
.
Code for the form validation
.
[Javascript tag]
<?php

THE CODE FOR THE FORM

?>
[Javascript tag]
new validateForm(document.forms['example'])
[Javascript tag]


This works but is this also a normal way to make programs with codeigniter?
#2

[eluser]davidbehler[/eluser]
I would not call the indices 0, 1, 2 and so on but rather something more comprehendible. E.g.
Code:
$data['list_of_fields'] = $q->list_fields();
$data['row_of_some_stuff'] = $q->row_array();
as the indices are used as variable names in your views.

You can put javscript code in the view files, no problem.
#3

[eluser]crwtrue[/eluser]
thx for fast reply. In my view i read the array to tmp_array for more easier handling cause i dont care so much for multidimensonal arrays but i dont like to use foreach also Big Grin
#4

[eluser]TheFuzzy0ne[/eluser]
What's not to like about multi-dimensional arrays and foreach loops? They are perhaps two of the most useful features of PHP. I'd highly suggest you learn to like them, as they can make your life much easier, especially when dealing with multiple results where the number of results can vary. Imagine how a mechanic would get on with his work if he didn't like engines...
#5

[eluser]crwtrue[/eluser]
well foreach(i prefer for,while) is needed when you have array which indexes are not numbers(which i dont like) but if you would have the need for big multiarray like that why just not use database for storage? And i am not saying that i am right i just dont like working with those things but now that i am learning codeigniter i could as well learn some new practices.

The old version of the program that i am doing now with codeigniter didnt have any arrays but there aint that many queries so if it would be a bigger program using arrays to store data would make it faster.




Theme © iAndrew 2016 - Forum software by © MyBB