• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CodeExtinguisher 2.0 Release Candidate 14.2

[eluser]Paul T[/eluser]
[quote author="OOBE" date="1218724329"]When I use OneToMany plugin, click "Add new", the form without a submit button.
How can I submit it?[/quote]

The related record will be added when you submit the current record you are editing.

[eluser]Paul T[/eluser]
Hi Rob,

No need to apologize when asking for help. We've all benefited from the CodeIgniter community. The best thing to do is participate and return the favor, if possible.

As far as your issue goes, I ran into similar (if not the same) problems when I started working with Codex. After messing with it quite a bit, I went back to the examples and I finally discovered what works.

To use your application, Codex wants your main form to be named music_form.yml. If you are referring to the music table from another table, it will look for music.yml.


In my app, here's the setup:

staff, departments, departments_staff

Here's staff_form.yml:

Code:
name_first:
    class: TextBox
    label: First Name
name_last:
    class: TextBox
    label: Last Name
title:
    class: TextBox
    label: Job Title
departments:  //This is the name of the related table. Codex assumes the join table will be
              //named alphabetically by table name. In this case, departments_staff.
              //Codex will look at departments.yml for the form_setup.
    class: ManyToMany
    params:
        display_field: name

And departments_form.yml:

Code:
name:
   class: TextBox
   label: Department Name
description:
   class: Editor
   label: Description
   attributes:
       rows:10
       cols:100
   params:
       options:
           theme: advanced
           plugins: fullscreen,paste,spellchecker
           theme_advanced_toolbar_location: top
           theme_advanced_toolbar_align: left
           theme_advanced_buttons1_add: |,forecolor,fullscreen
           theme_advanced_buttons3_add : spellchecker
           spellchecker_languages : "+English=en"

When you want to directly access the staff or departments tables, Codex uses the *_form.yml file (no form_setup). But when you include the ManyToMany plugin, Codex looks for the *.yml file.

For example, in my code it needs to see the departments.yml:

Code:
form_setup:
    name:
        class: TextBox
        label: Department Name
    description:
        class: Editor
        label: Description
        attributes:
            rows:50
            cols:100
        params:
            options:
                theme: advanced
                plugins: fullscreen,paste,spellchecker
                theme_advanced_toolbar_location: top
                theme_advanced_toolbar_align: left
                theme_advanced_buttons1_add: |,forecolor,fullscreen
                theme_advanced_buttons3_add : spellchecker
                spellchecker_languages : "+English=en"

Notice that in this file, which we only access indirectly via the ManyToMany plugin (to access directly we use departments_form.yml), there is a form_setup at the top.

So it appears that Codex assumes specific naming conventions. As troubleshooting step if you get stuck, you may try only using underscores in join tables (i.e. MUSICTYPES vs. MUSIC_TYPES). All my tables are named lowercase, but I don't think that matters. Anyway, something to try if you get stuck.

Also, make sure your join tables have the field names Codex likes. For my departments_staff: id, departments_id, staff_id.

Oh, and make sure your yml files do not contain tabs--spaces only.

Good luck, Rob. I hope this was clear enough to help!

[eluser]Rob Stefanussen[/eluser]
Hi Paul, thank you so much for the explanation, it's making a lot more sense, even from a quick skim. I will try to integrate this later tonight, and let you know how it goes. Thanks!

[eluser]Nagyman[/eluser]
Note: See UPDATE below.

Hey! I found the post below while searching for a solution to "prepForDB null values".

[quote author="jTaby" date="1212624776"]gusa, Actually, I'm not sure you can do that without modifying the code a little bit. At first glance, my instinct was to tell you to create a new plugin exactly like TextBox, but with a different prepForDb function. But if you return NULL from prepForDb, then the whole thing will be omitted from the query. If that's fine, then go ahead and do it. If you intend on setting the value as NULL, then I would add a checkbox and in your plugin's prepForDb function, I would do what needs to be done and return NULL...[/quote]

The ability to set a field to NULL when it's empty is very important. INSERTing new records is no problem, because setting the value to NULL omits it from the SQL INSERT and the default NULL in the database can take care of that.

The big problem arises when you want to UPDATE a value and set it to null. The source of the issue is in this function in plugins/codexevents.php

Code:
function prepForDb($data=array()){
        $result = $this->CI->codexforms->iterate('prepForDb',$data);
        foreach($result as $field=>$v)
            if($v === NULL){
                unset($result[$field]);  // PROBLEM!
            }
            else if(is_array($v)){
                foreach($v as $key=>$val){
                    if($val !== NULL)    // ALSO, A PROBLEM.
                        $result[$key] = $val;
                }
                array_merge($result,$v);
                unset($result[$field]);
            }
        return $result;
    }

I'm going to guess that the motivation for unsetting the field was to add the ability to remove a field completely from the INSERTs/UPDATEs??? However, null has important meaning and another mechanism is necessary. (CodeIgniter knows how to handle null values.)

Personally, I will be changing the above code to this:

Code:
function prepForDb($data=array()){
        $result = $this->CI->codexforms->iterate('prepForDb',$data);
        foreach($result as $field=>$v)
            if(is_array($v)){
                foreach($v as $key=>$val){
                   $result[$key] = $val;
                }
                array_merge($result,$v);
                unset($result[$field]);
            }
        return $result;
    }

