codeigniter-4

Error: Call to undefined method CodeIgniter\Database\MySQLi\Result::paginate()

左心房为你撑大大i 提交于 2021-01-28 05:26:10
问题 Struggling to wrap my head around paginate in CI4. All examples in the user guide shows the ->paginate() method linked directly onto the $model variable (without arguments) in the Controller. I have all my queries in the Model, so I'm a bit confused if the paginate method goes onto the end of my query there, or where it's called in the Controller. I've tried both - neither work. Model: public function brand_name($brand_name_slug) { return $this ->db ->table('shop a') ->select() ->join('

Not redirected to specific URL in Codeigniter 4

一世执手 提交于 2021-01-27 13:50:49
问题 Why is it that whenever I redirect something through the constructor of my Codeigniter 4 controller is not working? <?php namespace App\Controllers\Web\Auth; class Register extends \App\Controllers\BaseController { function __construct() { if(session('username')){ return redirect()->to('/dashboard'); } } public function index() { // return view('welcome_message'); } } But if I put it inside index it's working as expected. public function index() { if(session('username')){ return redirect()-

CodeIgniter 4 Models->find()

孤人 提交于 2021-01-05 07:51:06
问题 i'm so sorry if this question already asked before, so what i'm trying to do is to get result like this from my models $data = $userModel->where('username', 'myname')->find(); my expectation : $data = [ 'id' => 1, 'username' => 'myname', 'fullname' => 'my full name', ] what i get : $data = [ 0 => [ 'id' => 1, 'username' => 'myname', 'fullname' => 'my full name', ] ] from the docs here, it does return a single row as result, but when i want to use the value of the array, i need to type it like

Codeigniter redirect()->to() doesnt work in __construct()

*爱你&永不变心* 提交于 2020-11-25 03:46:08
问题 I have code in my controller public function __construct() { return redirect()->to('/auth'); $this->validation = \Config\Services::validation(); $this->title = 'Header Menu'; $this->controller = 'user'; } public function index() { $data = [ 'title_prefix' => 'Profil', 'title' => $this->title, 'controller' => $this->controller, 'button_add' => false, 'validation' => $this->validation ]; return view('user/index', $data); } it still show view('user/index'). How to get to return redirect()->to('

Codeigniter redirect()->to() doesnt work in __construct()

给你一囗甜甜゛ 提交于 2020-11-25 03:45:10
问题 I have code in my controller public function __construct() { return redirect()->to('/auth'); $this->validation = \Config\Services::validation(); $this->title = 'Header Menu'; $this->controller = 'user'; } public function index() { $data = [ 'title_prefix' => 'Profil', 'title' => $this->title, 'controller' => $this->controller, 'button_add' => false, 'validation' => $this->validation ]; return view('user/index', $data); } it still show view('user/index'). How to get to return redirect()->to('

Codeigniter 4: Uploading files with move_uploaded_file

ぃ、小莉子 提交于 2020-08-20 03:02:17
问题 I just started moving CodeIgniter 3 project to CodeIgniter 4. Everything works fine except file upload. I would like to keep the user uploaded files in /writable/uploads. Below is the code I use to move the uploaded file to desired location. $target_dir = '/writable/uploads/recordings/'; $target_file = $target_dir . basename($_FILES["gfile"]["name"]); $FileType = pathinfo($target_file,PATHINFO_EXTENSION); if($FileType != "mp3") { $vmuploadOk = 1; } else $vmuploadOk = 1; if ($vmuploadOk == 1)