Laravel 8: Unable to locate a class or view for component [dashboardHeader] - laravel

Everything was fine in my localhost. But after putting in online server I am facing many errors. I got this error and there is not case sensitivity issue in name.
Here is my class name in app->http->view/component
class dashboardHeader extends Component
And here is my calling tag of component in view file.
<x-dashboardHeader />
I also tried this way
<x-dashboardHeader> </x-dashboardHeader>
But still it is not working!

I will put this as an answer since it's too big for the comment.
When you put x-dashboardHeader tag in your template - Laravel is actually trying to load your DashboardHeader class (notice the uppercase D) from the View\Components namespace (read it as LARAVEL_ROOT\App\View\Components\DashboardHeader.php).
It does it using the autoloader which is generated by the composer.
While developing using Windows/MacOS - case sensitivity for the file name isn't a problem, since in those systems you can't have two files with the same name (independent of the name casing). So if you have a file named "myCoolFile" - you can access it using "mycoolfile", "MyCoolFile", etc....
But this isn't the case for unix systems. In those systems file names are case-sensitive. You can have 3 files named "myCoolFile", "mycoolFile", "MyCoolFile" and this won't be a problem. You can test it yourself using:
touch myCoolFile
touch MyCoolFile
touch mycoolfile
ls -l
So going back to Laravel trying to load your LARAVEL_ROOT\App\View\Components\DashboardHeader.php file, the file is named differently in your case dashboardHeader.php. And since DashboardHeader.php and dashboardHeader.php are different files in unix systems - you get the error.
I really hope that I could describe the problem.
This is why I suggest that you might want to read the PHP-PSR docs (which, again, Laravel follows) where it says that classes MUST be named using StudlyCaps. So no "dashboardHeader", no "dashboard_Header" and stuff like that, only "DashboardHeader", "MyCoolClass" and so on.

Related

Trying to implement FPDF with all forms of instantiation but only one form works. Others give Error

Installed crabbley/fpdf-laravel as per instructions. Tried some sample code as follows:
$pdf= app('FPDF');
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Swordsmen Class Times');
$pdf->Output();
While the instantiation of fpdf is different from the samples in the tutorials, all works as expected and the pdf is displayed in the browser. I got this working sample from the crabbley packagist.org/packages/crabbly/fpdf-laravel readme under 'usage'. The 'usage' instructions also provide an alternative instantiation viz: $pdf = new Crabbly\FPDF\FPDF;
The tutorial samples use something slightly different again, ie
require('fpdf.php');
x=new FPDF();
and thus are a little different. When I changed it to be the same as the tutorial, all I changed was the instantiation line from
$pdf= app('FPDF');
to
$pdf = new FPDF('L', 'mm','A4');
and I get the error 'Class 'App\Http\Controllers\FPDF' not found'. I do not understand the difference between the different forms of instantiation and not sure what is going on but I need the latter format so I can set page orientation etc. I also tried the usage format as described above with the same sort of error, ie new Crabbly\FPDF\FPDF not found.
I have tried the require statement but FPDF is not found and I am unsure where to point 'require' to.
Installation consisted of:
composer require crabbly/fpdf-laravel
add Crabbly\FPDF\FpdfServiceProvider::class to config/app.php in the providers section
Any suggestions will be appreciated.
You are using an implementation for the Laravel framework that binds an instance of FPDF to the service container. Using app('FPDF') returns you a new instance of FPDF, which is pretty much the same what new FPDF() would do.
The require way of using it is framework agnostic and would be the way to use FPDF if you are just using a plain PHP script. While you could use this way with Laravel too, why would you want to do that?
The reason the require does not work, by the way, is that the fpdf.php file is not found from where you call it. It would be required to sit in the same directory unless you give it a path. Considering you installed it using composer, the fpdf.php script, if any, should sit inside the vendor directory.
However, just go with using the service container. The line $pdf = new FPDF('L', 'mm','A4'); just creates a new instance of the FPDF class and initializes it by passing arguments to the constructor, these being 'L' for landscape orientation, 'mm' for the measurement unit, and 'A4' for the page size. Without knowing the package you use and having testing it, you should also be able to set them equivalently by calling:
$pdf = app('FPDF', ['L', 'mm', 'A4']);
Hope that helps!

Omnet/Inet : how to access class/submodules to get variables values

in my simulation there is a mobile node composed by the following components from the inet framework:
Now I am working on the UdpApp which is UDPVideoStreamCli.cc which is also given by inet framework as one of example udp application.
Now as you can see from the image I had to access to the lisp module (which is an instance of LispRouting.cc) because I have to read some values or call some public methods of that class...how can I do that? All I know is that I have to start from
getParentModule()->getSubmodule();
but then I don't know how to go on...can you help?
(LispRouting *)getParentModule()->getSubmodule("lisp")
will do the trick. Be sure to check if the returned pointer is not null.
Generally this is bad design as it hard-codes the name and the relative position of the LispRouting module. Any change in naming/architecture will cause crashes.
A proper design would be to create a parameter that specifies the name/path of the lisp submodule (with default value) and then use
#include "inet/common/ModuleAccess.h"
...
LispRouting *lr = getModuleFromPar<LispRouting>(par("lispModule"), this);
and then add a parameter to the module's NED file:
string lispModule = default("^.lisp");
meaning the default place where you can find the lisp module is: go one level up and then find the submodule named "lisp". This is a much better pattern, because the user can later reconfigure the name/placement of the lisp module without breaking the code.

