I have successfully removed 'public' from my Laravel project URL.
Now when I include any asset using helper function asset() I have to include public at all places like below.
asset('public/images/a.img')
When I try dumping helper function basepath() and publicpath(), correct values are displayed. How can I avoid writing public all the times in all calls to asset. Is there anyway asset function uses publicpath() instead of basepath().
You have to set your Web Directory on your Web Server to point to
/yourproject/public
it seems like your pointing now to
/yourproject/
Related
When I pass a URL parameter (Laravel 5.4) I'm seeing the static images on my page not load (the usual broken place holder image instead) but without the URL parameter and using the exact same view, they load fine. So http://localhost/site/public/filmpage shows images but http://localhost/site/filmpage/batman doesn't show images (all other assets load fine). Wondering why this is, and how to fix it please?
I've got my web.php route file with:
Route::get('filmpage', 'FilmController#filmpagetest');
Route::get('filmpage/{name}', 'FilmController#filmpage');
then controller file with:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class FilmController extends Controller
{
public function filmpage($name)
{
return view('filmpage',array('name' => $name));
}
public function filmpagetest()
{
return view('filmpage',array('name' => 'hello'));
}
}
I'm running Laravel on my Win 7 64 bit machine, PHP 5.6.24, Bitnami WAMP Stack 7.1.2.
Thanks for any suggestions.
Using informations you provided I think your assets are linked like that:
/path/to/asset/file.ext
but you are loading images using paths like that:
path/to/image.ext
Note missing / and the beginning.
Thats is why your images may not be loaded.
I have am using Laravel and I am trying to call a single php file via the browser, which is
located in my app path.
I have setup a Route::get to a function HomeController#index
function index(){
include(app_path().'/myphpfile.php');
}
And gets called when doing http://localhost:8888/home/index
This is how I call it atm.
The Problem is my file accepts furthe parameters, which are
processed inside my php file like:
http://localhost:8888/myphpfile.php/user/hello1
or
http://localhost:8888/myphpfile.php/user/hello1/default
So I tried to use Route::any.
It is not working. Can I somehow just tell Laravel to pick up the php file like I mentioned above? Other way then using include?
I donĀ“t want to put this file into the public folder.
Something like wildcard routing.
Thank you for your help.
For loading the views in CodeIgniter, I have to repeat loading the fixed views (header and footer) which is a little annoying to be repeated for every view-related controller.
Currently when I want to load views in CI, I do the following:
$this->load->view("header");
$this->load->view("index");
$this->load->view("footer");
Then, how can I change $this->load->view(); to get a parameter (for instance boolean) which allows a view to be loaded before/after the targeted view. Such as this one:
$this->load->view("index", TRUE, FALSE, $data); // TRUE=>header FALSE=>footer $data=>common variable
Is it possible to hack the function like this?
try this library, it worked for me, when I used it
https://github.com/philsturgeon/codeigniter-template
You can do with library.
Create a new library file called template.php and write a function called load_template. In that function, use above code.
public function load_template($view_file_name,$data_array=array())
{
$ci = &get_instatnce();
$ci->load->view("header");
$ci->load->view($view_file_name,$data_array);
$ci->> load->view("footer");
}
You have to load this library in autoload file in config folder. so you don't want to load in all controller.
You can this function like
$this->template->load_template("index");
If you want to pass date to view file, then you can send via $data_array
I am working on a new website being built in SilverStripe. Currently I am having a ton of trouble trying to get the system to let me change the URL alias (or create a second one) for the Security controller's login (and eventually logout) function.
I have tried playing around with the routes.yml file and I tried creating the paths in my own UserController and loading directly from the Security controller with "return Security::login()". But that gives me errors about the use of the static functions.
Unfortunately I don't come from a ton of object oriented experience and this is the first CMS I have used that actually uses a bunch of true object orientation. The current version of SilverStripe we are using is 3.0 (but we will be upgrading to 3.1.1 in a few days).
Does anyone know much about the routing in SilverStripe?
as you stated correctly, SilverStripe has routes, and they can be defined in a yaml config file.
if you take a look at the existing routes.yml in the framework you can see how the default security route is defined:
https://github.com/silverstripe/silverstripe-framework/blob/fd6a1619cb7696d0f7e3ab344bc5ac7d9f6cfe77/_config/routes.yml#L17
if you just want to replace the Secuirty in Secuirty/login, its as easy as just creating your own routes.ymlin mysite/_config/ with the following content:
---
Name: myroutesorsomeotherrandomname
Before: '*'
After:
- '#rootroutes'
- '#coreroutes'
- '#modelascontrollerroutes'
- '#adminroutes'
---
Director:
rules:
'foobar//$Action/$ID/$OtherID': 'Security'
NOTE: make sure you ran a ?flush=1 to ensure the yml file is loaded (they get cached)
also make sure you use spaces in the yml file, if you use tabs you are going to have a bad time
if you however wish to also replace /login and /logout this is no longer a thing for routing.
login and logout are actions (php functions that are listed in Security::$allowed_actions and thus available as URL) on the on Security.
but its still rather easy, just subclass Security and create the actions you want:
<?php
class MySuperSecurity extends Security {
private static $allowed_actions = array(
'showMeTheLoginForm',
'alternative_login_action_with_dashes',
'doTheLogout',
);
function showMeTheLoginForm() {
// can be visited via http://website.com/foobar/showMeTheLoginForm
return $this->login();
}
function alternative_login_action_with_dashes() {
// can be visited via http://website.com/foobar/alternative-login-action-with-dashes
return $this->login();
}
function doTheLogout($redirect = true) {
// can be visited via http://website.com/foobar/doTheLogout
return $this->logout($redirect);
}
}
and make the route point to your new class instead of Security inside the routes.yml:
'foobar//$Action/$ID/$OtherID': 'MySuperSecurity'
NOTE: again, make sure you did a ?flush=1, both the private static $allowed_actions as well as the yml config file are cached by silverstripe.
NOTE: both solutions suggested in this post will create an additional route to login and does not replace the existing one, so the old Security/login will still be available
I don't know nothing about SilverStripe excepting that is a CMS, but i think SilverStripe must provide a way to aliases Url. Also an alternative is create Alias in virtual host definition if you're using apache or in .htaccess file. Refer to apache doc to further details. If you post a skeleton of your .htaccess file or VirtualHost definition i could help you.
I have a website with many scripts written in "pure" PHP, i.e. no specific framework has been used to write the files. Furthermore, all the URLs are custom using .htaccess and specific PHP scripts.
For a smooth transition, I would like to start using CodeIgniter for new pages without disrupting access to the old pages, but all the documentation I've seen on CodeIgniter gives the impression that the whole website (perhaps with a few exceptions) needs to be based on the framework.
Would it be possible to use the framework for single pages here and there while leaving old URLs and code intact?
Short answer, yes.
You could access the CI framework from a subfolder, for instance, leaving the existing site untouched.
i.e
www.site.com/my_new_app/controller/method/
where my_new_app is the renamed application folder.
I'm going to go on the assumption that you already have a basic template system in place, and are able to render full pages with your existing site. Since Codeigniter is really just a framework, there's nothing to stop you from using vanilla php, like include, or additional libraries and classes. So, one thing you can do is dump your site into a sub directory in your views folder, then create a "master" controller which does nothing but load full html pages.
class Master extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
// We're expecting something like "registration/how-to-apply" here
// Whatever your URL is. The .php extension is optional
$args = func_get_args();
$path = 'path_to_my_old_site/'.explode('/', $args);
$this->load->view($path);
}
}
// Then use this in config/routes.php
$route['(:any)'] = 'master/index/$1';
This will route all pages through the master controller. So, yoursite.com/pages/faq will load the file application/views/old_site/pages/faq.php. You can apply different routes as you see fit.
This way, you can take your time migrating to use Codeigniter conventions, one page at a time.