I have following Codeigniter 4 project structure. I am having problem with using base_url() and setting app.baseURL in .env file properly. Following two questions are due to this same problem:
Project Structure
wamp-web-root
ci_4_project
public
app
assets
APP Structure
public
system
app
Controllers
First_controller.php
Subfolder1
Subfolder2
Subfolder3
Second_controller.php
FIRST QUESTION - controller sub-directories
My First_controller.php
Link" works fine but my Second_controller.php Link" is not working.
SECOND QUESTION - accessing assets folder
I use following code to include css files in my views:
<link href="<?php echo base_url();?>/assets/bootstrap-4.4.1/css/bootstrap.css" rel="stylesheet">
In my .env file: if I use app.baseURL = 'http://localhost/ci_4_project/public/' then Codeigniter Debug Toolbar is displayed but css files are not included in views.
If I use app.baseURL = 'http://localhost/ci_4_project/' i.e. without appending public then css files are included in views but Codeigniter Debug Toolbar is not displayed. Apparently this is because assets folder is not inside public folder but instead at same level so when I use public in baseURL, assets are not included. My question is: how to define app.baseURL and whether to add public or not in the url.
For your second controller, make sure you correctly namespaced it:
namespace App\Controllers\Subfolder1\Subfolder2\Subfolder3;
Related
I've finished my laravel project and played it in a subfolder on my domain.
https://example.com/swap
So the above is the root of my directory and when I go there, I do get the index. But now every link I press, I'm redirected to the root of my domain. So I'm getting:
https://example.com/events/1
Instead of https://example.com/swap/events/1
Am I forced to change all URLs by hand in my files are is there a way my htaccess can always redirect to this 'swap' folder and place everything behind that?
I've tried using groups in my routes, without success.
Use url for all your links which are inside views folder:
For subfolder link use:
Sub-Folder Link
For root folder links use this syntax:
Index
There might arise issues with stylesheet and javascript in 'swap" sub-folder links with a 404 error. To fix that, use:
<script type="text/javascript" src="{{asset('js/app.js')}}">
<link rel="stylesheet" type="text/css" href="{{asset('css/app.css')}}">
You need to direct your VHOST to laravel's public folder. This is done for security purposes. Ideally your laravel install is outside the public folder, thus you would have yourdomain.com contain your laravel install and rename your public folder to swap.
IF you really want the name swap in your routes you could use route prefix with groups.
Open .env File and Change Your App Url to https://example.com/swap/ and use routes as links of whole application
All Url's Will Work fine.
When putting a laravel application in a subfolder. You need to modify your .htaccess for subfolder hosting. And add the following:
RewriteBase /swap
This way, the app knows when you go to route {{ url('/hello-world') }}, it will ultimately go to "/swap/hello-world"
I'm using Laravel 5.3 and on some pages the css isn't loading. I tried the suggestions from this question, but they didn't help.
This is what I did so far:
I installed Laravel on wamp inside www/lblog directory so I access laravel's main page via http://localhost:8080/lblog/
To get rid of the "public" part from the URL I moved the index.php and htaccess files from the "public" directory to the root directory and changed two lines in index.php like this:
require DIR.'./bootstrap/autoload.php';
$app = require_once DIR.'./bootstrap/app.php';
In "resources/views/layouts/app.blade.php" I have the styles linked like this:
I tried to remove the / before the "css", it didn't work that way either.
The main page is ok, but if I go to http://localhost:8080/lblog/login for example, the style is broken.
Don't hack the core, use it as it is which is recommended.
Use laravel's built in helpers for generating URL for your assets that are on public directory
<link rel="stylesheet" href="{{ asset('css/styles.css') }}">
which will properly generate URL for your files that are on public directory
I have changed the name of codeigniter and placed htdocs then in application folder I have created a new folder in that new folder again I created some folders for different web pages in each and every folder I added controllers,models,view files. Now I want to access a controller file which is in the new folder.
I tried with default route but not working..Can anyone suggest
Create as many folders as you want inside the controller model and view folders in CodeIgniter and not outside them if you really want to organise them.
Remember to set base URL in application/config/config.php file and default router inside the application/config/routes.php file.
If you have problems please comment below describing errors.
I am currently using Laravel 5.2 framework for my web dev project and stuck on problem. In my dashboard.blade.php i want specify the link to an external css file which is in public/src/css/main.css.
I used URL::to() and URL::asset() methods to get the absolute path to the CSS file but still it is not working.
When i placed my CSS file just inside the public directory everything worked fine but when i place it inside any subdirectory in the public directory it doesnot work.
I am homestead along with the laravel as development environment.
dashboard.blade.php file
directory structure of the project
Please put your css in public folder
<link type="text/css" rel="stylesheet" href="{{ asset('css/style.css')}}">
No matter where you place your css file inside public folder you can get it using the code :
<link rel=stylesheet" href="{{asset('src/css/main.css')}}">
For this code place your css file inside public/src/css
In your image of directory there is no folder as css inside src
I'm trying to integrate svg-editor with Laravel 4.
My current solution is to insert svg-editor.html file renamed as svg-editor.php inside my views folder and move the rest of files into the public folder. So now I've moved all the calls to js and css files into the edit view and all points to the public folder to let laravel load the needed files for svg-editor. js and css files are into assets folder and I call them with asset function:
<script>{{{ asset('/assets/js/ *original path from svg-editor* ') }}}</script>
public folder structure
app
public
vendor
svg-edit-2_6
Views folder: inside svg-edit-2_6 there's just svg-editor.php to be able to include on template with #include()
Of course this solution is messy because I've to modify all calls inside svg-editor code such as paths and URLs references. My question is if there's any way to let laravel to load this program without having to modify its params. I think could be possible to make some kind of calls froms start.php file but I could not find information about how to do this.
Could it be possible?