Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter v4.3.8 and v4.4.0 Released!
#21

(This post was last modified: 08-28-2023, 11:54 PM by chaos.)

(08-28-2023, 06:16 PM)kenjis Wrote: @chaos Did you customize Services for URI or Request?
Since v4.4.0, Services::request()->getUri() must return the SiteURI instance.
https://codeigniter4.github.io/CodeIgnit...ri-changes
No, I am just calling anchor function (inside a Model if it can help)
Reply
#22

i got this error after upgrading to 4.4.0

TypeError
CodeIgniter\Router\RouteCollection::__construct(): Argument #3 ($routing) must be of type Config\Routing, null given, called in C:\xampp\htdocs\GPMS\vendor\codeigniter4\framework\system\Config\Services.php on line 617
SYSTEMPATH\Router\RouteCollection.php at line 283

276      * Flag to limit or not the routes with {locale} placeholder to App::$supportedLocales
277      */
278    protected bool $useSupportedLocalesOnly = false;
279
280    /**
281      * Constructor
282      */
283    public function __construct(FileLocator $locator, Modules $moduleConfig, Routing $routing)
284    {
285        $this->fileLocator  = $locator;
286        $this->moduleConfig = $moduleConfig;
287
288        $this->httpHost = Services::request()->getServer('HTTP_HOST');
289
290        // Setup based on config file. Let routes file override.
Backtrace Server Request Response Files Memory
SYSTEMPATH\Config\Services.php : 617  —  CodeIgniter\Router\RouteCollection->__construct ( arguments )

610      */
611    public static function routes(bool $getShared = true)
612    {
613        if ($getShared) {
614            return static::getSharedInstance('routes');
615        }
616
617        return new RouteCollection(AppServices::locator(), config(Modules::class), config(Routing::class));
618    }
619
620    /**
621      * The Router class uses a RouteCollection's array of routes, and determines
622      * the correct Controller and Method to execute.
623      *
624      * @return Router
SYSTEMPATH\Config\BaseService.php : 258  —  CodeIgniter\Config\Services::routes ( arguments )

251    {
252        $service = static:ConfusederviceExists($name);
253
254        if ($service === null) {
255            return null;
256        }
257
258        return $service::$name(...$arguments);
259    }
260
261    /**
262      * Check if the requested service is defined and return the declaring
263      * class. Return null if not found.
264      */
265    public static function serviceExists(string $name): ?string
SYSTEMPATH\Config\BaseService.php : 199  —  CodeIgniter\Config\BaseService::__callStatic ( arguments )

192            return static::$mocks[$key];
193        }
194
195        if (! isset(static::$instances[$key])) {
196            // Make sure $getShared is false
197            $params[] = false;
198
199            static::$instances[$key] = AppServices::$key(...$params);
200        }
201
202        return static::$instances[$key];
203    }
204
205    /**
206      * The Autoloader class is the central class that handles our
SYSTEMPATH\Config\Services.php : 614  —  CodeIgniter\Config\BaseService::getSharedInstance ( arguments )

607      * a collection of routes.
608      *
609      * @return RouteCollection
610      */
611    public static function routes(bool $getShared = true)
612    {
613        if ($getShared) {
614            return static::getSharedInstance('routes');
615        }
616
617        return new RouteCollection(AppServices::locator(), config(Modules::class), config(Routing::class));
618    }
619
620    /**
621      * The Router class uses a RouteCollection's array of routes, and determines
SYSTEMPATH\Config\BaseService.php : 258  —  CodeIgniter\Config\Services::routes ()

251    {
252        $service = static:ConfusederviceExists($name);
253
254        if ($service === null) {
255            return null;
256        }
257
258        return $service::$name(...$arguments);
259    }
260
261    /**
262      * Check if the requested service is defined and return the declaring
263      * class. Return null if not found.
264      */
265    public static function serviceExists(string $name): ?string
SYSTEMPATH\CodeIgniter.php : 783  —  CodeIgniter\Config\BaseService::__callStatic ( arguments )

