Git Product home page Git Product logo

Comments (2)

ThaDafinser avatar ThaDafinser commented on June 11, 2024

From @jonathangreco on June 2, 2015 13:47

I think you inversed column and table values.

Column should be with 'p' value.
table should be with 'name' value.

This seems to work.

from zfc-datagrid.

ThaDafinser avatar ThaDafinser commented on June 11, 2024

From @olexp on June 2, 2015 16:12

It seems you didn't read the example code. 'p' stands for 'Application\Entity\Product'. It couldn't be column. Also alias in exception (p_name) created for name.p should say that it is something wrong.

Let me explain what really happens in code.
This part of Datagrid.php works correctly:

        if ('ZfcDatagrid\\Column\\Select' == $class) {
            if (! isset($config['select']['column'])) {
                throw new \InvalidArgumentException('For "ZfcDatagrid\Column\Select" the option select[column] must be defined!');
            }
            $table = isset($config['select']['table']) ? $config['select']['table'] : null;
            $instance = new $class($config['select']['column'], $table);
        } else {

and we have instance of Select in $instance. Few lines below it there is loop:

        foreach ($config as $key => $value) {
            $method = 'set'.ucfirst($key);
            if (method_exists($instance, $method)) {
                if (in_array($key, $this->specialMethods)) {
                    if (! is_array($value)) {
                        $value = array(
                            $value,
                        );
                    }
                    call_user_func_array(array(
                        $instance,
                        $method,
                    ), $value);
                } else {
                    call_user_func(array(
                        $instance,
                        $method,
                    ), $value);
                }
            }
        }

When it comes to 'select' key the method 'setSelect' is triggered on $instance and that's where the values of table and column switched. setSelect is called with $value = array('column' => 'name', 'table' => 'p') that magically transforms to setSelect('name', 'p'). Order here is important and it could be changed in action ($grid->addColumn()) but executing method call like this is unsafe.

As I already wrote, skipping key with 'select' value in loop could help.

from zfc-datagrid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.