Welcome Guest, Not a member yet? Register   Sign In
Undefined Method for POST/$request->getPOST()
#1

(This post was last modified: 02-06-2024, 02:48 PM by kenjis.)

First off - long time lurker first time poster and I have no programming experience outside of this. I decided to create a database driven website and ended up exploring PHP/CodeIgniter. Those who do this for a living - kudos to you man.... I m just trying to learn however I can and I've made some progress but now, I'm totally stuck. I can't get this POST data to populate. It's probably something really obvious, but I just am stumped.

If anyone could help I'll send a starbucks gift card or something their way, thanks!
<?php

namespace App\Models;

use CodeIgniter\Model;
use Config\Services;

class FileUploadModel extends Model
{
    protected $DBGroup              = 'default';
    protected $table                = 'fileuploads';
    protected $primaryKey          = 'id';
    protected $useAutoIncrement    = true;
    protected $insertID            = 0;
    protected $returnType          = 'object';
    protected $useSoftDeletes      = false;
    protected $protectFields        = true;
    protected $allowedFields        = ['filename', 'filepath', 'created_at', 'updated_at', 'user_id', 'webpath', 'notes' ,'doctype', 'type'];

    // Dates
    protected $useTimestamps        = true;
    protected $dateFormat          = 'date';
    protected $createdField        = 'created_at';
    protected $updatedField        = 'updated_at';
    protected $deletedField        = 'deleted_at';

    // Validation
    protected $validationRules      = [];
    protected $validationMessages  = [];
    protected $skipValidation      = true;
    protected $cleanValidationRules = true;

    // Callbacks
    protected $allowCallbacks      = true;
    protected $beforeInsert        = [];
    protected $afterInsert          = [];
    protected $beforeUpdate        = [];
    protected $afterUpdate          = [];
    protected $beforeFind          = [];
    protected $afterFind            = [];
    protected $beforeDelete        = [];
    protected $afterDelete          = [];



    private function getuserfiles()
    {

                $user_id = 0;
                $user_id = user_id();
                $db = db_connect();
                $builder = $db->table('fileuploads');
                $query= $builder->where('user_id', $user_id, false);
               

        }
}

<?php

namespace App\Controllers;

use App\Controllers\BaseController;
use App\Models\FileUploadModel;
use CodeIgniter\HTTP\Response;
use Config\Services;

class Fileupload extends BaseController
{

        protected $request;
         
        public function index()
      {
              service('request');
              $request = request();
            $fileUploadModel = new FileUploadModel();
     
              $request->getuserfiles();
            return view('includes/file-upload', ['fileUploads/' => $fileUploadModel->orderBy('created_at', 'asc')->findAll()]);

              return $request;
              }

      public function multipleUploads()
      {

              $request = request();
            $files = $this->request->getFileMultiple('fileuploads');
     
           
              $data = [];
              $user_id = 0;
              foreach($files as $file) {
              $data = [
        $user_id => user_id(),
        $doctype => $request->getPost('doctype'),
        $todaysdate => date(m-d-Y),
        $rand => rand(100,999),
        $type => $file->guessExtension(),
        $newName => $doctype . $user_id . $rand . $type,
        $directoryName => WRITEPATH . "uploads/useruploads/" . $user_id . "/",
        $filepath => $directoryName . $newName,
        $webpath => $baseURL . 'public/useruploads/' . $user_id . "/" . $newName,
        $notes => $request->getPost('notes'),
       
              ];


        if ($file->isValid() && ! $file->hasMoved()) {
        $db  = db_connect();
{      $new = model('FileUploadModel', $db);
        $new->save($data);
        $new++;


        }
        if($new <= 0)
        {
            return redirect()->back()->with('error', 'Choose files to upload.');
        }

        return redirect()->back()->with('success', $filesUploaded . ' File/s uploaded successfully.', $data);
              }
              }
      }



}
Reply
#2

Your code is unreadable because the indentation is messed up.

Have you tried the official tutorial?
https://codeigniter.com/user_guide/tutorial/index.html
If not, I recommend you try it first.

Also, if you get an error, I suggest pasting the entire error message. 
That way you will get better help.
Reply
#3

don't need to redeclare $request, it already initiated in basecontroller

$this->request
Reply




Theme © iAndrew 2016 - Forum software by © MyBB