PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 1, 2022

[FIXED] CakePHP 3.8 - How to access public path to webroot in view?

 January 01, 2022     cakephp, cakephp-3.0     No comments   

Issue

Migrating from 2.3.x to 3.8 and I can't figure out how I may access the public path to webroot in my views. Previously I could do something like this:

<link rel="stylesheet" type="text/css" href="<?php echo $this->webroot ?>wp-dist/acd76cde.css" />

But when I try this on 3.8 it says:

Error: webrootHelper could not be found.

I tried html helper, but can't find a helper method which gives just the public path to webroot. For example image() is relative to webroot/img, css() is relative to webroot/css and so on.

Am I missing something?


Solution

Update:

As @ndm said in the comments above, the following works for me as well.

echo $this->Html->css('lightweight_lpbbd374e3', ['pathPrefix' => 'wp-dist/']);

Original my solution, which works too

$this->Url->webroot finally worked for me. So I'm including my css as follows:

<link rel="stylesheet" type="text/css" href="<?php echo $this->Url->webroot('wp-dist/lightweight_lpbbd374e3.css'); ?>" />

Until someone else suggests a better way, I'll continue using this.



Answered By - Souvik Ghosh
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing