Error when using Auth with ORM driver kohana 3.3.0 - kohana-3

today i download a 3.3.0 but have error when working with Auth and ORM :
Fatal error: Class 'Auth_Orm' not found in
/home/vsao4/domains/v4.mclub.vn/public_html/modules/auth/classes/Kohana/Auth.php
on line 37
My Auth config as below :
'driver' => 'orm',
'hash_method' => 'md5',
'hash_key' => 'secret',
'lifetime' => 1209600,
'session_type' => Session::$default,
'session_key' => 'auth_user',
and the code is :
$ars = array(
'username'=>'manhquan',
'password'=>'232323',
'email'=>'manhquan#fifthmediacorp.com'
);
if (Auth::instance()->login($ars['username'], $ars['password']))
{
// sucessfully loged
$this->response->body('login');
} else {
//TODO error
$this->response->body('not login');
}

change
'driver' => 'orm',
to
'driver' => 'ORM',
Also, there will be an error to Database_Mysql class. Also change your config/database.php file:
'type' => 'mysql',
to
'type' => 'MySQL',
This happens due to new Kohana conventions:
http://kohanaframework.org/3.3/guide/kohana/conventions

Related

Magento 2 Multi select custom product attribute options not showing

In my custom module, used installData.php to create a custom multiselect attribute. Where i have set the option values from my source class (using Magento\Eav\Model\Entity\Attribute\Source\AbstractSource) which is working fine after installation. I can see the options while editing the product.
But the options are not visible while editing the attribute. Im not able to add/remove option after this.
Please advise.
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'my_option',
[
'group' => 'General',
'label' => 'My Label',
'type' => 'text',
'input' => 'multiselect',
'user_defined' => true,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'source' => 'Vendor\Module\Model\Attribute\Source\Options',
'required' => false,
'filterable' => true,
'filterable_in_search' => true,
'is_searchable_in_grid' => false,
'is_used_in_grid' => false,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => false,
'sort_order' => 200,
'used_in_product_listing' => true,
'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
'visible' => true,
'visible_on_front' => true,
'searchable' => false,
'comparable' => false,
]
);
1. Create InstallData.php file at Vendor\Extension\Setup\ folder.
<?php
namespace Vendor\Extension\Setup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements InstallDataInterface
{
private $eavSetupFactory;
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'eway_option',
[
'group' => 'Groupe Name',
'label' => 'Multiselect Attribute',
'type' => 'text',
'input' => 'multiselect',
'source' => 'Vendor\Extension\Model\Config\Product\Extensionoption',
'required' => false,
'sort_order' => 30,
'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
'used_in_product_listing' => true,
'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
'visible_on_front' => false
]
);
$setup->endSetup();
}
}
2. Create Extensionoption.php file at Vendor\Extension\Model\Config\Product folder.
<?php
namespace Vendor\Extension\Model\Config\Product;
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
class Extensionoption extends AbstractSource
{
protected $optionFactory;
public function getAllOptions()
{
$this->_options = [];
$this->_options[] = ['label' => 'Label 1', 'value' => 'value 1'];
$this->_options[] = ['label' => 'Label 2', 'value' => 'value 2'];
return $this->_options;
}
}

lumen-passport Authentication - $request->user() not setting

I am struggling to login a user using lumen-passport. I have followed the instructions in the link I just supplied but cannot seem to set the user to use in the $request variable of via the Auth facade.
As long as I have my guard driver set to passport in auth.php I cannot get into this block inside AuthServiceProvider.php boot() method no matter what I seem to do:
Auth::viaRequest('api', function ($request) {
if ($request->input('api_token')) {
return User::where('api_token', $request->input('api_token'))->first();
}
});
But even if I try manually return a User record before that call the user is never set, and if I try the following:
Auth::setUser(User::where('id', 1);
I get this message:
InvalidArgumentException in AuthManager.php line 99:
Auth guard driver [api] is not defined.
My query above is definitely returning a record from the User table as well. It's just I cannot get around to setting it so I can access it in my application via the $request->user() method.
Any help would be greatly appreciated as this really has me puzzled. If it helps at all this is my auth.php config.
'defaults' => [
//'guard' => env('AUTH_GUARD', 'api'),
'guard' => 'api',
'passwords' => 'users',
],
'guards' => [
//'api' => ['driver' => 'api'],
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => \App\User::class
]
],
'passwords' => [
//
],
];

