luisdias / CakePHP-Report-Manager-Plugin

CakePHP 2.x Report Manager Plugin
MIT License
42 stars 22 forks source link

Schema() on Non-Object #9

Open larry-tx opened 11 years ago

larry-tx commented 11 years ago

Thanks for a great plugin. From the README.md file changelog, it appears that I'm using version 0.4.5.1. I can get to the /report_manager/reports page just fine, but when I try to add a report after having selected a model that does not have any one-to-many relationships, I get this error message:

Error: Call to a member function schema() on a non-object File: L:\xampp\htdocs\lel\app\Plugin\ReportManager\Controller\ReportsController.php Line: 257

If I select a model that has a one-to-many relationship and select the associated model from the drop-down, I get this error message:

Error: Table reports for model Report was not found in datasource default.

I've got a fairly large number of models, and that seems to happen across all of them. Any idea on what I may be doing wrong or need to correct?

luisdias commented 11 years ago

Hi!

It seems that you are using the branch master with the modification made by netors. I have not created a tag from these changes because I have other enhancements to commit.

Try this tag and let me know if anything changes.

https://github.com/luisdias/CakePHP-Report-Manager-Plugin/archive/v0.4.5.1.zip

Best regards

larry-tx commented 11 years ago

Thanks for the super-fast response. Using netors' modification did get me a step further, but also opened another problem area. I have the following association specified in nearly all my models:

public $belongsTo = array(
    'Creator'  => array(
        'className'  => 'Users.User',
        'foreignKey' => 'creator_id',
    ),
    'Modifier' => array(
        'className'  => 'Users.User',
        'foreignKey' => 'modifier_id'
    )
);

(I'm using the CakeDC Users plugin.)

Now, when I try to go to /report_manager/reports and follow it on to the wizard, I've got a new error message:

**Error:** Table creators for model Creator was not found in datasource *default*.

Apparently, ReportManager and its wizard are ignoring the class designation in the $belongsTo statement.

Any idea how I could work around this?

luisdias commented 11 years ago

Try to add the model Creator to the «Ignore list» in the bootstrap.php file. It may solve the problem as as emergency solution.

Is there a table "creators" in your database?

larry-tx commented 11 years ago

I added this to bootstrap.php:

Configure::write('ReportManager.modelIgnoreList', array(
    'AppModel',
    'Creator',
    'Modifier',
));

However, I still get this:

Error: Table creators for model Creator was not found in datasource default.

There is no table "creators" or "modifiers" in the database. Again, the relationship is:

public $belongsTo = array(
    'Creator'  => array(
        'className'  => 'Users.User',
        'foreignKey' => 'creator_id',
    ),
    'Modifier' => array(
        'className'  => 'Users.User',
        'foreignKey' => 'modifier_id'
    )
);

The table involved in both is "users." A user can create a record and can modify a record. Each model records who created it (by users.id) recorded as "creator_id" and who modified it (by users.id) recorded as "modifier_id." The belongsTo is supposed to clarify that by the className, both of which refer to the same model (Users.User) which, of course, points to the table users.

By the way, I do have this in the main bootstrap.php file:

CakePlugin::load(
    array(
        'Users.Users', array('routes' => TRUE),
        'Acl.Acl', array('bootstrap' => TRUE),
        'Utils.Sluggable',
        'ClearCache',
        'AclExtras',
        'DebugKit',
        'Upload',
        'ReportManager', array('bootstrap' => TRUE),
    )
);

I tried copying the «Ignore list» directive into the main bootstrap.php file, but that didn't change anything. I still get the same message.

It occurred to me that seeing the Stack Trace might be helpful to you. It is:

CORE\Cake\Model\Model.php line 3191 → Model->setSource(string)
CORE\Cake\Model\Model.php line 1305 → Model->getDataSource()
APP\Plugin\ReportManager\Controller\ReportsController.php line 254 → Model->schema()
[internal function] → ReportsController->wizard(string, string)
CORE\Cake\Controller\Controller.php line 485 → ReflectionMethod->invokeArgs(ReportsController, array)
CORE\Cake\Routing\Dispatcher.php line 186 → Controller->invokeAction(CakeRequest)
CORE\Cake\Routing\Dispatcher.php line 161 → Dispatcher->_invoke(ReportsController, CakeRequest, CakeResponse)
APP\webroot\index.php line 92 → Dispatcher->dispatch(CakeRequest, CakeResponse)
luisdias commented 11 years ago

Did you try to add "User" to the ignore list? I don't know the DC Users plugin, but this line seems strange to me : 'className' => 'Users.User'

larry-tx commented 11 years ago

I just tried adding "User" to the ignore list, and it produced the same error.

The line 'className' => 'Users.User' is not unique to the CakeDC plugin. It comes straight out of the CakePHP API and Cookbook documentation (http://book.cakephp.org/2.0/en/plugins.html) which states:

You can reference a plugin’s controllers, models, components, behaviors, and helpers by prefixing the name of the plugin before the class name.

For example, say you wanted to use the ContactManager plugin’s ContactInfoHelper to output some pretty contact information in one of your views. In your controller, your $helpers array could look like this:

public $helpers = array('ContactManager.ContactInfo');

In this case, the plugin is Users, and the model is User, hence Users.User. If your plugin had a model, it would be referenced as ReportManager.SomeModel.

In addition, this method of referring to a plugin model works very well with all the other plugins in my application, as well as all the non-plugin models, of which I have a considerable number.

luisdias commented 11 years ago

See the content of $associatedModels after line 249. Maybe it can help you.

larry-tx commented 11 years ago

I think I'll wait until your plugin matures a little. A word to the wise, in your controller, you've got public $uses = array();. I tried completely commenting out the belongsTo association, and got beyond the Error: Table creators for model Creator was not found in datasource default. Then, guess what, I got this error message:

Error: Table report_managers for model ReportManager not found in datasource default.

CakePHP 2.2 (or maybey 2.1) and beyond handles this differently. The statement should be:

$uses = false;

Unfortunately, I made that change and actually got into the wizard, but after selecting the fields in step 1, clicking "Next" produced no action whatsoever. As I said, I think I'll just wait. Please let me know if you come up with a major revision so that I can try it again.

luisdias commented 11 years ago

I will try to create the same environment with the Users DC plugin to test it and improve it. The only DC plugin which I have tested with ReportManager was the search plugin. Thank you for your contribution. I will keep you informed.

Best regards

larry-tx commented 11 years ago

I almost forgot; be sure to take a look at _Multiple relations to the same model_ in the CakePHP Cookbook at http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html.

clarkritchie commented 11 years ago

Same issue here (both master and 0.4.5.1). I'm not using Users DC.

I don't have time to debug this extensivley, but this seems to work:

if ( $reportAction == "load" ) {
            $fileName = urldecode($param2);            
            $fileName .= '.crp';
            if ($fileName!='') {
                $params = explode('.', $fileName);
                if (count($params)>=2) {
                    $modelClass = $params[0];// $params[0];
                    if (count($params)>3) {
                        $oneToManyOption = $params[1];
                    } 
                }
            }             
        }