简体   繁体   English

Codeigniter如何在php codeigniter中从数据库中检索base_url

[英]Codeigniter how to retrieve base_url from database in php codeigniter

As I am retrieving a column of content in html form, from database as this column contain text and image which is retrieved through base url();当我以 html 形式检索一列内容时,从数据库中检索,因为该列包含通过 base url() 检索的文本和图像;

see example:见示例:

<p>Although the complexities, individualities and uniqueness of the human mind is beyond 
imagination, let alone comprehension.</p>

<img src="<?php echo base_url(); ?>assets/uploads/guide-banner.jpg" alt="guide" />

data mentioned above is stored in database field.上面提到的数据存储在数据库字段中。 I can retrieve html fine but I can't access base_url() from database field, help me what i'm doing wrong calling php while we are already in php ??我可以很好地检索 html,但我无法从数据库字段访问base_url() ,帮助我在我们已经在 php 中调用 php 时我做错了什么?

you can use like this syntax to retrieve image from database in codeignitor您可以使用这种语法从 codeignitor 中的数据库中检索图像

<?php foreach($results_partners as $part) { ?>
    <a href="main/partner" class="roller-item fancybox fancybox.ajax">
        <img src="<?php echo base_url() .'cms/uploads/partners/thumb_290/'.$part->partner_image; ?>" style="width:264px; height:263px;"> 
    </a>
<?php } ?>        

You cannot execute PHP code inside PHP code !.您不能在 PHP 代码中执行 PHP 代码!。 I think we can do some trick to make PHP chunks executable.我认为我们可以做一些技巧来使 PHP 块可执行。

At this point we need JavaScript capabilities , you have to put that column content into JavaScript variable , then output that variable to your page while loading.此时我们需要 JavaScript 功能,您必须将该列内容放入 JavaScript 变量中,然后在加载时将该变量输出到您的页面。 You can notice at that moment your PHP code converted to real output !您会注意到此时您的 PHP 代码已转换为实际输出!

I hope this helping you !我希望这对你有帮助!

你可以使用这样的语法。

<img src="' . base_url() . 'assets/uploads/guide-banner.jpg " alt="guide" />'

assign your base_url() to a variable like将您的base_url()分配给一个变量,如

$base_url = base_url();

modify your code as shown修改您的代码,如图所示

<p>Although the complexities, individualities and uniqueness of the human mind is beyond 
imagination, let alone comprehension.</p>

<img src="{$base_url}assets/uploads/guide-banner.jpg" alt="guide" />
      ---^            

Is there any solutions to the above tex field which contains PHP code? 上述包含PHP代码的tex字段是否有解决方案? Can any one provide the solution to the above problem? 任何人都可以为上述问题提供解决方案吗?

it will solve this: change your base_url();它将解决这个问题:改变你的 base_url(); to the content of base_url : exp: http://localhost/blablabla ;到 base_url 的内容: exp: http://localhost/blablabla ; through var_dump(base_url());通过 var_dump(base_url());

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

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