CakePHP Bake Error: Database connection “Mysql” is missing, or could not be created

i just download the cakephp 2.5.1 extract and create a database.
now i am try to using cake bake but terminal showing that error (i am using ubuntu)
Error: Database connection “Mysql” is missing, or could not be created
also no issue with database connection.just tested with pages/index function. its working fine.
should i used empty table ? currently i am using current project database.
database.php
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'abcd',
'prefix' => 'lab_',
'encoding' => 'utf8',
);
public $test = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'user',
'password' => 'password',
'database' => 'test_database_name',
'encoding' => 'utf8',
);
}
Sql connect working fine ( find query result ) >
Thanks
update >
Connection, not database
The question is asking which database connection to use - not which database to use i.e.
Which of these to use?
public $default = array();
^ This one?
public $test = array();
^ Or this one?
Answering abcd will cause bake to look for and use public $abcd in the database config class - which evidently is misconfigured.
Try locating 'mysql.sock' and add the path (eg: /tmp/mysql.sock) of this file to the database config entry 'unix_socket'. so your database config looks like this:
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'abcd',
'prefix' => 'lab_',
'encoding' => 'utf8',
'unix_socket' => '/tmp/mysql.sock',
);

Different database instance in Kohana App and Module

I need to make an integration for my application with Wordpress. I have a module for that. But I need to use different database instances. In my App I use 'default' and in Wordpress module I want to use 'wordpress' database instance. How can I do that? Because Database::$default = 'wordpress' in modules\wordpress\init.php sets instances for Module and App.
If you have defined two database connections in your configuration files like this:
config/database.php (can be in APPPATH, MODPATH, etc.)
return array
(
'default' => array
(
'type' => 'mysql',
'connection' => array(
'hostname' => 'localhost',
'username' => 'dbuser',
'password' => 'mypassword',
'persistent' => FALSE,
'database' => 'my_db_name',
),
'table_prefix' => '',
'charset' => 'utf8',
),
'wordpress' => array(
'type' => 'mysql',
'connection' => array(
'hostname' => 'localhost',
'username' => 'other_user',
'password' => 'mypassword',
'persistent' => FALSE,
'database' => 'wordpress',
),
'table_prefix' => '',
'charset' => 'utf8',
),
);
then you can refer to them like this:
// This would connect to the database defined as 'default'
$default = Database::instance();
// This would connect to the database defined as 'wordpress'
$remote = Database::instance('wordpress');
If you are using the ORM module, you do it like this in each Model that uses the WordPress database:
protected String $_db_group = 'wordpress';
(Or, you can create an abstract class...
abstract class Model_WordPress extends ORM
{
protected String $_db_group = 'wordpress';
}
...and then have your WordPress Models extend Model_WordPress instead of directly from ORM. For example, class Model_WordPress_Post extends Model_WordPress ....)

How Kohana implement sessions saved to database?

the source code hands Session_Cookie and Session_Native class but the Session_Database,
here the config file
<?php defined('SYSPATH') or die('No direct script access.');
return array(
'database' => array(
'database' => array(
'name' => 'blog_session_cookie',
'encrypted' => TRUE,
'lifetime' => 43200,
'group' => 'default',
'table' => 'sessions',
'columns' => array(
'session_id' => 'session_id',
'last_active' => 'last_active',
'contents' => 'contents'
),
'gc' => 500,
),
),
);
usage
$session = Session::Instance("Database");
$session->set('username', 'far');
great, its added a column in database, amusing! How the core do that?
thank you.
It's handled by Session_Database class in Database module
See the source: https://github.com/kohana/database/blob/3.2/master/classes/kohana/session/database.php
To implement database session mechanism there is Auth_ORM class in Kohana 3.2.

Resources