yii2: model relations error can't find another class in ubuntu server 16.04 - yii2

I have upload my YII2 project to ubuntu 16.04.
My source is no problem when run on localhost on my computer, but when I run it on the server ubuntu 16.04 with network, it has a problem.
The model source can't find another relation model
public function getLokasiAwal()
{
return $this->hasOne(KotaBandara::className(), ['id_kota' => 'lokasi_awal']);
}
and i have error
Class 'backend\models\TypeNonstaf' not found
I have found the solution, I added the following code:
use backend\models\Kotabandara;
On top in model file but, in my source in localhost,
I do not need to add that code
Can someone explain that issue??

As #rob006 pointed out, it appears that you had been working/running your app on a Windows local file system, which is case-preserving, but not case-sensitive.
When you first call upon a namespaced class directly or via the use operator, it passes this full class name as $className into yii\BaseYii\autoload::($className) (Yii2's global class autoloading handler), which in turn attempts to include the corresponding class file, if found.
So, on your Windows local machine, when you use backend\models\KotaBandara, it will find and include any file associated with the corresponding path alias in a case-insensitive manner, thus it will find any of:
#backend/models/KotaBandara.php
#backend/models/Kotabandara.php
#backend/models/kotabandara.php
#backend/models/KoTaBaNdArA.php
There can be only 1 target file with this sequence of paths/characters anyway.
However, when you migrate this code to a Ubuntu system, which is both case-preserving and case-sensitive, there is a distinct difference between KotaBandara.php and kotabandara.php and in fact both files can exist side by side, unlike on Windows.
So, you have to be precise here - on Ubuntu, use backend\models\KotaBandara will trigger the autoloader to find only the file whose path AND case matches, i.e. KotaBandara.php. If you named the file kotabandara.php, it will be found on Windows, but not on Ubuntu!

Related

ViewHelper is not found

I fiddled around with it for more than 8 hours without getting it resolved.
All I want is to call a ViewHelper in a Fluid template. I did that before and I never had a similar problem.
My ViewHelper file is located in
EXTDIR/VendorName/Classes/ViewHelpers/SomeViewHelper.php.
In my Fluid Template I use the namespace
{namespace k=VendorName\Extname\ViewHelpers}.
Somewhere in the template I call the ViewHelper with
{k:some()}.
The ViewHelper script "SomeViewHelper.php" contains the following code:
class SomeViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
public function initializeArguments() { }
public function render() {
return 7;
}
}
As you can see, the whole thing is quite simple and the expected output on the page should be "7". But calling a page in the frontend produces this error message:
Oops, an error occurred!
Could not analyse class:VendorName\Extname\ViewHelpers\SomeViewHelper maybe not loaded
or no autoloader?"
Any hints on what might be wrong here?
Cheers
Michael
If everything is spelled correct, and even after deleting System/Configuration Cache the ViewHelper doesn't come up (Could not analyse.. / maybe not loaded or no autoloader), try to reinstall the extension in extension manager!
Your path to the viewHelper source file is wrong.
The correct path should be (without vendorname):
EXTDIR/Classes/ViewHelpers/SomeViewHelper.php
You also need to make sure, you use the correct namespace for your viewHelper (if you're on TYPO3 6+, don't use the old Tx_ classes but namespaces).
<?php
namespace VendorName\Extname\ViewHelpers;
class SomeViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
public function initializeArguments() { }
public function render() {
return 7;
}
}
The error message seems to indicate that the class is not found.
Without more info, I would probably suspect a typo somewhere (pun not intended).
The following assumes you are using TYPO3 7 and not composer mode:
First, please check if your viewhelper class is autoloaded. This will help to narrow down the problem. On the command line in the htdocs directory: grep SomeViewHelper typo3temp/autoload/autoload_classmap.php This should give you a hit, if the ViewHelper class is included in the autoload file.
If the classes are not autoloaded, you might manually want to do the autoloading: On the command line in the htdocs directory: php typo3/cli_dispatch.phpsh extbase extension:dumpclassloadinginformation
For more information see: https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Autoloading/Index.html. For more in depth info see this: http://insight.helhum.io/post/130876393595/how-to-configure-class-loading-for-extensions-in You can find this functionality of autoloading in the install tool in TYPO3 8, so in that case you would not need to run the command on the command line.
If this does not work either, check the following:
Are you using namespace correctly in the class: <?php namespace VendorName\Extname\ViewHelpers\SomeViewHelper;
Is the path (including Camelcase class name) correct: /Classes/ViewHelpers/SomeViewHelper.php
After that, clear the system cache and reinitiate the autoloading as described above.
In order for the autoloading to be initiated automatically, you might have to update your ext_emconf.php (if you are not using composer mode) or composer.json (if you are using composer mode).
Just some questions:
Did you add the TypoScript Template of the Extension to the Static Includes?
If you're using a unix-alike system, are you sure that your webserver has the permission to read that files?
If TYPO3 is installed in composer mode and your extension is not installed via composer (e.g. a ProviderExtension of FluidTYPO3), you must provide autoload information for your extension in the main composer.json file, as described within TYPO3-composer-documentation:
In Composer Mode all class loading information must be provided by each of the installed extensions or the root package. If TYPO3 extensions are not installed by composer, e.g. because they are directly committed to the root package or a new package is kickstarted, class loading information needs to be provided, otherwise no classes can be loaded for these extensions/ packages.
E.g. if you have a site extension directly committed to your root package, you must include the class loading information in the root package like that:
Drove me crazy to get my ViewHelpers autoloaded. Providing the autoload-information within a composer.json or the ext_emconf.php of the extension and reinstalling it didn't do the trick.

Using CakePHP 3.0 plugin

I'm currently building a new CakePHP app with version 3.0.0-RC1, and trying to install and use the jasig/phpCAS plugin. Using this guide, I've run the following command from the command prompt: composer require jasig/phpcas
This correctly copies the jasig/phpcas files into the vendor directory of my app, but one of the other files that the guide says should be updated (vendor/cakephp-plugins.php) doesn't even exist.
I've had a tough time accessing the plugin. I want to be able to call its static methods, and I keep getting errors of the form: Error: Class 'App\Controller\phpCAS' not found. (The exact directory in the error changes depending on where I'm calling the method from.)
I don't know if this is due to not having the cakephp-plugins.php file, or if I'm not calling the plugin correctly. It's my understanding that if the plugin is loaded I should just be able to call static methods on it like this: phpCAS::methodName()
First of all jasig/phpcas is not a CakePHP plugin. And the vendor/cakephp-plugins.php file is created by the CakePHP plugin installer, so if you don't see such a file, you seem to have either not installed any plugins yet, or you are not using a recent version of the installer, as the creation of this file has been introduced just recently.
Regarding the error about the class not being found, you are missing the leading namespace separator (\phpCAS::methodName()) to access the class in the global namespace, respectively you are missing a proper import (use phpCAS;) that would make the class available in the current namespace.
In case you are not familiar with namespaces, you may want to start with: http://php.net/namespaces

How to get sqldb to use a particular fbclient.dll?

I'm using sqldb to connect to Firebird from within my DLL. This fails because it cannot find fbclient.dll which is actually present in the same directory as my DLL. GetCurrentDir returns the path to the Windows system folder. Performing a SetCurrentDir with the path of the DLL successfully changes the current directory, but still it won't work. What can I do to get sqldb to use fbclient.dll at a location of my choosing?
From the wiki page seems there is no way to explicitly specify the directory from where the Firebird client library could be loaded. So as a workaround you may use the SetDllDirectory function which will add a directory provided to its only parameter to the search path used to locate DLL libraries for the application. A subsequent call to LoadLibrary function used to load the Firebird's client library will go through the search list and find it in the location you added by the SetDllDirectory function call.

mysql not in my PATH for some reason

I've installed mysql on several macs and on one of them mysql is not in the path. If I export it it shows up in the path correctly, but upon reboot, disappears.
What should I do to get the machine to keep it in the path and what are the machines that DO have it in their path doing differently?
Any thoughts appreciated.
Check the /etc/profile file on the macs it's working on. The path file should be defined there, which would be for all users. The ~/.bash_profile mentioned is for an individual user.
You should see something similar to the previously mentioned
export PATH=/path/to/mysql_folder:$PATH
in this file, though it may be a bit buried. If you don't see PATH defined here, try /etc/environment. Failing this, I'm not sure where else OS X would define the path variable, but being a Unix system, there is a common file read by all profiles where it sets it.
Once you find it, compare the definition on the machines it works on to the one it doesn't, and edit accordingly. If it looks the same, then something's amiss, and you should let us know.
if it is linux you have to add this export to your profile script. if windows edit PATH in My Computer | Properties | Edit environmental variables
To one of your init files (such as /home/username/.bash_profile) add a line like:
export PATH=/path/to/mysql_folder:$PATH

Get the application's path

I've recently searched how I could get the application's directory in Java. I've finally found the answer but I've needed surprisingly long because searching for such a generic term isn't easy. I think it would be a good idea to compile a list of how to achieve this in multiple languages.
Feel free to up/downvote if you (don't) like the idea and please contribute if you like it.
Clarification:
There's a fine distinction between the directory that contains the executable file and the current working directory (given by pwd under Unix). I was originally interested in the former but feel free to post methods for determining the latter as well (clarifying which one you mean).
In Java the calls
System.getProperty("user.dir")
and
new java.io.File(".").getAbsolutePath();
return the current working directory.
The call to
getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
returns the path to the JAR file containing the current class, or the CLASSPATH element (path) that yielded the current class if you're running directly from the filesystem.
Example:
Your application is located at
C:\MyJar.jar
Open the shell (cmd.exe) and cd to C:\test\subdirectory.
Start the application using the command java -jar C:\MyJar.jar.
The first two calls return 'C:\test\subdirectory'; the third call returns 'C:\MyJar.jar'.
When running from a filesystem rather than a JAR file, the result will be the path to the root of the generated class files, for instance
c:\eclipse\workspaces\YourProject\bin\
The path does not include the package directories for the generated class files.
A complete example to get the application directory without .jar file name, or the corresponding path to the class files if running directly from the filesystem (e.g. when debugging):
String applicationDir = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
if (applicationDir.endsWith(".jar"))
{
applicationDir = new File(applicationDir).getParent();
}
// else we already have the correct answer
In .NET (C#, VB, …), you can query the current Assembly instance for its Location. However, this has the executable's file name appended. The following code sanitizes the path (using System.IO and using System.Reflection):
Directory.GetParent(Assembly.GetExecutingAssembly().Location)
Alternatively, you can use the information provided by AppDomain to search for referenced assemblies:
System.AppDomain.CurrentDomain.BaseDirectory
VB allows another shortcut via the My namespace:
My.Application.Info.DirectoryPath
In Windows, use the WinAPI function GetModuleFileName(). Pass in NULL for the module handle to get the path for the current module.
Python
path = os.path.dirname(__file__)
That gets the path of the current module.
Objective-C Cocoa (Mac OS X, I don't know for iPhone specificities):
NSString * applicationPath = [[NSBundle mainBundle] bundlePath];
In Java, there are two ways to find the application's path. One is to employ System.getProperty:
System.getProperty("user.dir");
Another possibility is the use of java.io.File:
new java.io.File("").getAbsolutePath();
Yet another possibilty uses reflection:
getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
In VB6, you can get the application path using the App.Path property.
Note that this will not have a trailing \ EXCEPT when the application is in the root of the drive.
In the IDE:
?App.Path
C:\Program Files\Microsoft Visual Studio\VB98
In .Net you can use
System.IO.Directory.GetCurrentDirectory
to get the current working directory of the application, and in VB.NET specifically you can use
My.Application.Info.DirectoryPath
to get the directory of the exe.
Delphi
In Windows applications:
Unit Forms;
path := ExtractFilePath(Application.ExeName);
In console applications:
Independent of language, the first command line parameter is the fully qualified executable name:
Unit System;
path := ExtractFilePath(ParamStr(0));
Libc
In *nix type environment (also Cygwin in Windows):
#include <unistd.h>
char *getcwd(char *buf, size_t size);
char *getwd(char *buf); //deprecated
char *get_current_dir_name(void);
See man page
Unix
In unix one can find the path to the executable that was started using the environment variables. It is not necessarily an absolute path, so you would need to combine the current working directory (in the shell: pwd) and/or PATH variable with the value of the 0'th element of the environment.
The value is limited in unix though, as the executable can for example be called through a symbolic link, and only the initial link is used for the environment variable. In general applications on unix are not very robust if they use this for any interesting thing (such as loading resources). On unix, it is common to use hard-coded locations for things, for example a configuration file in /etc where the resource locations are specified.
In bash, the 'pwd' command returns the current working directory.
In PHP :
<?php
echo __DIR__; //same as dirname(__FILE__). will return the directory of the running script
echo $_SERVER["DOCUMENT_ROOT"]; // will return the document root directory under which the current script is executing, as defined in the server's configuration file.
echo getcwd(); //will return the current working directory (it may differ from the current script location).
?>
in Android its
getApplicationInfo().dataDir;
to get SD card, I use
Environment.getExternalStorageDirectory();
Environment.getExternalStoragePublicDirectory(String type);
where the latter is used to store a specific type of file (Audio / Movies etc). You have constants for these strings in Environment class.
Basically, for anything to with app use ApplicationInfo class and for anything to do with data in SD card / External Directory using Environment class.
Docs :
ApplicationInfo ,
Environment
In Tcl
Path of current script:
set path [info script]
Tcl shell path:
set path [info nameofexecutable]
If you need the directory of any of these, do:
set dir [file dirname $path]
Get current (working) directory:
set dir [pwd]
Java:
On all systems (Windows, Linux, Mac OS X) works for me only this:
public static File getApplicationDir()
{
URL url = ClassLoader.getSystemClassLoader().getResource(".");
File applicationDir = null;
try {
applicationDir = new File(url.toURI());
} catch(URISyntaxException e) {
applicationDir = new File(url.getPath());
}
return applicationDir;
}
in Ruby, the following snippet returns the path of the current source file:
path = File.dirname(__FILE__)
In CFML there are two functions for accessing the path of a script:
getBaseTemplatePath()
getCurrentTemplatePath()
Calling getBaseTemplatePath returns the path of the 'base' script - i.e. the one that was requested by the web server.
Calling getCurrentTemplatePath returns the path of the current script - i.e. the one that is currently executing.
Both paths are absolute and contain the full directory+filename of the script.
To determine just the directory, use the function getDirectoryFromPath( ... ) on the results.
So, to determine the directory location of an application, you could do:
<cfset Application.Paths.Root = getDirectoryFromPath( getCurrentTemplatePath() ) />
Inside of the onApplicationStart event for your Application.cfc
To determine the path where the app server running your CFML engine is at, you can access shell commands with cfexecute, so (bearing in mind above discussions on pwd/etc) you can do:
Unix:
<cfexecute name="pwd"/>
for Windows, create a pwd.bat containing text #cd, then:
<cfexecute name="C:\docume~1\myuser\pwd.bat"/>
(Use the variable attribute of cfexecute to store the value instead of outputting to screen.)
In cmd (the Microsoft command line shell)
You can get the name of the script with %* (may be relative to pwd)
This gets directory of script:
set oldpwd=%cd%
cd %0\..
set app_dir=%pwd%
cd %oldpwd%
If you find any bugs, which you will. Then please fix or comment.
I released https://github.com/gpakosz/whereami which solves the problem in C and gives you:
the path to the current executable
the path to the current module (differs from path to executable when calling from a shared library).
It uses GetModuleFileNameW on Windows, parses /proc/self/maps on Linux and Android and uses _NSGetExecutablePath or dladdr on Mac and iOS.
Note to answer "20 above regarding Mac OSX only: If a JAR executable is transformed to an "app" via the OSX JAR BUNDLER, then the getClass().getProtectionDomain().getCodeSource().getLocation(); will NOT return the current directory of the app, but will add the internal directory structure of the app to the response. This internal structure of an app is /theCurrentFolderWhereTheAppReside/Contents/Resources/Java/yourfile
Perhaps this is a little bug in Java. Anyway, one must use method one or two to get the correct answer, and both will deliver the correct answer even if the app is started e.g. via a shortcut located in a different folder or on the desktop.
carl
SoundPimp.com