We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I want to extend CodeIgniter\View\View class with additional methods. I'm using view layouts.
CodeIgniter\View\View
<?php class MyView extends \CodeIgniter\View\View { public function asset() { //.... } }
app/Config/Services.php file:
app/Config/Services.php
<?php namespace Config; use CodeIgniter\Config\Services as CoreServices; use CodeIgniter\Config\BaseConfig; require_once SYSTEMPATH . 'Config/Services.php'; class class Services extends CoreServices { public static function renderer($viewPath=null, $config=null, bool $getShared=true) { if ($getShared) { return static::getSharedInstance('renderer', $viewPath, $config); } if (is_null($config)) { $config = new \Config\View(); } if (is_null($viewPath)) { $paths = config('Paths'); $viewPath = $paths->viewDirectory; } return new \MyView($config, $viewPath, static::locator(true), CI_DEBUG, static::logger(true)); } }
In my view file, shared instance always return \CodeIgniter\View\View class, not MyView class.
\CodeIgniter\View\View
MyView
app/Views/sample.php file:
app/Views/sample.php
<?php // Error: Call to undefined method CodeIgniter\View\View::asset() $this->asset();
My solution is simple, only move CodeIgniter\Config\BaseService::getSharedInstance() to Config\Services::getSharedInstance().
CodeIgniter\Config\BaseService::getSharedInstance()
Config\Services::getSharedInstance()
Any idea? Thanks.
CodeIgniter 4.0.0-beta-2
Config services files.
The text was updated successfully, but these errors were encountered:
Changing the location of that method will only break functionality and not solve anything.
This isn't a bug, though, so should be asked on the forums.
Bigger question is, though - why are you extending Config\Services? That file is there for you to edit. That's it's sole purpose.
Sorry, something went wrong.
No branches or pull requests
Description/Detail
I want to extend
CodeIgniter\View\View
class with additional methods.I'm using view layouts.
app/Config/Services.php
file:In my view file, shared instance always return
\CodeIgniter\View\View
class, notMyView
class.app/Views/sample.php
file:My solution is simple, only move
CodeIgniter\Config\BaseService::getSharedInstance()
toConfig\Services::getSharedInstance()
.Any idea? Thanks.
Version
CodeIgniter 4.0.0-beta-2
Affected module(s)
Config services files.
The text was updated successfully, but these errors were encountered: