the more I read the more confused I become.

Permalink 1 user found helpful
Let me explain. I look at others coding and there seems to be a lack of consistency in how things are coded. Especially with the MVC. I have seen lots of Model pages that just include a name and a var $_table = 'dbTable';

then 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.

INTcommunications
 
exchangecore replied on at Permalink Reply
exchangecore
It's a well known fact that C5's documentation leaves a little to be desired in many areas. I find myself more often than not digging through code just to figure out how things work. That said, if you are looking for examples on how to do things, I've found that asking the people in the IRC channel are extremely helpful. They've often got samples / tid bits of code and they are usually quite well designed and follow best practices.

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...
INTcommunications replied on at Permalink Reply
INTcommunications
i do try to answer questions that are in my wheel house and If I ask a question and figure something out I go back and mark the person that got me there and then post a "if anyone is interested " reply with what eventually happened for me.

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.
exchangecore replied on at Permalink Best Answer Reply
exchangecore
For a form helper with a select you could do something like this in your view file:

$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.
INTcommunications replied on at Permalink Reply
INTcommunications
Thanks so much for this detailed explanation - I am guessing that you have used this before - the only line I don't understand is the -
$categories = MyPackageProductCategories::getActiveCategories();

MyPackageProductCategories is your model? what is the second part?

Thanks so much.
exchangecore replied on at Permalink Reply
exchangecore
Exactly. MyPackageCategories is my model, it contains a static function that simply queries the database and returns an array of my categories and their associated ID's. I then pull those to my controller, then loop through them to make an associated array that looks something like this in the end:

array(
  0 => '',
  1 => 'Fish',
  2 => 'Pork',
  5 => 'Fruit',
  25 => 'Dairy'
);
INTcommunications replied on at Permalink Reply
INTcommunications
I figured you were passing a function or class with the :: - The :: reference is something that I wasn't quite sure about

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
exchangecore replied on at Permalink Reply
exchangecore
The :: simply means that it is a static function, that is, the function does not need an instance of the object in order to exist (you can read a little more about thishttp://www.exchangecore.com/blog/php-self-vs-this/... ).

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;
    }
}
INTcommunications replied on at Permalink Reply
INTcommunications
Thanks for clarification. I needed to connect the two loops to figure out whats going on- so you are looping through your records in the model and then looping through them again and formatting them for the select paramenter? i.e. the foreach($teams AS $t){
$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.
exchangecore replied on at Permalink Reply
exchangecore
You got it. I reuse that model function elsewhere so I do the reformatting of the data in my controller. That said I think it would probably be acceptable to have a function in your model that gives you back your data in the desired format if that makes sense to you. In my case, I only use a select box with that data in one spot, so it was just as easy to wrap that in the controller, which is where I would typically build my arrays for view stuff anyway
INTcommunications replied on at Permalink Reply
INTcommunications
I probably will do the same thing as I haven't built the CRUD for the enduser to input their own choices for the select. So I probably will have a function that returns records anyway. learned a ton on this thread.
Jim

This website stores cookies on your computer. These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media. To find out more about the cookies we use, see our Privacy Policy.