CakePHP 3 : Define global contant variable -


i working on cakephp 3 project little big.

i want keep application clean possible separating media files core application , that's why have store media files on separate subdomain media.myproject.com , project accessible www.myproject.com.

also in media.myproject.com there many directories as

/root |- users    |- avatar    |- cover |- services    |- logo    |- banner    |- slides |- clients    |- logo    |- avatar |- etc    |- etc    |- etc    |- etc 

now, able access files in application view want set global variables can use in view like

<img src="<?= $media.$mediauser.$useravatar.$user->avatar ?>" /> 

how ?

you can make this:

config/bootstrap.php

configure::write('media', array(         'users' => array(             'avatar' => 'media.myproject.com/users/avatar/',             'cover'  => 'media.myproject.com/users/cover/'           ),         'services' => array(             'logo' => 'media.myproject.com/services/logo/',             'banner'  => 'media.myproject.com/services/banner/'          )  )); 

yourview.ctp

<?php use cake\core\configure; ?>   <img src="<?= configure::read('media.users.avatar').$user->avatar ?>" /> 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -