0

I got this error when I tried to integrate Plugins for charts. The plugins I found online are all for cake version 2.*. I try to did the same for 3.0 and got this error.Here's my code.I also tried high charts and got the same thing.

use App\Controller\AppController;


App::uses('AppController', 'Controller');
App::uses('GoogleCharts', 'GoogleCharts.Lib');

class ChartsController extends AppController {

  public $helpers = array('GoogleCharts.GoogleCharts');

//Setup data for chart
  public function index() {
  $chart = new GoogleCharts();

  $chart->type("LineChart");  
    //Options array holds all options for Chart API
    $chart->options(array('title' => "Recent Scores")); 
    $chart->columns(array(
        //Each column key should correspond to a field in your data array
        'event_date' => array(
            //Tells the chart what type of data this is
            'type' => 'string',     
            //The chart label for this column           
            'label' => 'Date'
        ),
        'score' => array(
            'type' => 'number',
            'label' => 'Score',
            //Optional NumberFormat pattern
            'format' => '#,###'
        )
    ));

//You can also manually add rows: 
    $chart->addRow(array('event_date' => '1/1/2012', 'score' => 55));

//Set the chart for your view
    $this->set(compact('chart'));
    }
}

1 Answer 1

3

You cannot just throw Cake 2x and Cake 3x stuff together and expect it to work, in case the plugin is not made for 3.x, you simply cannot use it as such.

You are receiving the error because there is no App class in the current namespace, Cake 3x uses real namespaces and autoloading, so if you'd wanted to use the App class, you would have to import it using the use statement

use Cake\Core\App;

However there is no App::uses() anymore anyways, you either use autoloading, or simply include/require the files manually.

Suggested readings:

Sign up to request clarification or add additional context in comments.

4 Comments

@przemo_li Missing what?
proper using and namespace in code examples :D (esp. if somebody install from composer)
@przemo_li You mean like here, and here, and here, and here, and... many other examples that are missing proper use statements and/or namespacing, just create an issue over at GitHub so that it can be fixed in case necessary.
@przemo_li Namespacing and PSR-4 are PHP 101, if somebody doesn't know about that, then s/he maybe shouldn't use a fully fledged PHP framework like CakePHP, but instead start to learn the basics first - no offense though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.