Codeigniter css in view - css

I added new function which is called "css_url". I set in constructor of controller, It works.
Besides, I want to reach in assets in view. In view directory I put themes, and each themes has own assets. How can I reach assets in view directory?
-view
--theme1
---assets
----css
----js
----images
-----f1.jpg
enter code here
public function __construct() {
parent::__construct();
// Temel veriler veri tabanından çekilecek;
$this -> theme = "theme1";
$this->config->set_item('css_url', $this->theme);
}
css_url("images/f1.jpg");

goto application/config/autoload.php and url helper like this...
$autoload['helper'] = array('url');
Now you are able to access assets folder in your view using base_url() function like this...
<?php echo base_url('assets/css/yourstyle.css'); ?>
Place your assets folder on root of your application...
application/
assets/
system/

Related

wordpress live site : include them class in a cron job

import a class from theme directory outside of wordpress.
The CRON
I am cronning a daily job via Cpanel for my site that will feed a stats table. I created a file in the root Home/myDirectory (same level as public_html ) beloo is the code
<?php
include dirname(__FILE__) . '/public_html/wp-load.php'; // Load WP Functions
include dirname(__FILE__) . '/public_html/wp-content/themes/cooking/config/Data/ViewsData.php'; // require a class
function test(){
if(class_exists('ViewsData')){
$viewsData = new ViewsData;
$views= $viewsData::getViews(394);
update_post_meta(394 , 'views_test', $views);
}
die();
}
test();
THE CLASS
as shown in the code I am trying to include a class from the theme folder. this class include different functionaries to set , get and update the views data> bellow is an idea of how the class is structured ;
namespace GS\Data;
use GS\DisplayFunc;
class ViewsData {
static function getViews(){}
}
however class_exists('ViewsData') always return false.
any suggestions on what is wrong. or even on how to reorganize the whole cron solution. the most important is that I need to use many classes from my theme folder.
I was able to find the problem. it has to do with namespaces the code that works bellow :
<?php
include dirname(__FILE__) . '/public_html/wp-load.php'; // Load WP Functions
include dirname(__FILE__) . '/public_html/wp-content/themes/cooking/config/Data/ViewsData.php'; // require a class
function test(){
if(class_exists('GS\Data\ViewsData')){
$viewsData = new ViewsData;
$views= $viewsData::getViews(394);
update_post_meta(394 , 'views_test', $views);
}
die();
}
test();

SilverStripe renaming uploaded file only for specific field

I have extended CMS settings to upload two CSS files. Part of the SiteConfig extension code -
<?php
//OTHER CODES HERE
$fields->addFieldToTab('Root.Main', $cssfile = UploadField::create(
'StyleSheet',
'Style Sheet'
));
$fields->addFieldToTab('Root.Main', $clientcssfile = UploadField::create(
'ClientStyleSheet',
'Client Style Sheet'
));
//OTHER CODES HERE
?>
And i have extended the File class
class FileRenameExtension extends DataExtension {
function onAfterUpload() {
$file = $this->owner;
$file->Name = 'CustomStyle.'.$file->getExtension();
$file->write();
}
}
PROBLEM
The code renames the file uploaded from all the fields, but I want to rename the files uploaded from ClientStyleSheet only.
Before it renames the file, if user uploads file with name that already exists, it warns, and if I click Overwrite, it overwrites the files and renames the file. I just want no matter what is the file name, it just saves the file with name that is specified in the File Extension Class
What is the proper way to rename file before its get uploaded?
You better use FileField directly in your case with custom upload() action handler.
With the DataExtension, you modify all instances of File, wherever they are uploaded.
One possible solution: You subclass File and hook into onAfterUpload:
class CSSFile extends File {
function onAfterUpload() {
$file = $this;
$file->Name = 'CustomStyle.'.$file->getExtension();
$file->write();
parent::onAfterUpload();
}
}
Now you use this in your SiteConfig, it should work with UploadField just like a standard File.
If I understand it correctly, you want to enable the user to add a stylesheet to the site. A different solution would then be to allow any filenames and to use the original filename in the template:
<link rel="stylesheet" href="$SiteConfig.StyleSheet.URL">
I would prefer to use this second solution.

