CodeIgniter 3 MY_Loader - codeigniter

I'm using CodeIgniter 3 with HMVC.
In CI2, I could load a model and call functions on one line like this:
$this->load->model('mymodule/mymodule_model')->some_function();
But CI3 throws an error and I have to load the model on a separate line.
Fatal error: Call to undefined method MY_Loader::some_function() in
This works:
$this->load->model('mymodule/mymodule_model');
$this->mymodule_model->some_function();
Is this normal behavior or is something misconfigured with CI3 / HMVC?

Related

codeigniter 4 - Loading helpers and user_agent library in model

I've been struggle with this for hours. I would like to use helpers and the user_agent library on a model.
User_agent: every-time I'm trying to load the user agent library using the next code:
$agent = $this->request->getUserAgent();
I getting the next error:
Error
Call to a member function getUserAgent() on null
When trying to load helper and use it from model for example cookie helper:
helper(cookie);
I think it's loading the helper but when trying to use it I printing next error:
Error Call to a member function is_mobile() on null
There isn't any need to load helpers.
User Agent Class
The User Agent Class provides functions that help identify information
about the browser, mobile device, or robot visiting your site.
$agent = \Config\Services::request()->getUserAgent();
$isMobile = $agent->isMobile();

Codeigniter 4 - route with parameters (segments) not working

I have problems with routing and I just can't figure out what is wrong.
When I need to take parameter from URI I just can't make my route works.
So this is what I have in route.php
$routes->add('admin', 'Admin/Login::index');
$routes->add('admin/login', 'Admin/Login::login');
$routes->add('admin/gUP', 'Admin/AdminGlavni::g_obrada');
$routes->add('admin/cam', 'Admin/AdminGlavni::cam_prikaz');
$routes->add('admin/cam/edit/(:any)', 'Admin/AdminGlavni::cam_edit_show/$1');
but this is not working (all other routes works as they should)
$routes->add('admin/cam/edit/(:any)', 'Admin/AdminGlavni::cam_edit_show/$1');
When I try to reach mydmain.com/admin/cam/edit/1 I get:
404 - File Not Found
Controller or its method is not found: \App\Controllers\Admin::index
and cam_edit_show in AdminGlavni Class is defined like this:
public function cam_edit_show($id) {
......
}
What is wrong whit my route? Please help.
FOUND ANSWER:
Slash in handler was wrong. It supposed to be \ and not /
I think you have a directory called admin and then your controller called AdminGlavni. I solved same issue by just change the **
I changed / to ** where route call controller with the directory.i think it should require namespace pattern
your code:
Admin/AdminGlavni::cam_edit_show/$1
Try with this:
Admin\AdminGlavni::cam_edit_show/$1
find the below as:
$routes->add('admin/cam/edit/(:any)', 'Admin\AdminGlavni::cam_edit_show/$1');

Trying to get property of non-object in codeigniter class my_exception

I encounter this error in my CI code
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: core/MY_Exceptions.php
Line Number: 11
and this is my CI code
class MY_Exceptions extends CI_Exceptions {
function __construct() {
parent::__construct();
$CI =& get_instance();
var_dump($CI);
}
I don't know why this happen, wherein in the documentation it says the same syntax.
Is there anyone here know about this?
What to do about it?
New to me, but I found this and this might help
https://forum.codeigniter.com/thread-67859-post-342719.html
When extending the CI Exception class, there is no way to get the
instance with "get_instance()" because as what i've seen, CI isn't
loading the core before the Exception controller. I need some basic
functions to generate my 404 error pages, so this behavious is
completely useless for me as it only handles static output.

SWIG php how to call reference arguments

I am trying to use my C++ libraries in PHP with SWIG, everything work fine and I generated my shared object precisely. I also include phppointers.i and std_string.i in my interface file. but when I want to call my C++ methods which have reference or pointer arguments in their input section, the method just would not work properly or I got some errors like :
Fatal error:no matching function
for example one of my methods is declared as below:
int func(string &ptr,bool space=true) const;
but when I call this method in my php code as:
$bf->func('abcd',true);
I got this error:
Fatal error:no matching function
I tried to call this function with other ways like:
$str = 'abcd';
$bf->func(&$str,true);
but this time I got following error:
Fatal error: Call-time pass-by-reference has been removed
I am totally confused, I truly appreciate if someone can help me with this problem.

call to undefined method illuminate database schema blueprint::blob()

I'm new to laravel 5 and in my first project when I try to migrate this I got this error:
[Symfony\Component\Debug\Exception\FatalErrorException] Call to
undefined method Illuminate\Database\Schema\Blueprint::blob()
There is no such method blob(). It's binary():
$table->binary('data'); // BLOB equivalent for the database

Resources