LInking to CSS from Module CodeIgniter - codeigniter

So I have a module setup and working, and have setup an asset folder within it containing a css and js folder. My files are in there, but when I try linking to them like this:
<script type="text/javascript" src=/application/modules/badge_progress/assets/js/jquery.jcarousel.js"></script>
Or this:
<script type="text/javascript" src=<?php echo base_url(); ?>/application/modules/badge_progress/assets/js/jquery.jcarousel.js"></script>
They don't work. What is the proper way to link to the files?

You have a problem with your quotation marks. The src value starts with no quotation mark but ends with one. Try
<script type="text/javascript" src="<?php echo base_url();?>/application/modules/badge_progress/assets/js/jquery.jcarousel.js"></script>`

You cant access directly from /application folder from web browser.
Move badge_progress folder with same directory with application and try this
<script type="text/javascript" src="<? echo base_url();?>badge_progress/assets/js/jquery.jcarousel.js"></script>

keep your js and css file in root folder and try and check in firebug js file and css file is loading or not and what path is created for that file and then fix it.

Related

asset('assets') return to wrong directory after using prefix in laravel

This is the line I load my assets:
<script src="{{ asset('assets') }}/js/vendors/jquery-3.2.1.min.js"></script>
And here code from web.php for route settings:
Route::resource('masuk', 'Backend\ParkirInController');
It works fine with this code, but when I using a prefix like here:
Route::group(['prefix'=>'parkir'], function (){
Route::resource('masuk', 'Backend\ParkirInController');
});
The assets are not loaded and show an error like
require.min.js:5 GET http://localhost:8000/parkir/assets/js/vendors/jquery-3.2.1.min.js net::ERR_ABORTED 404 (Not Found)
So the name of prefix parkir is included to the assets URL.
Try changing this line:
<script src="{{ asset('assets') }}/js/vendors/jquery-3.2.1.min.js"></script>
to
<script src="{{ asset('/assets/js/vendors/jquery-3.2.1.min.js') }}"></script>
Here, you have just added a / before the assets so that the url starts from root instead of relative current path.
Finally I can solve it! This is because the dashboard.js from template is using require.js to set the required assets with a static path.
It look like this
Static path of assets
After I added / at the beginning of line like what #Imran said. It works fine

Laravel 5 recognizes some css and js files as routes

I'm getting mad with this issue.
Basically there are some css and js files which are opened correctly from laravel. But some other js and css files are recognized as routes!
For example: http://localhost:8000/assets/ammap/themes/light.js
I'm using the following code to access assets from templates:
<script type="text/javascript" src="{!! asset("assets/ammap/themes/light.js") !!}"></script>
Obviously the path is correct and the file exists.
I've solved the problem.
I'm using OS X and it was a permission issue.
chmod -R 0777 public
Then set everyone to "Read & Write" into file permissions.

How I can call a file in CodeIgniter, that has existed in core folder

I am a absolute beginner of CodeIgniter, Now I was creating a simple project with CI. But I don't know how I can call a file that has existed in core folder.
Core folder is like the following
/core/bootstrap/bootstrap.css
I want to call bootstap.css from my view/admin/index.php
How I can call it?
I already try it like the following
<link href="/application/core/bootstrap/bootstrap.css" rel="stylesheet" media="screen">
but it still doesn't work.
You should not put your CSS files in the core folder. Best practice with CI is the following:
- application
- assets
-- css
-- js
-- images
- system
-- <all CI folders here>
Use a URL helper to point to the assets folder like:
function asset_url(){
return base_url().'public/';
}
more info on url_helpers
Then you can point to your assets in your view like this:
<link rel="stylesheet" href='<?php echo asset_url()."css/YOUR_FILE.css" ?>'/>
Look at documentation and read about url_helper.
Use internal links with function site_url() or base_url()
First of all I will not put my css files in the core folder.
I will create folder which is in the same level as in the "application" and "system" folder.
Secondly, you need to configure the base url at application/confi/config.php like
$config['base_url'] = 'http://localhost/NV/';
With in the folder "NV", I have my CI files such as "application" and "system".
Then in the view I will just use
<link rel="stylesheet" href="<?php echo base_url();?>css/ace.min.css"/>
In this case, the "CSS" folder resides as in the same level as "application" and "system" folders.

Access to root folder from subdomains (Codeigniter)

I have some trouble to access root dir files when using subdomains:
My css files located in css dir in the root.
If i use url "my-site.com/css/file.css" - everything okay
If i use url "en.my-site.com/css/file.css" - 404 error
How can i fix it? I don't want to hardcode path to all my css and js files.
Thanks
try this for for loading all images, styles, js
<link rel="stylesheet" href="<?php echo site_url('css/file.css'); ?>">
don't forgot to create directory in your main CI folder.
if you not able to get that like this:
<link rel="stylesheet" href="<?php echo base_url(); ?>css/file.css">
you have a server problems and it is not Codeigniter related ;)

.htaccess redirect for subfolder images and stylesheets

Is it possible with a .htaccess redirect to have all style sheets and image paths, that are located in a subfolder, point to the appropriate folder(images/styles) in the the root folder? With out having to change the path in each file.
Let me try to explain my situation a little better.
Im using an include (header.inc.php) that contains my doctype, stylesheet links
<link href="styles/layout.css" rel="stylesheet" type="text/css">
and a couple other html element/images.
That becomes an issue when header.inc.php in pulled into my subfolder files, because style/layout.css does not exist in that folder. Additionally there are
a couple images that break because of the same reason,
<img src="images/image.jpg">
the images folder does not exist…
In my current .htaccess file, I have the below script with my include path (for local testing). Is there something similar to the include_path script that can help with the issues listed above?
php_value include_path ".:/Applications/MAMP/bin/php/php5.4.4/lib/php:/Applications/MAMP/htdocs/site/inc"
Here is an example of the file structure/hierarchy.
[ROOT FOLDER]
index.php
/subfolder
subpage1.php
subpage2.php
subpage3.php
/subfolder2
subpage1.php
subpage2.php
subpage3.php
contact.php
/images
/styles
/scripts
/inc
You don't need to use rewrites to solve this you just need to now how to define the source properly in your HTML elements.
Don't do this
<link href="styles/layout.css" rel="stylesheet" type="text/css">
Do this
<link href="/styles/layout.css" rel="stylesheet" type="text/css">
What this has changed is that your path is no longer relative to the file being browsed to but is now relative to the root of your web site.
Hope that helps.

Resources