disable a css only for one layout yii2

I am trying to integrate a custom theme on YII2 basic app.
I have two layouts, the main layout and other is login layout.
Now I don't need a css file say xyz.css on login layout but it gets loaded there and my design is getting messed up. Any proper way of disabling it on that one layout?
I am registering my css files from AppAsset.php file.
the css section look like
public $css = [
'themes/mytheme/assets/css/xyz.css',
'themes/mytheme/assets/css/main.css'
];
Step - 1: Create LoginAsset.php in assets Folder.
LoginAsset.php
In this file, Keep those .css & .js which is required for login.
<?php
namespace app\assets;
use yii\web\AssetBundle;
class LoginAsset extends AssetBundle
{
public $basePath = '#webroot';
public $baseUrl = '#web';
public $css = [
'css/include-your-css-if-any.css'
];
public $js = [
'js/include-your-js-if-any.js',
];
}
Step - 2: Since, you told that you are having one more layout i.e. login layout. So, Use LoginAsset.php in your login layout, Like:
login.php (One out of two layouts i.e. main/login.php)
<?php
use yii\helpers\Html;
use app\assets\LoginAsset;
LoginAsset::register($this);
?>
<?php $this->beginPage() ?>
.
. // Your code
Step - 3: If even though it didn't worked. Then,
Include
<?php
use app\assets\LoginAsset;
LoginAsset::register($this);
.
.
?>
on top of your view file.
Related Search
Two Different Layouts For Guest User & Logged In User-Yii2

Fetch image from specific directory in drupal

I'm beginner in drupal. I would like to fetch images from specific folder in drupal. Is there any way to fetch drupal images directly from any specific in custom theme.
You should use only images from your theme. And you can get path to your theme like this:
$theme = drupal_get_path('theme',$GLOBALS['theme']);
Put that i.e. at top of template file that uses theme images. And then inside your theme templates you can have something like:
<img src="/<?php echo $theme; ?>/images/my_image.png">
If you stored you theme images inside images dir...
If an array of image paths on your local filesystem is what you want - use this code, it should do what you need. gets all the png jpg gif paths within the sites/default/files/vegas directory.
//We will use the stream wrapper to access your files directory
if ($wrapper = file_stream_wrapper_get_instance_by_uri('public://')) {
//Now we can easily get an actual path to that folder
$directory = $wrapper->realpath();
//Don't forget to append your "vegas" subfolder here
$directory .= DIRECTORY_SEPARATOR . 'vegas' . DIRECTORY_SEPARATOR;
$images = glob($directory . "*.{jpg,png,gif}", GLOB_BRACE);
foreach($images as $imagePath)
{
//Do your thing!
echo $imagePath;
}
}

Wordpress menu in Codeigniter controller

I try to call from my Codeigniter controller as outside of the box my Wordpress blog menu, but I get the following error
Fatal error: Cannot redeclare site_url() (previously declared in /../system/helpers/url_helper.php:53)
public function getWordpressMenu() {
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
// no theme output
define('WP_USE_THEMES', false);
// initializes the entire Wordpress
require $_SERVER['DOCUMENT_ROOT'] . 'blog/wp-blog-header.php';
wp_nav_menu('your_theme_menu_location');
}
I know both of frameworks have the same function but is there a way to disable on of inside of controller?
In Codeigniter you can simply replace your helpers by creating a new file at application/helpers
In your case, you can simply create a new file at application/helpers with name url_helper.php
Just copy the url_helper.php from the folder system/helpers and copy it to application/helpers/ . Now Open the file url_helper.php and rename the function url_helper to something else, for example: ci_site_url

Resources