Call to a member function build() on boolean error in CakePHP 3

707 views Asked by At

I am using the below code in my Controller file to generate full site URL

$this->Url->build(['controller' => 'home', 'action' => 'index'], true);.

But I am getting a "Call to a member function build() on boolean" error. The reason why I am not using

Router::URL(['controller' => 'home', 'action' => 'index']);

is I don't want a relative URL. Can't I use Url builder in the controller?

1

There are 1 answers

0
Oliwer Lisek On

I think, the main reason of your Error is wrong name of Controller.

First,Name Conventions says

"Controller class names are plural, PascalCased, and end in Controller. UsersController and ArticleCategoriesController are both examples of conventional controller names."

so your file name must be like HomesController.php. Next the Class name should be like this HomesController.

Secondly, for CakePHP character size matters. If you want build URL to your controller you have to do like this

$this->Url->build(['controller' => 'Home', 'action' => 'index'], true);

Where controller name should be capitalize.

More about building URL in CakePHP