"Use of undefined constant" 尝试在 codeigniter 中显示图像时出错
"Use of undefined constant" error while trying to display image in codeigniter
我是 codeigniter 的新手,在尝试显示图像时遇到问题。
这是我的代码:
<img src="<?php echo base_url(images/sty2.png);?>" alt="">
这是错误信息:
A PHP Error was encountered Severity: Notice Message: Use of undefined
constant sty2 - assumed 'sty2' Filename: views/index.php Line Number:
195 Backtrace: File:
C:\xampp\htdocs\SAMSON\application\views\index.php Line: 195 Function:
_error_handler File: C:\xampp\htdocs\SAMSON\application\controllers\Home.php Line: 31
Function: view File: C:\xampp\htdocs\SAMSON\index.php Line: 315
Function: require_once
我该如何解决这个问题?
我不使用 codeigniter,但根据 https://www.codeigniter.com/user_guide/helpers/url_helper.html 你的语法似乎是正确的,除了缺少引号。
echo base_url("images/sty2.png");
你加载助手了吗?
类似于:$this->load->helper('url');
我是 codeigniter 的新手,在尝试显示图像时遇到问题。
这是我的代码:
<img src="<?php echo base_url(images/sty2.png);?>" alt="">
这是错误信息:
A PHP Error was encountered Severity: Notice Message: Use of undefined constant sty2 - assumed 'sty2' Filename: views/index.php Line Number: 195 Backtrace: File: C:\xampp\htdocs\SAMSON\application\views\index.php Line: 195 Function: _error_handler File: C:\xampp\htdocs\SAMSON\application\controllers\Home.php Line: 31 Function: view File: C:\xampp\htdocs\SAMSON\index.php Line: 315 Function: require_once
我该如何解决这个问题?
我不使用 codeigniter,但根据 https://www.codeigniter.com/user_guide/helpers/url_helper.html 你的语法似乎是正确的,除了缺少引号。
echo base_url("images/sty2.png");
你加载助手了吗?
类似于:$this->load->helper('url');