776      * @return string|string[]|null Route filters, that is, the filters specified in the routes file
777      *
778      * @throws RedirectException
779      */
780    protected function tryToRouteIt(?RouteCollectionInterface $routes = null)
781    {
782        if ($routes === null) {
783            $routes = Services::routes()->loadRoutes();
784        }
785
786        // $routes is defined in Config/Routes.php
787        $this->router = Services::router($routes, $this->request);
788
789        $path = $this->determinePath();
790
SYSTEMPATH\CodeIgniter.php : 442  —  CodeIgniter\CodeIgniter->tryToRouteIt ( arguments )

435
436        // Check for a cached page. Execution will stop
437        // if the page has been cached.
438        if (($response = $this->displayCache($cacheConfig)) instanceof ResponseInterface) {
439            return $response;
440        }
441
442        $routeFilter = $this->tryToRouteIt($routes);
443
444        $uri = $this->determinePath();
445
446        if ($this->enableFilters) {
447            // Start up the filters
448            $filters = Services::filters();
449
SYSTEMPATH\CodeIgniter.php : 353  —  CodeIgniter\CodeIgniter->handleRequest ( arguments )

346
347        $this->getRequestObject();
348        $this->getResponseObject();
349
350        $this->spoofRequestMethod();
351
352        try {
353            $this->response = $this->handleRequest($routes, config(Cache::class), $returnResponse);
354        } catch (ResponsableInterface|DeprecatedRedirectException $e) {
355            $this->outputBufferingEnd();
356            if ($e instanceof DeprecatedRedirectException) {
357                $e = new RedirectException($e->getMessage(), $e->getCode(), $e);
358            }
359
360            $this->response = $e->getResponse();
FCPATH\index.php : 79  —  CodeIgniter\CodeIgniter->run ()

72  *---------------------------------------------------------------
73  * LAUNCH THE APPLICATION
74  *---------------------------------------------------------------
75  * Now that everything is set up, it's time to actually fire
76  * up the engines and make this app do its thang.
77  */
78
79 $app->run();
80
81 // Save Config Cache
82 // $factoriesCache->save('config');
83 // ^^^ Uncomment this line if you want to use Config Caching.
84
85 // Exits the application, setting the exit code for CLI-based applications
86 // that might be watching.
Reply
#23

(This post was last modified: 08-29-2023, 06:54 AM by Frederik.)

@sushan
Routing configuration has changed. Pay attention to this:
https://codeigniter.com/user_guide/insta...outing-php

Regards,
Frederik
Reply
#24

(This post was last modified: 08-29-2023, 04:06 PM by ALTITUDE_DEV.)

Hi, thanks for reply, is not working for me : issue open



(08-25-2023, 06:33 AM)ALTITUDE_DEV Wrote: I have a question about how the hot reload bar works. I didn't quite understand it, could you please explain?

Before now, when you update pages of your website, for example, change some text, you will need to go to your browser to click on the reload button. With the hot reloading feature, the system automatically detects changes in files within your app directory and reload your browser for you. See docs.


[Image: qxmwTbn.png]
Reply
#25

(This post was last modified: 09-01-2023, 07:39 AM by Muzikant.)

Thank you Loonie for hot realoading support! I was just thinking about how I could implement it by myself and now I have it with almost no configuration. It is really helping me with frontend, but I am eager to test it with backend too. Thank you again. It is big quality of development improvement for me.
Reply
#26

(08-28-2023, 06:16 PM)kenjis Wrote: @chaos Did you customize Services for URI or Request?
Since v4.4.0, Services::request()->getUri() must return the SiteURI instance.
https://codeigniter4.github.io/CodeIgnit...ri-changes

Hello any help about this? this piece of code writes in to a database a text. The text is loaded from the database and should show a link to click where one can see a battle report. 

If i use anchor in a view no problem, the assert doesn't fail. However if i use anchor helper in a Model (like in the code below) I have the error displayed below. What am i doing wrong? before it used to work.

CODE


Code:
$characterevent_model->add(1, 'towncrier', "App.event_battleexecuted;". $this->battle['id'] ."," .
anchor("battle/view/{$this->battle['id']}", 'here') . "," .
$this->battle['source']['name'] . "," .
$this->battle['target']['name'] . "," .
$winnertext . "," .
$node['longname'],
'high'
);

ERROR


Code:
assert($currentURI instanceof SiteURI)

at SYSTEMPATH\Helpers\url_helper.php:34

Backtrace:
  1    SYSTEMPATH\Helpers\url_helper.php:34
      assert(false, 'assert($currentURI instanceof SiteURI)')

  2    APPPATH\Models\BattleModel.php:877
      site_url('battle/view/9')
'high'
);
Reply
#27

@chaos Show all backtrace and minimum code to reproduce the error.
Reply
#28

(09-06-2023, 02:05 PM)kenjis Wrote: @chaos Show all backtrace and minimum code to reproduce the error.

Sure.

Put this in a Model:

PHP Code:
function replicate_bug ()
 {
$text anchor("battle/view/4"'here'); 
die();

Full Backtrace

Code:
[AssertionError]

assert($currentURI instanceof SiteURI)

at SYSTEMPATH\Helpers\url_helper.php:34

Backtrace:
  1    SYSTEMPATH\Helpers\url_helper.php:34
      assert(false, 'assert($currentURI instanceof SiteURI)')

  2    SYSTEMPATH\Helpers\url_helper.php:151
      site_url('battle/view/4', null, Object(Config\App))

  3    APPPATH\Models\BattleModel.php:894
      anchor('battle/view/4', 'here')

  4    APPPATH\Models\BattleModel.php:840
      App\Models\BattleModel()->replicate_bug()

  5    APPPATH\Models\BattleModel.php:101
      App\Models\BattleModel()->complete()

  6    APPPATH\Models\GameModel.php:69
      App\Models\BattleModel()->execute('9')

  7    APPPATH\Controllers\GameController.php:19
      App\Models\GameModel()->tasks5m()

  8    SYSTEMPATH\CodeIgniter.php:915
      App\Controllers\GameController()->tasks5m('purrpaomiaopuf7345736')

  9    SYSTEMPATH\CodeIgniter.php:492
      CodeIgniter\CodeIgniter()->runController(Object(App\Controllers\GameController))

10    SYSTEMPATH\CodeIgniter.php:353
      CodeIgniter\CodeIgniter()->handleRequest(null, Object(Config\Cache), false)

11    FCPATH\index.php:79
      CodeIgniter\CodeIgniter()->run()
Reply
#29

I cannot reproduce the error.
I see "<a href="http://localhost:8080/index.php/battle/view/4">here</a>".

PHP Code:
<?php

namespace App\Controllers;

class 
Home extends BaseController
{
    public function index(): string
    
{
        return model('Foo')->replicateBug();
    }




PHP Code:
<?php

namespace App\Models;

use 
CodeIgniter\Model;

class 
Foo extends Model
{
    protected $table 'foo';

    public function replicateBug(): string
    
{
        return anchor('battle/view/4''here');
    }

Reply
#30

(This post was last modified: 09-07-2023, 07:12 AM by chaos.)

(09-07-2023, 01:53 AM)kenjis Wrote: I cannot reproduce the error.
I see "<a href="http://localhost:8080/index.php/battle/view/4">here</a>".

PHP Code:
<?php

namespace App\Controllers;

class 
Home extends BaseController
{
    public function index(): string
    
{
        return model('Foo')->replicateBug();
    }




PHP Code:
<?php

namespace App\Models;

use 
CodeIgniter\Model;

class 
Foo extends Model
{
    protected $table 'foo';

    public function replicateBug(): string
    
{
        return anchor('battle/view/4''here');
    }


Note: I checked and I did not extend or replace/customize the URI or Request Service.

Did you try to reproduce it by calling the method from CLI?

I added a debug message and if i browse the app the uri returned is correct: $currentURI CodeIgniter\HTTP\SiteURI#21 (20)

While if i call the method in the Model from CLI and i type from ms-dos: 

Code:
>php public\index.php battle replicate_bug

I have wrong URI: 

PHP Code:
CodeIgniter\HTTP\URI#19 (15) (
    protected 'uriString' -> null
    
private 'baseURL' -> null
    
protected 'segments' -> array (0) []
    protected 'scheme' -> string (4"http"
    protected 'user' -> null
    
protected 'password' -> null
    
protected 'host' -> null
    
protected 'port' -> null
    
protected 'path' -> null
    
protected 'fragment' -> string (0""
    protected 'query' -> array (0) []
    protected 'defaultPorts' -> array (4) [
        'http' => integer 80
        
'https' => integer 443
        
'ftp' => integer 21
        
'sftp' => integer 22
    
]
    protected 'showPassword' -> boolean false
    
protected 'silent' -> boolean false
    
protected 'rawQueryString' -> boolean false

Reply




Theme © iAndrew 2016 - Forum software by © MyBB