SOAP faultcode list

I'm developing a magento script to import products from a XML file using the API and a SOAP wsdl connection.
I would like to know the faultcode list, I've been searching it for several days without luck, anyone know if there is one at all and where I can find it?
I need to handle the error codes to avoid the code to stop instead of just skipping the errors and continue importing what is correct.
At the moment I just discovered that the faultcode 101 is "Product not exists.".
Here's how to grab the list for your version of Magento. (I can't imagine this would be radically different between versions, but one never knows what's been done to a system)
Find all your api.xml files.
$ find app/code/core -name 'api.xml'
app/code/core/Mage/Api/etc/api.xml
app/code/core/Mage/Catalog/etc/api.xml
app/code/core/Mage/CatalogInventory/etc/api.xml
app/code/core/Mage/Checkout/etc/api.xml
app/code/core/Mage/Core/etc/api.xml
app/code/core/Mage/Customer/etc/api.xml
app/code/core/Mage/Directory/etc/api.xml
app/code/core/Mage/Downloadable/etc/api.xml
app/code/core/Mage/GiftMessage/etc/api.xml
app/code/core/Mage/Sales/etc/api.xml
app/code/core/Mage/Tag/etc/api.xml
Each file will have one or many <faults/> nodes which will contain the code and message.
<!-- File: app/code/core/Mage/CatalogInventory/etc/api.xml -->
<faults module="cataloginventory">
<not_exists>
<code>101</code>
<message>Product not exists.</message>
</not_exists>
<not_updated>
<code>102</code>
<message>Product inventory not updated. Details in error message.</message>
</not_updated>
</faults>
It's probably worth mentioning that the numeric codes aren't unique. Each "soap object" (unsure what to call these) defines its own.
<!-- File: app/code/core/Mage/Sales/etc/api.xml -->
<faults module="sales">
<not_exists>
<code>100</code>
<message>Requested order not exists.</message>
</not_exists>
<filters_invalid>
<code>101</code>
<message>Invalid filters given. Details in error message.</message>
</filters_invalid>
Good luck!

Ruby - Difference between :variable and #variable

As a Ruby on Rails newbie, I understand that the "#" and ":" references have different meanings. I saw this post in SO, which described some of the differences.
# indicates a instance variable (e.g., #my_selection)
: indicates an alias (e.g., :my_selection)
I ran into a situation where I had a standard MVC page, similar to all of the other forms/pages in my webapp.
html.erb snippet
<%= form_for #my_selection do |f| %>
route.rb snippet
resources :my_selections
When I attempt to access this page, I get this error:
NoMethodError in selections#create
Showing C:/somedir/myapp/app/views/my_selections/index.html.erb where line #16 raised:
undefined method `my_selection_index_path' for #<#<Class:0x1197e5676>:0x25439c3b>
Line 16 is the form snippet shown above.
All of my other forms/pages in the same web app are set up in exactly the same way and are working fine. However, once I changed the erb form reference to :my_selection, this error went away and my page behaved normally.
Questions:
Is my understanding of the difference between :my_selections and #my_selections correct?
Why would switching to :my_selection resolve my original error?
Is my understanding of the difference between :my_selections and
#my_selections correct?
Nope :(
: indicates a symbol, its not an alias for anything intrinsically. It's like an immutable string, which is often used as a name to represent something.
In places where the Rails api accepts a symbol in place of an instance variable, internally it's actually doing this:
self.instance_variable_get "##{my_symbol}"
Which actually returns the value of the requested instance variable.
So the only reason that you think symbol correspond to instance variable at all, is because the code that drives the API you are using works that way. Without a framework to do that for you, there is no correlation at all.
Why would switching to :my_selection resolve my original error?
for_form(model_instance) will generate a form that submits to the create action if the model instance is unsaved, or to the update action if the model is already exiting in your DB.
No I don't know what's in #my_selection, but whatever class it is doesn't seem to be generating the routes properly.
resources :my_selections
Will generate a route you would invoke like this:
my_selections_path
How your form is generating a route for my_selection_index_path I'm not sure and it really depends on what your models are.
And when you pass a symbol instead, and there is no corresponding ivar, it uses that as the model name for route generation. Which would do the right thing by trying to invoke my_selections_path, which is directly based on the symbol you pass in.

Serving static files in Sinatra... with beautiful routes?

Assuming I have a directory structure similar to:
path_to_file/one/index.html
How can I set my sinatra app to be routed to
mysite.com/path_to_file/one/
and have the previously mentioned file to render? path_to_file will always stay the same, but there will be different folders (two, three, etc.) inside it.
I've tried the following:
get '/path_to_file/:number' do
File.read(File.join('path_to_file', "#{params[:number]}", "index.html"))
end
but then the e.g. javascript file linked from index.html doesn't render correctly.
Got it!
get '/path_to_file/:number/:file' do
File.read(File.join('path_to_file', "#{params[:number]}", "#{params[:file]}"))
end
get '/path_to_file/:number' do
File.read(File.join('path_to_file', "#{params[:number]}", "index.html"))
end
Order is important, since if these two methods are reversed, get '/path_to_file/:number' becomes a superset of get '/path_to_file/:number/:file'.
Just a thought, but you could setup your server software, Apache, nginx, whatever it is you're using, to serve .css and .js and image files from a different location.

Resources