Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New classes autoloader #2345

Closed
RAdevelop opened this issue Nov 25, 2014 · 9 comments
Closed

New classes autoloader #2345

RAdevelop opened this issue Nov 25, 2014 · 9 comments

Comments

@RAdevelop
Copy link

registry); it is more useful than $this->load->model('catalog/category'); because developer cat click at the method name and go to method declaration in IDE. */ /** List of dir for including to "include_path" */ $includePath = array ( DIR_APPLICATION, DIR_APPLICATION.'controller', DIR_APPLICATION.'model', DIR_SYSTEM, DIR_SYSTEM.'engine', DIR_SYSTEM.'library', DIR_DATABASE, ); foreach ($includePath as $path) { set_include_path(get_include_path() . PATH_SEPARATOR . $path); } /** - Classes autoloader - Example: new ModelCatalogCategory($this->registry); - @param $className */ function __autoload($className) { if (class_exists($className)) return true; if ($file = classToPath($className)) { return require_once($file); } else { trigger_error('Error: Could not load class ' . $className . '!'); exit(); } } /** - Build path to class file - @param string $className - @return string|boolean - path to file OR false */ function classToPath($className) { $filePath = preg_replace('/[^a-zA-Z0-9]/', '', $className); $filePath = trim(preg_replace('/([A-Z])/', '_$1', $filePath), '_'); $filePath = strtolower(str_replace('_', '/', $filePath)) . '.php'; if ($f = @fopen($filePath, 'r', true)) { fclose($f); return $filePath; } return false; } ?>
@danielkerr
Copy link
Member

you don't think for one second I tried doing:

new ModelCatalogCategory($this->registry);

its ugly

@RAdevelop
Copy link
Author

may be, but it's more useful for developers... and the php code becomes shorter.

@danielkerr
Copy link
Member

no it does not dip shit!

if you actually put a real example down it would be

$this->model_catalog_category = new ModelCatalogCategory($this->registry);

vs

$this->load->model('catalog/category');

autoloading from my own experience should only be used for loading library classes which opencart does.

@RAdevelop
Copy link
Author

yes, You are right about sintaxis
$this->model_catalog_category = new ModelCatalogCategory($this->registry);

but, in the IDE, for example ZendStudio, or any other, after that
$this->model_catalog_category = new ModelCatalogCategory($this->registry);
$this->model_catalog_category->getCategory($category_id);

You can Ctrl + mouse click on the method or class to go to method/class declaration...

with that
$this->load->model('catalog/category');

you can't do like this...

don't be so angry :) it's your system.
I just proposed amendment

@danielkerr
Copy link
Member

ZendStudio is one of the worst IDE's out there. the company has not produced one successful product.

all they have done is jumped on the back of php and destroyed the language.

@danielkerr
Copy link
Member

I don't need your amendments! your suggestion is not actually helpful and unneeded.

its just the way you would prefer to do something. no bugs or issue to be reported.

this is actually the way that is suggested if you follow ZF way of doing things.

$this->model_catalog_category = new \Model\Catalog\Category($this->registry);

ugly ugly code.

after 7 years they still have not got a decent autoloading system in place.

@RAdevelop
Copy link
Author

Ok, Daniel :) thanks for the answers

@RAdevelop
Copy link
Author

About ugly code...

U should stop coding like this:

for(...){

"SELECT ...."

}

and stop coding like this:

SELECT ..... date_time_field > NOW()

I think You know, that all of this slowdown work of the web site.
I don't understand why You coding like this from release to release

@RAdevelop
Copy link
Author

I like your system (OpenCart). It's simple for work, but same pice of code is ugly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants