Welcome Guest, Not a member yet? Register   Sign In
CodeExtinguisher 2.0 Release Candidate 14.2

[eluser]Thoer[/eluser]
[quote author="abmcr" date="1213711760"][quote author="Thoer" date="1213709817"]I just wanted to gossip that I have successfully merged the current version with my development, which makes advanced sql calls with dbdropdowns and onetomany and manytomany plugins and fixes a lot of hardcoded English text. I'm really busy this week and jTaby seems to be missing too, but I'd love to share some code with you next week. (Some plugins and scaffolding is yet to be tested.) Would that make RC14.3? Smile[/quote]
Hello Thoer: maybe have you try this feature http://ellislab.com/forums/viewthread/79...90/#412515 ? Thank you[/quote]

I tried to run through the conversation, but as I said I'm quite busy this week, although I'd love to help. The problem you're trying to solve is to link a special element of a different table from a particular table. Like if you were having a "parents" table and a "children" table, and you wanted to add a link to the "children" table so you could instantly edit the given child's mother's data right? Let me know if I misunderstood the problem (and I appologise if so). Now point one is that I gotto say I'm sorry but it seems like a waste of time for me to debug and I cannot afford that right now. I'm saying this because it looks like a hack in the first place, and I have my hack for this problem which is (in my humble opinion) superior to this one. I'll explain it, but I must state beforehand that it is currently a hack, although I think a nice one. I wish it could be involved in the "official" version soon, but a couple month ago I was told that it must wait until the current version gets more stable. It may mess up something with the automated crud system which I never use, although I don't see how. It's gonna be a long one but I wish to hear some opinion so please bear with me:

1. First I added a new variable to codexcontroller:
Code:
class codexController extends Controller {
    var $entry = array();                //temporary data for other objects

2. I added a new line in codexcontroller which makes the data of the current table line available for any plugins.
Code:
function prepForDisplay($result){
        for($i=0;$i<count($result);$i++){
            //Update the active id
            $this->codexadmin->active_id = $result[$i][$this->codexadmin->primary_key];

            $db_data = $result[$i];
            $this->entry = $db_data;
...
        }
    }

3. I created a new plugin and named it Template (probably a poor name but I haven't come up with a better one yet), and added that to my "children" table. It should be like this:
definitions/children_form.yml
Code:
mother:
    class: Template
    template: <a href="parents/{mothers_id}">{mothers_name}</a>
But unfortunately spyc doesn't like to have HTML characters so I added it in my controllers/children.php to the $config['form_setup'] as a normal array. I'm sure it could be worked out but I didn't take the time since I don't use yaml files all that much. (They aren't flexible enough for my taste.)
Now the plugin doesn't really do much, it finds the text in the braces and tries to replace them with the corresponding data from the empty variable of the codexcontroller.

Template plugin soon...

[eluser]Thoer[/eluser]
OK, I still haven't got the time to doublecheck it but my Template plugin looks like this:
Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Template extends codexForms
{
    var $CI, $html, $func, $func_params;

    function Template($name,$params)
    {
        codexForms::initiate($name,$params);
        $this->CI =& get_instance();
        
        $this->html = isset($params['template']) ? $params['template'] : '';
        $this->func = (isset($params['func']) && method_exists($this->CI, $params['func'])) ? $params['func'] : '';
        $this->func_params = (isset($params['func_params']) && is_array($params['func_params'])) ? $params['func_params'] : array();
    }
    
    // Plugin doesn't need its own database value
    function getDbFields()
    {
        return NULL;
    }
    
    // Plugin is not to write anything into database
    function prepForDb($value)
    {
        return NULL;
    }

    // We search a simple string for values we'll need to change
    function prepForDisplay()
    {
        if ($this->func){
            $params = array();
            foreach ($this->func_params as $key => $param){
                if (isset($this->CI->save_data[$param])) $params[$key] = $this->CI->save_data[$param];
                else $params[$key] = $param;
            }
            if (empty($params)){
                $func = $this->func;
                $template = $this->CI->$func();
            }
            else $template = call_user_func_array(array($this->CI->controller_name, $this->func), $params);
        }
        else $template = FALSE;
        if ($template===FALSE) $template = $this->html;
        
        return preg_replace_callback('|{([^}]*)}|', array('Template', 'getRowData'), $template);
    }

    // We don't need it to show up in editing or adding views
    function getHTML()
    {
        return NULL;
    }
    
    function getRowData($key)
    {
        $CI =& get_instance();
        return $CI->entry[$key[1]];
    }
}
?&gt;
As you can see from prepDisplay definition it knows a bit more than just replacing string to values as it can also run some user defined function. I'll try to run it on a fresh codex install tomorrow.

[eluser]abmcr[/eluser]
Wow! i will try also. Thank you

[eluser]Thoer[/eluser]
It seems to be working, let me know if you're stuck! I'll try to force spyc to handle htmls somehow, probably by changing < and > to some other characters.

[eluser]Thoer[/eluser]
looks like all you need to do is put the html string inside single quotes. I've only tried a simple example, but it looks promising.
Code:
mother:
    class: Template
    template: '<a href="parents/{mothers_id}">{mothers_name}</a>'

[eluser]Thoer[/eluser]
[quote author="ocergyNohtna" date="1213647629"]nice. thanks. apparently it's set to 0 by default. why is my user getting kicked out once in a while?? i guess it has to be user error...[/quote]
Well, I just ran into this, and it turned out to be my mistake. I used the same session variable in the frontend and backend, so when I checked the changes on frontend I got kicked out, so I changed the config.php for the frontend...

[eluser]DennisP[/eluser]
Hi,

Is there any way to change the default id field to something else? I prefix most of my id fields with the table name, i.e. comment_id, but codeextinguisher looks for the id field in every table.

[eluser]Thoer[/eluser]
From controllers/example.php
Code:
$config = array(
                    'db_table' => 'example', //The name of the table associated with this controller
                    'form_setup' => $this->spyc->YAMLLOAD($this->codexadmin->getDefinitionFileName('example_form')), //The array that holds our elements
                    'controller_name' => 'Example', //The name of the controller, so that it can be used when generating the URLs
                    'primary_key' => 'my_id', //The name of the controller, so that it can be used when generating the URLs
                    'display_fields'=>array('textbox_test','date_test','related_example'),
                    'rules'=>$rules
                    );
so just change the primary_key and you should be okay.

[eluser]DennisP[/eluser]
One other thing... how do I join tables?

[eluser]Thoer[/eluser]
depending on what you're trying to achive, you can use DbDropDown, OneToMany and ManyToMany plugins.




Theme © iAndrew 2016 - Forum software by © MyBB