If I encounter problems with this change, I'll post them here. jTaby, if you foresee problems already, please let me know. Thanks!

UPDATE (20080922)

Ok, the above worked alright until I tried to use the ManyToMany plugin, which returns NULL from the prepForDB function. The expected result being that the value would not be inserted/updated since it would be removed. With the change I made above, the ManyToMany field was added to the UPDATE/INSERT statement as field = NULL, but the field doesn't exist in that table, so it fails.

Here's my suggested change; I'll go with it until I find another problem. prepForDB functions can now return a "NULL" string which will be converted to a null value to be inserted/updated. If prepForDB returns NULL (not a string, but the literal), it won't be included in the statement. The only downside is that you can't insert a NULL string into a text field in the database, but hopefully that doesn't come up very often.

Code:
function prepForDb($data=array()){
        $result = $this->CI->codexforms->iterate('prepForDb',$data);
        foreach($result as $field=>$v)
            if($v === NULL){
                unset($result[$field]);
            }
            else if(strtoupper($v) == "NULL")
            {
                $result[$field] = null;                
            }
            else if(is_array($v))
            {
                foreach($v as $key=>$val){
                    if($val !== NULL)
                        $result[$key] = $val;
                }
                array_merge($result,$v);
                unset($result[$field]);
            }
        return $result;
    }

[eluser]Rob Stefanussen[/eluser]
Paul, thanks for the tips, I was able to get it working! I thought you might like to know about a little discovery I made while I was at it. At first, I was using the naming my YML with "_form", but that wasn't working. After digging around in the code, I found out what was going on. From what I can tell, there's nothing special about "_form" to CodeEx.

You can either do your CRUDs using a custom controller, or use the default controller. Right now, I'm using the default controller until I have a better handle on things. The reason YMLs don't need the form_setup directive is because it's defined in the $config array in the controller. It turns out that the trick is in the naming of the linking table and the foreign keys, which I wasn't able to figure out until I read your reply. I was a bit disappointed that CodeEx relies on an inflexible naming convention for this, but beggars can't be choosers, right?

I was able to get my tables linked up with these YMLs:

music.yml
Code:
form_setup:
    music_name:
        class: TextBox
    people:
        class: ManyToMany
        params:
            display_field: last_name
    music_types:
        class: ManyToMany
        params:
            display_field: music_type

music_types.yml

Code:
form_setup:
    music_type:
        class: TextBox

I hope this helps clear things up, someone please let me know if I'm way off base!

Thanks, Paul

[eluser]Treb[/eluser]
Hi there,

First of all: great tool!

I've implemented a backend application to manage 7000+ entries. When loading (unfiltered) all entries are streamed to the browser and after that they are paginated. This takes a very long time.

Is there a way to do queries per page like in sql SELECT * FROM table LIMIT 0,100 ?

Thanks.

Bert

[eluser]Treb[/eluser]
Hi There,

My database expects UTF-8 encoded strings, but the default character set is missing from the config.php.

Adding:
Code:
/*
|--------------------------------------------------------------------------
| Default Character Set
|--------------------------------------------------------------------------
|
| This determines which character set is used by default in various methods
| that require a character set to be provided.
|
*/
$config['charset'] = "UTF-8";

fixed it.

Enhancement for the next version?

Bert

[eluser]Majd Taby[/eluser]
hey guys, thanks for the continued interest. As you might have noticed, I haven't been participating in the forums at all in the past 2-3 months. There are multiple reasons, mainly:

1) I got tired of php
2) I needed a break from CE (a full year of development)
3) I got a job

So if you guys have some patches you'd like to see rolled into a release, please submit them to me (either through PM or email) and i'll svn commit them.

The project isn't dead...it's just put on hold.

[eluser]unsub[/eluser]
[edit]I have come up with a tentative solution, so I'm clearing space here, as the question is no longer relevant.[/edit]

[eluser]unsub[/eluser]
an edit button in table view.
<img src="http://www.unsub.ca/editbtn.jpg">
don't know if anyone would find this useful, and it's dead easy, but maybe there's a beginner like me here, so...

in codex/application/views/view_modes/table.php, around line 75 - 80 depending on what you've done to it, right below this...
Code:
<td width="60" class="first">&lt;input class="edit-button" type="checkbox" value="&lt;?php echo $entry[$this-&gt;codexadmin->primary_key]?&gt;" name="selected_rows[]"/>

... do this:

Code:
&lt;?php
$button = "<img >config->item('codex_asset_folder')."images/edit.png' />";
echo "&nbsp;".codexAnchor(str_replace('{num}',$entry[$this->codexadmin->primary_key],$this->edit_link),$button,array('title'=>'Edit Record'));
?&gt;

Then put your little edit btn icon in the assets images folder in whatever template you're using. For 'clean blue' it's here:
codex/assets/clean_blue/images/ <put your image here>

I drew that little pencil button in inkscape, so if you want it say so, i'll link to it. I figure most people here could draw a better one.

Hope that helps someone and doesn't just waste typespace Smile it was a request from the person this project was for, so i had to do it.

cheers.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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