the more I read the more confused I become.
Permalink 1 user found helpfulthen others are just doing the sql right in the controllers.
Also in forms - there are traditional coded forms i.e. <input type="textbox"> and then form/helpers versions and then some are mixed.
I realize that coders do what they are comfortable doing but as someone trying to learn this format ( and PHP ) at the same time it is very confusing. ( I have extensive experience in coldfusion - only helps a little.).
I find the documentation is good but lacks in examples. Just like when I used to try to find books on
coldfusion programming they were either way to simple ( Hello World) or aimed at advanced users.
Anyway, my goal is to master this - but I can't seem to get information fast enough - I have posted questions in the forum and got some great help. Other times - I have tried to search for answers and only found my own unanswered posts.
Is there a book or site suggestions to really learn the programming end ( code ) ?
I have tried to analyze approaches by downloading free blocks - packages etc. found JordanLev's are great but just a little too advanced to really follow. Need Intermediate tutorials - not beginners or advanced.
The cheat sheet link - I already have bookmarked. If you go through it though, most of the code is related to Concretes admin ( users ) and page lists, file attributes etc. The reason I have chosen Concrete is for the built in permissions / admin and file handling. Important stuff. I think others think the same as it seems to be pretty well covered on lots of sites.
So far everything I have had to do with that I have been lucky enough to find information.
The stuff I think is hard to find, is the information on Database driven Crud applications. using the MVC approach. There is code every where but not laid out like
- Here is the model
- here is how it's connects to the controller
-and here it is in the dashboard single ( form )
- read,update and delete.
Some are using active record and letting Concrete handle the lifting and others are doing themselves - some are writing re-useable functions or classes (jordanlev) others are not- that's where the confusion starts. It doesn't help when there are really old forum posts referring to stuff that is no longer in Concrete.
I have posted several times questions about the form/helper especially the select - Can't find one sample of an array from a database going into a form helper - select dropdown. And how to use the select when putting the application into edit - still confused. May have to go back to how I used to do it.
When using select boxes in forms in Edit mode in the past - I have used the traditional select and tested for data and inserted the first option from the db- if it is in the database the first option is put in ( at the top of the list ) and then under it set a loop for all options below it in case the enduser wants to change it. I haven't a clue how to do this with the form/helper.
$form = Loader::helper('form'); echo $form->select('pCategory', $categorySelection, $selectedKeyValue);
In this example 'pCategory' is the name of the field that will get posted on submit.
$categorySelection is an array with key/value pairs where the KEY is the value that gets submitted and the Value is the displayed text on the screen. This would typically be fed forward from your controller and in your controller you would run a command in a model to get your database data and manipulate it to match the format for the array. Typically this means doing something like this:
Loader::model('MyPackageProductCategories', 'my_package'); $categories = MyPackageProductCategories::getActiveCategories(); $categorySelection = [0 => '']; //pre-populate with a blank option foreach($categories AS $c){ $categorySelection[$c['prodcat_id']] = $c['prodcat_name']; } $this->set('categorySelection', $categorySelection);
$selectedKeyValue is the key value which you want to be selected on page load. So in my case on new records I set this to be 0, for my blank option, otherwise i'll set this to the id of whatever the value currently is. Simple logic over in the controller.
--------------------
All that said there is nothing to prevent someone from spinning up a database query directly in a controller, it's just bad practice.
$categories = MyPackageProductCategories::getActiveCategories();
MyPackageProductCategories is your model? what is the second part?
Thanks so much.
array( 0 => '', 1 => 'Fish', 2 => 'Pork', 5 => 'Fruit', 25 => 'Dairy' );
What does the model function look like? Something like this?
static function getActiveCategories() {
$sql = "SELECT prodcatID,product_name FROM {$this->table} ORDER BY prodcatID";
return $this->db->GetArray($sql);
}
If you could post that function I think that I can finally understand pretty much all of it?
Thanks in advance
For the model function, I've not used the getArray function in c5 though I imagine it's probably close. Basically, in your array you need to have both the id (or whatever you want the key value of your select box to be) as well as the display text (in my code above i had a typo, i was using product_name, should have been prodcat_name).
The model class (or the important part anyway):
class MyPackageProductCategories extends Object public static function getActiveCategories($onlyTop = false) { $query = 'SELECT prodcat_id, prodcat_name FROM ProductCategories ORDER BY prodcat_sort'; $db = Loader::db(); $r = $db->Execute($query); $records = []; while ($row = $r->FetchRow()) { $records[] = $row; } return $records; } }
$categorySelection[$t['id']] = $t['team_name'];
}
bit
Just comment so that if someone else stumbles upon this they can get it - faster than I have. Anyways got it working in my situation - just wanted to confirm that I was understanding. I also take that you model function is being used other places as well.
Anyway thanks again.
Jim
All of this in mind, if you have something to contribute to the community it would be great to see a How-To posted on something you have done that you found difficult due to lack of documentation. This will not only help others trying to accomplish the same or similar goals, but also helps to indicate that gap exists.
One of my favorite resources to go look at is this simple c5 cheat sheet. It has a great number of basic examples / code snippets.
http://www.weblicating.com/doku/doku.php?id=cheatsheet/#.U11xO_ldW5...