I use:
wampserver
laravel 5
bootstrap v3.3.6
I'm new in laravel, I usually use a manual route::get. Now I try to use route:resource to make things faster but somehow those two display different result even though it's should be showing the same page.
My routes code:
Route::get('create', 'PostController#create');
Route::resource('posts','PostController');
as you can see above, it's directing to the same controller
PostController#create code:
public function create()
{
$data['title'] = ' | Create Post';
return view('posts.create',$data);
}
When I go to blog.dev/create (which is from route::get). It's successfully displaying:
BUT, when I go to blog.dev/posts/create (which is from route::resource). It's showing a css-less page:
Why is that happen? any way to fix it? (I prefer not to use route::get)
Note:
I've tried different browsers, clear cookies&cache and restarting wamp
Both have exactly the same code in view page source from browser.
It seems to be issue with css file paths. Your css paths are relative.
make your css file path to be absolute.
Read this:-
https://css-tricks.com/quick-reminder-about-file-paths/
https://www.w3.org/TR/REC-CSS1/#url
http://jeffreybarke.net/2013/06/paths-and-urls-relative-and-absolute/
Related
I have an issue with my current web project. I need to check if my request contains an input called image, so I just apply the normal method like so:
if($request->has('image'))
{
...
}
But for some reason, this is not working as shown below:
Can someone explain me why ?
I think you need to access uploaded files as,
$request->hasFile('image');
then it should be
if($request->hasFile('image')) { ...
see this DOC
I am using Yii bbii forum module and it works fine. But now I want to add comments-module so every forum post could be seperately commented.
At the begining it might look:
I followed instruction what is here, but I can't make it work :(
And why I even need to include this file, if I want to add just comment?
When I added the same widget to user page (just for testing) - I got "This item cann't be commentable" and it's fine because probably I don't have correct configuration in main.php.
Difference between widget in user model view and forum view is data passed in it.
Here:
public function actionPostComment()
{
if(isset($_POST['Comment']) && Yii::app()->request->isAjaxRequest)
{
$comment = new Comment();
$comment->attributes = $_POST['Comment'];
var_dump($comment);
var_dump returned this when tried to submit comment in forum, and here in user view page.
And probably it is not even possible to combine these to modules? I'm really new in Yii.
Updated:
Basically what I have done is:
exstracted comment module (under protected->modules)
in main.php (under protected->config) added all cofiguration in modules array:
'comments'=>array(
//you may override default config for all connecting models
'defaultModelConfig' => array(
//only registered users can post comments
'registeredOnly' => false,
'useCaptcha' => false,
.......
and in view file _post.php added following:
<?php $this->widget('comments.widgets.ECommentsListWidget', array(
'model' => $data,
));
and var_dump($data) gives this (when this is called in controller where post is reseaved).
An error message was given here:
include(BbiiPost.php): failed to open stream: No such file or directory
You said that the Bbii was working with Yii and it broke when you tried to add comments.
The links to your var_dump files are broken, but I did try to read them ;)
It looks like the comments module is interfering with the POST path so that when the form submission comes in it is in a different path from the root which is confusing the YiiBase's autoloader.
You could try explicitly adding the path to BbiiPost.php to the autoloader's search path, or finding where the include("BbiiPost.php") line is and changing it to an absolute path.
Another possibility is that the forum page you are on has links to add comments but the page routing has not been taken from the route. So it might be that the POST link to the comments is actually at /forum/123/comment/add instead of just /comment/add. So when the form is submitted it is trying to the comments/add controller/action but finding that it is in /forum/view and getting confused about the paths to the include files.
I have generally found that the instructions on the Yii (v1) [v2 docs are much better] site for these modules is flaky at best. Quite often the source download link on the page points to an old buggy version of the code as the project has usually moved somewhere else. You generally need to have a pretty good PHP/Yii knowledge to debug these user-submitted modules and get them working.
http://angulairapi.rohanchhabra.in/airports
This is a very simple route I have created in Laravel. It just takes a json file in the public directory, decodes it into an array and return the same json in response.
If you go the route (mentioned above), the error say "No such file or directory" but it exists in fact. It is working fine on my local machine. But when I pushed the same thing on my server, it is giving me this error.
http://gitlab.learningtechasia.com:8901/rohan0793/angulairapi.git
I have made the repository public so that everyone can have a look.
I have tested on my machine asset() is working for me and the path(public/airports.json) you have written reflect same error for me.
Laravel`s Helper function asset("file_name") generate a URL for an asset.
please check laravel`s helper function documentation for more detail
put this code in your routes.php and try again
<?php
Route::get('/airports', function(){
$airports = json_decode(file_get_contents(asset("airports.json")));
return Response::json($airports);
});
Route::get('/flights', function(){
$airports = json_decode(file_get_contents(asset("flights.json")));
return Response::json($airports);
});
EDIT
When you are working on local machine your url having word public i.e localhost/project-name/public/airports.json.
but when you deploy project on server it seems it remove public word from url, so what happing here, server finding airports.json at location http://angulairapi.rohanchhabra.in/public/airports.json but its not actually there its at location http://angulairapi.rohanchhabra.in/airports.json, so it is recommended to use laravel function(in this case asset()) to generate url/assets link.
An alternative to asset() and Anands answer is the helper function public_path(). It returns an absolute file path from the system point of view and not a URL.
$airports = json_decode(file_get_contents(public_path().DIRECTORY_SEPARATOR."airports.json")));
asset() should be used for URLs to files. URLs that you send to the client. You should work with public_path() for internal things, such as getting the content of a file.
I am getting a strange 500 Internal Server Error with a new script I am trying to implement in the actual site. Here's a screen:
![500 Internal][1]
I can route to this files manually without problems and they are working too. But not in the script itself. The Paths are also correct.
Heres the link to the Site:
[>>> Link <<<][2] (just enter R10369 in the input field or a random number)
Everything else is working correctly except these 3 files:
reseller.php,
checkresellerid.php,
resellermail.php
I googled a bit and everywhere is the .htaccess mentioned. but I never modified it or overwrited it. What could be the Problem? Thanks for any Help and sorry for my bad Englisch.
(Let me know if you want to see the php files)
EDIT: I managed to include my new php files into wordpress but i still got the 500 Error
I checked out the website.
I think Wordpress doesn't let you call .php inside of it's system.
I mean you cannot call PHP files for ajax.
You need to use wordpress ajax. Here is a snippet how to use ajax:
Function.php in your theme file.
function myajax()
{
//do stuff
die();
}
add_action( 'wp_ajax_nopriv_product_s', 'myajax' );
add_action( 'wp_ajax_product_s', 'myajax' );
And in your javascript file using jQuery:
The url may change, maybe it's enough to have wp-admin/admin.ajax.php or something like this, i don't really remember right now.
$.post('/wp-admin/admin-ajax.php',{action:'myajax',yourdata:"mydata"}).done(function(data)
{
//do stuffs
});
Update:
So basically if you want to have ajax request inside wordpresss, you need to define these things and use it like this. the "action" parameter is the function name which you want to call. And you need to put the PHP code into your current theme's function.php.
I have a bit of an annoying problem in Zend Framework 2. My js, which is located in my public/js folder, calls an action in the controller for my admin module. This is the call:
$.post('admin/expand', {
id: CCID
},function(data){
if(data.hasOwnProperty('info')){
expand(data.info);
} else {
console.log('Can\'t find customer info.');
}
},'json');
The call works fine normally, but then sometimes it won't be able to find the action. The console will say:
POST http://localhost/admin/admin/expand 404 (Not Found)
So I'll change the path in the AJAX to just 'expand' instead of 'admin/expand' and it'll work for a while... and then it won't until I change it back!
So it seems that sometimes it gets confused about the routing and sometimes it doesn't. Is this a namespace problem? The js file is supposed to be in my root/public/js, right? Does anyone know what the problem is here?
Try changing the url from admin/expand to /admin/expand . It is more pragmatic to use ZF2 routes.