简体   繁体   English

如何在cakephp中的“ configure :: write()”内部添加图像链接?

[英]How to add an image link inside “configure::write()” in cakephp?

I want to set a logo for my application. 我想为我的应用设置徽标。

In my AppController.php page I wrote the following line of code: 在我的AppController.php页面中,我编写了以下代码行:

Configure::write('CompanyLogo','echo $this->Html->image('logo.png', $options = array());');" 

But, It's not working for me. 但是,它对我不起作用。 Do you have any suggestion how to make it work? 您对如何使其工作有任何建议吗? Thanks 谢谢

Components in controllers and helpers in views. 控制器中的组件和视图中的助手。 You are currently trying to use a helper in a controller, which won't work. 您当前正在尝试在控制器中使用辅助器,该辅助器将无法工作。 instead write the image_name in config : 而是在config中写入image_name:

`Configure::write('Config.logo', 'logo.png');`

use this into layouts/views 用它来布局/视图

$image_name= Configure::read('logo');

$this->Html->image($image_name, array());

Don't use "echo" inside a function parameter. 不要在函数参数中使用“ echo”。 So it should be Configure::write('CompanyLogo',$this->Html->image('logo.png')); 所以应该是Configure :: write('CompanyLogo',$ this-> Html-> image('logo.png'));

You can simply write the image path in "configure::write" and access it in view Like: Configure::write('CompanyLogo', $this->webroot."img/logo.png"); 您可以简单地在“ configure :: write”中写入图像路径,然后在视图中访问它,例如: Configure :: write('CompanyLogo',$ this-> webroot。“ img / logo.png”); and in view you can use this: < img src="< ?php echo Configure::read('CompanyLogo');?>"/> 并在视图中可以使用此命令: <img src =“ <?php echo Configure :: read('CompanyLogo');?>” />

But good practice using this in view: $this->Html->image('logo.png'); 但是在视图中使用此方法是一种好习惯: $ this-> Html-> image('logo.png');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM