xml class cannot be found - php

I am trying to work with fluidxml to test if I can use it, but I cant get it to start working, I am using codeigniter framework. I cloned the repo https://github.com/servo-php/fluidxml and added it to a folder I created called thirdparty. Then here is the code for the function
public function xmltrial(){
$this->load->helper('file');
require_once(APPPATH.'third_party/fluidxml/source/FluidXml.php');
$book = new FluidXml();
$book->add([ 'title' => 'The Theory Of Everything',
'author' => 'S. Hawking',
'chapters' => [
[ 'chapter' => [
'#id' => '1',
'#' => 'Ideas About The Universe' ] ],
[ 'chapter' => [
'#id' => '2',
'#' => 'The Expanding Universe' ] ],
]]);
echo $book;
}
So I am getting two errors , one is Fatal error: Class 'FluidXml' not found even and the second one is if I use use function \FluidXml\fluidxml;
use function \FluidXml\fluidns;
use function \FluidXml\fluidify; all this character inside my xmltrial function it shows a red error on them.

You should use composer to manage your dependencies. Get composer installed, then install FluidXml into the vendor folder by typing
composer require servo/fluidxml
in the command line. Then you can
require_once 'vendor/autoload.php'
in your index.php, and you can forget about having to require in the files! You just need to put the relevant use statement under your namespace declaration.In your case,
use FluidXml\FluidXml;
Now you can start calling your class!
See Packagist for composer package details https://packagist.org/packages/servo/fluidxml
See Composer site to get composer into CodeIgniter if you don't already https://getcomposer.org/

Related

Laravel merging configs in Laravel packages

I'm writing a package on laravel that it require some packages to install.
I want to overwrite own package configuration file with the applications's published copy, and use the mergeConfigFrom method within my package service provider's register method. but it dosent work as i expect
app/config/publishedConfig.php
return [
'dashboard_url' => 'home',
'logout_url' => 'logout',
'login_url' => 'login'
];
And
package/vendor/path/to/config/config.php
return [
'dashboard_url' => 'dashboard/login',
'logout_url' => 'dashboard/logout',
'login_url' => 'mongodb-login'
]
Then in register method on my package service provider i use mergeConfigFrom like below to overwrite publishedConfig on run time:
public function register(){
$this->mergeConfigFrom(
__DIR__.'/config/adminlte-logo.php','publishedConfig'
);
}
After that I use dd(config('publishedConfig')) helper to get result of merge But the result not changed.
expected result is :
'dashboard_url' => 'dashboard/login',
'logout_url' => 'dashboard/logout',
'login_url' => 'mongodb-login'
I will appreciate anyone who solve my issue.
Thanks in advance
Finally i have overwrite it in --force tag way.
php artisan vendor:publish --tag=config --force

Call to undefined method Illuminate\Validation\Rules\In::__set_state()

i tried every method to resolve this, like clear cache,composer update/install, but after php artisan config:cache, it appears again.
In config.php line 839:
Call to undefined method Illuminate\Validation\Rules\In::__set_state()
and whole page turns to blank page.
In bootstrap/cache/config.php file it shows:
'environment' =>
array (
'form' =>
array (
'rules' =>
array (
'app_name' => 'required|string|max:50',
'environment' => 'required|string|max:50',
'environment_custom' => 'required_if:environment,other|max:50',
'app_debug' =>
array (
0 => 'required',
1 =>
Illuminate\Validation\Rules\In::__set_state(array(
'rule' => 'in',
'values' =>
array (
0 => 'true',
1 => 'false',
),
)),
),
I also got this error because instead of
"Illuminate\Validation\Rule"
I have put
"Illuminate\Contracts\Validation\Rule"
This is issue with laravel/framework/src/Illuminate/Validation package.
Here inside Rules folder, we have class named In (file In.php)
It is missing function __set_state .
If you will add following function in this class,
static public function __set_state($array = []){
return 'boolean';
}
The problem will be resolved. Also, it is temporary solution ( composer install/update command can remove your function)
Enjoy...
I think you have some config file with validation rules. Verify if you have config/environment.php file or verify other configuration files.
I think in one of them you have:
Rule::in([true, false]);
You shouldn't use this syntax in configuration files because it cannot be cached, instead you should use:
'in:1,0'
However it seems to be quite strange to keep any validation rules in configuration files.
just delete file config.php
from bootstrap/cache/
and than run
command composer dumpautoload
than
php artisan config:cache
it work for me
Add this code:
use Illuminate\Validation\Rule;
Changing Rule::in([true, false]); with 'in:1,0' worked for me. I needed to remove all strange references to Rule class inside bootstrap/cache/config.php too.
just delete file
config.php
from
bootstrap/cache/
and than run command composer dumpautoload
than php artisan config:cache

Laravel blade template (Undefined class Meta) error

I’m getting error “Undefined class Meta” on my laravel blog application. Also it doesn't provides the title on output. On html output I get blank . Is it problem because of Undefined class Meta? If then how can I define that class on blade engine? Any idea?
Check screen shot to understand
Looks like you haven't installed the package but you're trying to use it.
First, type composer require eusonlito/laravel-meta
Then, in your config/app.php add:
'providers' => [
'...',
Eusonlito\LaravelMeta\MetaServiceProvider::class
];
'aliases' => [
'...',
'Meta' => Eusonlito\LaravelMeta\Facade::class,
];
Then retry. Your app should work

Install Yii2 extension manually without using Composer

I want to install Select 2 extension widget manually with Yii2 Framework without using composer.
I done the following steps but it's not working.
1) Added yii2-widget-select2 to vendor/yii-soft
2) Added following code in my yii-soft/extensions.php:
'yiisoft/yii2-widget-select2' => array(
'name' => 'yiisoft/yii2-widget-select2',
'version' => '2.0.3.0',
'alias' =>
array(
'#yii/kartik' => $vendorDir . '/yiisoft/yii2-widget-select2',
),
),
3) Added display in view form:
use kartik\select2\Select2;
<?php echo Select2::widget([
'model' => $model,
'attribute' => 'state_2',
'data' => $data,
'options' => ['placeholder' => 'Select a state ...'],
'pluginOptions' => [
'allowClear' => true,
],
]); ?>
And It shows the following error:
PHP Fatal Error – yii\base\ErrorException. Class
'kartik\select2\Select2' not found
It's highly recommended to use composer instead.
But if you want to do it manually:
1) Download archive of needed version from Github.
2) Open composer.json.
3) Find PSR-4 autoload section and remember it, in your case: kartik/select2.
4) Extract files to corresponding folder in vendor: vendor/kartik/select2 (not yiisoft!).
5) Add to vendor/composer/autoload_psr4.php:
'kartik\\select2\\' => array($vendorDir . '/kartik/select2'),
6) Add to vendor/yiisoft/extensions.php:
'kartik/select2' => array (
'name' => 'kartik/select2',
'version' => '2',
'alias' => array (
'#kartik/select2' => $vendorDir . '/kartik/select2',
),
),
samdark, one of the core contributors has the article in russian about it on his official blog here. It's basically brief translated version.
As you can see it's quite a lot of work to do. Multiply it by number of extensions and it becomes pain.
Seriously, use composer. If the hoster doesn't support it, find another one.
You can use yii2-workbench package. It designed for easy intergrate package without composer. It support composer autoload and bootstrap
It is subrepository .GIT , delete .git from vendor\kartik-v\yii2-widget-select2 and git rm --cached yii2-widget-select2
Stash, Commit,Push.

How to load a language file from a package in fuelphp?

Using the config.php always_load configuration, how does one load a language file from a package?
All of the fuelphp documentation alludes to being able to do this, but only shows the syntax for loading from a module.
Here's what I'm trying to do:
fuel/app/config/config.php
'always_load' => [
'language' => [
// loads fuel/app/lang/en/login.php into login group
'login',
],
],
fuel/app/config/production/config.php
'always_load' => [
'language' => [
// override /config/config.php with contents from
// /fuel/packages/pkg/lang/en/login.php
'lang_file_from_package' => 'login',
],
],
Packages are core extensions, which means it will merge the contents of the files found in app and in the package.
As such, there is no method to define you want to load it from the package only, other then by specifying a fully qualified pathname, which will always load just that file.

Categories