Closed keech closed 9 years ago
I could extend. You did something wrong.
app/classes/database/mysqli/connection.php
<?php
class Database_MySQLi_Connection extends \Fuel\Core\Database_MySQLi_Connection
{
public function test()
{
echo __METHOD__;
}
}
<?php
class Controller_MyCtrl extends Controller
{
public function action_index()
{
$db = \Database_Connection::instance();
$db->test();
}
}
--- a/fuel/app/bootstrap.php
+++ b/fuel/app/bootstrap.php
@@ -5,6 +5,7 @@ require COREPATH.'bootstrap.php';
\Autoloader::add_classes(array(
// Add classes you want to override here
// Example: 'View' => APPPATH.'classes/view.php',
+ 'Database_MySQLi_Connection' => APPPATH.'classes/database/mysqli/connection.php',
));
// Register the autoloader
You need to improve your example before we can help. I notice that your code has syntax errors in and some of the paths seems to have been incorrectly copied. Please make your issue clearer and include the version of fuel you are using, there have been some fixes to classes not being able to be extended recently in 1.8/develop
.
Also seeing that @kenjis is not having any issues and there have been no other reports of this issue I think this issue can be closed.
Ok, I'll try. Thanks.
I found out why this problem has occured. (I use "I use "Fuel: 1.7.1 running in "development" mode")
The key of "classes/database/mysqli/connection.php" is different.
My Source is below.
■fuel/app/bootstrap.php
Autoloader::add_classes(array(
'Database_MySQLi_Connection' => APPPATH.'classes/database/mysqli/connection.php'
));
■fuel/app/config/db.php
return array(
'default' => $default = array(
'type' => 'mysql',
'connection' => array(
),
),
);
And fuel core source is below.
■fuel/core/classes/autoloader.php
public static function load($class)
{
・・・・
if (isset(static::$classes[$class]))
{
・・・・
}
elseif ($full_class = static::find_core_class($class))
{
・・・・
}
・・・・
}
■fuel/core/classes/database/connection.php
public static function instance($name = null, array $config = null, $writable = true)
{
・・・・
$driver = '\\Database_' . ucfirst($config['type']) . '_Connection';
・・・・
{
So "Database_Mysqli_Connection" doesn't be found and
static::find_core_class($class)
will be called.
So my "APPPATH.'classes/database/mysqli/connection.php'" is not called.
When I exchange the all of core source from 1.7.1 from 1.7.2, this problem has not occured.
"strtolower" solves this problem.
■fuel/core/classes/autoloader.php(v1.7.2)
public static function add_classes($classes)
{
foreach ($classes as $class => $path)
{
static::$classes[strtolower($class)] = $path;
}
}
■fuel/core/classes/autoloader.php(v1.7.1)
public static function add_classes($classes)
{
foreach ($classes as $class => $path)
{
static::$classes[$class] = $path;
}
}
Will I close this issue?
Issue
I want to extend "MySQLi_Connection" class, but it seems not to work. I did below.
・/fuel/app/classes/database/mysqli/connection.php
・/fuel/app/classes/database/mysqli/connection.php
・/fuel/app/classes/controller/myctrl.php
But
・/fuel/app/classes/controller/myctrl.php
$db->test();
always calls・/fuel/core/classes/database/mysqli/connection.php
How does it solve?
Thanks.
Reference
https://github.com/fuelphp/orm/issues/18