CodeIgniter 4 from Scratch - #9 - Models

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ธ.ค. 2024

ความคิดเห็น • 62

  • @StanleyOnchari
    @StanleyOnchari 3 ปีที่แล้ว +1

    just got started with MVC and CodeIgniter, I have to admit this has been very helpful. Thank you so much.

  • @StevenMcGregor
    @StevenMcGregor 4 ปีที่แล้ว +3

    Keep them coming. These tutorials have been a great help. Thanks Alex.

    • @AlexLancer
      @AlexLancer  4 ปีที่แล้ว +2

      I am very glad to hear that.

  • @AntonioGarciaMarin
    @AntonioGarciaMarin ปีที่แล้ว +1

    A modern option to create a model is use spark
    >php spark make:model Blog
    Spark create model with all the code

  • @samuelkirbyaguilar7747
    @samuelkirbyaguilar7747 4 ปีที่แล้ว +5

    Hi Alex! Thanks for this video series, it's a huge help!
    I wish you'd zoom in a lot more during the videos though, the text is small and very very hard to see sometimes

    • @AlexLancer
      @AlexLancer  4 ปีที่แล้ว +3

      Got you, Samuel!

  • @windy112233
    @windy112233 4 ปีที่แล้ว +2

    Hi Alex, Great tutorials in this series! What extensions do you have installed for your snippets in Visual Studio?

  • @itsumarejaz
    @itsumarejaz 3 ปีที่แล้ว +1

    What is the extension that you used to comment on multiple lines at 03:21. Thanks in advance

  • @kallisch2000
    @kallisch2000 4 ปีที่แล้ว

    23:31 "Deletes are not allowed unless they contain a "where" or "like" clause". When I exchange find with where it doesn't really delete my entry. It just deletes post_id but not the hole row. What am I missing?

    • @kallisch2000
      @kallisch2000 4 ปีที่แล้ว

      Ok, got it. Didn't set AI onto post_id. Code works now. But why does it make such a big difference in terms of using Db commands?

  • @EliasNPC
    @EliasNPC 2 ปีที่แล้ว

    Hey Alex, ive been having a lot of problems when using $this->where(['id' => $id])->first(); and all of these variants, i might get something like a getUserName function to work on one view but then the next time i need it I might get an array error or something similar, im getting exhausted, oh and also some object errors :S

  • @julkalolz7152
    @julkalolz7152 3 ปีที่แล้ว

    hi i saw u have created a snippet 'ou' for '' . I made one too cause i find it very usefull, but whenever i try to use it between double quotes it does not see the snippet. I see it works for you, so can you please tell me how you did it?

  • @renec.o6765
    @renec.o6765 4 ปีที่แล้ว

    Muchas gracias por tu curso. Me gustaría que pudieras reducir la resolución de tu pantalla para que el espectador pueda tener una mejor visión del código. Saludos

  • @BusinessWolf1
    @BusinessWolf1 2 ปีที่แล้ว +1

    Did they pay you at all for this series? It's really good at 1.25x speed

  • @webvorobey
    @webvorobey 2 ปีที่แล้ว

    Perfect, thanks for your work!

  • @radybmcs6516
    @radybmcs6516 4 ปีที่แล้ว

    how can I check if record are not exist before record to database ?

  • @princeraj9536
    @princeraj9536 4 ปีที่แล้ว

    Really helpful tutorial . Thank you so much Alex

  • @Virtual__Tours
    @Virtual__Tours 4 ปีที่แล้ว +1

    Hi Alex thank you for the awesome content,
    I got this error, please let me know what wrong I've done.
    "message": "You must use the \"set\" method to update an entry.",

    • @Virtual__Tours
      @Virtual__Tours 4 ปีที่แล้ว

      Here is the complete error content.
      {
      "title": "CodeIgniter\\Database\\Exceptions\\DatabaseException",
      "type": "CodeIgniter\\Database\\Exceptions\\DatabaseException",
      "code": 500,
      "message": "You must use the \"set\" method to update an entry.",
      "file": "/home/keju66pioihx/public_html/bds/public_html/system/Database/BaseBuilder.php",
      "line": 2278,
      "trace": [{
      "file": "/home/keju66pioihx/public_html/bds/public_html/system/Database/BaseBuilder.php",
      "line": 2234,
      "function": "validateInsert",
      "class": "CodeIgniter\\Database\\BaseBuilder",
      "type": "->",
      "args": []
      },
      {
      "file": "/home/keju66pioihx/public_html/bds/public_html/system/Model.php",
      "line": 755,
      "function": "insert",
      "class": "CodeIgniter\\Database\\BaseBuilder",
      "type": "->",
      "args": []
      },
      {
      "file": "/home/keju66pioihx/public_html/bds/public_html/system/Model.php",
      "line": 574,
      "function": "insert",
      "class": "CodeIgniter\\Model",
      "type": "->",
      "args": [
      [],
      false
      ]
      },
      {
      "file": "/home/keju66pioihx/public_html/bds/public_html/app/Controllers/Home.php",
      "line": 62,
      "function": "save",
      "class": "CodeIgniter\\Model",
      "type": "->",
      "args": [{
      "name": "ankesh",
      "mobile": "4856734653",
      "aadhar": "86786576655656",
      "village": "village",
      "gram_panchayat": "gram_panchayat",
      "tahseel": "tahseel",
      "district": "district",
      "state": "state",
      "pincode": "pincode",
      "gender": "gender",
      "email": "email",
      "category": "category"
      }]
      },
      {
      "file": "/home/keju66pioihx/public_html/bds/public_html/system/CodeIgniter.php",
      "line": 918,
      "function": "add_update_beneficiary",
      "class": "App\\Controllers\\Home",
      "type": "->",
      "args": []
      },
      {
      "file": "/home/keju66pioihx/public_html/bds/public_html/system/CodeIgniter.php",
      "line": 404,
      "function": "runController",
      "class": "CodeIgniter\\CodeIgniter",
      "type": "->",
      "args": [{}]
      },
      {
      "file": "/home/keju66pioihx/public_html/bds/public_html/system/CodeIgniter.php",
      "line": 312,
      "function": "handleRequest",
      "class": "CodeIgniter\\CodeIgniter",
      "type": "->",
      "args": [
      null,
      {
      "handler": "file",
      "backupHandler": "dummy",
      "storePath": "/home/keju66pioihx/public_html/bds/public_html/writable/cache/",
      "cacheQueryString": false,
      "prefix": "",
      "memcached": {
      "host": "127.0.0.1",
      "port": 11211,
      "weight": 1,
      "raw": false
      },
      "redis": {
      "host": "127.0.0.1",
      "password": null,
      "port": 6379,
      "timeout": 0,
      "database": 0
      },
      "validHandlers": {
      "dummy": "CodeIgniter\\Cache\\Handlers\\DummyHandler",
      "file": "CodeIgniter\\Cache\\Handlers\\FileHandler",
      "memcached": "CodeIgniter\\Cache\\Handlers\\MemcachedHandler",
      "predis": "CodeIgniter\\Cache\\Handlers\\PredisHandler",
      "redis": "CodeIgniter\\Cache\\Handlers\\RedisHandler",
      "wincache": "CodeIgniter\\Cache\\Handlers\\WincacheHandler"
      }
      },
      false
      ]
      },
      {
      "file": "/home/keju66pioihx/public_html/bds/public_html/index.php",
      "line": 45,
      "function": "run",
      "class": "CodeIgniter\\CodeIgniter",
      "type": "->",
      "args": []
      }
      ]
      }

    • @ghulamhyder2628
      @ghulamhyder2628 3 ปีที่แล้ว +1

      you update post method varble names which comes from( form)
      E.g> post-title change in controller method post_title

  • @nanayawowusu1498
    @nanayawowusu1498 3 ปีที่แล้ว

    Please how can i call a custom function from a model to a view? ..... I want to create a function in my model and call it in my view.

  • @SimonCouture1993
    @SimonCouture1993 3 ปีที่แล้ว

    Hey Alex. I'm having an issue when I'm deleting a post. The post gets deleted, but the redirection adds the port :8080 to the url and thus get me the "This site can't be reached" error. I have the exact same code as you do. I don't know if there's a way to prevents the port :8080 to be added to the url? Great tutorials by the way!

  • @siddheshkadam2138
    @siddheshkadam2138 4 ปีที่แล้ว

    How to use Oder by, Joins in Codeighniter 4 Model. Plz help

  • @OneEye-k3m
    @OneEye-k3m หลายเดือนก่อน +1

    I can't insert what is problem?

    • @CT-YS
      @CT-YS 4 วันที่ผ่านมา

      Try CAPS for getMethod() == "POST"

  • @felixmaroy3949
    @felixmaroy3949 4 ปีที่แล้ว

    Hi Alex,
    Can you please make an indeth video on how to create core system classes in CI4 and an advanced tutorial on how to extend controllers (eg: My_controller.php, Public_controller.php, Admin_controller.php, etc...) ?
    I have a project in CI3 which I would like to migrate in CI4.
    But I see things changed completely in CI4.

  • @EvanAbaddon
    @EvanAbaddon 4 ปีที่แล้ว +1

    Thankyou my friend, you help me a lot. If you mind. please make a tutorial for build front end and back end technique

    • @AlexLancer
      @AlexLancer  4 ปีที่แล้ว +2

      I will publish a tutorial on how to create a website with backend later this month hopefully.

    • @EvanAbaddon
      @EvanAbaddon 4 ปีที่แล้ว

      @@AlexLancer awesome Thankyou,

  • @nijilnandanam
    @nijilnandanam 4 ปีที่แล้ว

    Hi Alex,
    Could you please help me building a CI 4 ACL library . If there is any reference links would be very great
    Thanks in Advance
    Nijil

  • @outstyler
    @outstyler 2 ปีที่แล้ว

    Hello Alex, for join queries, (eg: display a list of blogpost title, with the name of the post_category they belong to)
    Many table have the same column field name (post>title, category>title, sector>title) and when joining them, this create problems.
    Is the only solution to create unique fieldnames in every table ? (eg: posts>post_title; categories>category_title, ...) there is no cleaner ways?
    Thank you!

    • @AlexLancer
      @AlexLancer  2 ปีที่แล้ว +1

      A 'cleaner' way would be to use SELECT posts.title as post_title, categories.title as category_title......and so on
      but for large tables with multiple similar columns it is an issue. That's the reason why i always use prefixes.

  • @JeewakaKarunaratne
    @JeewakaKarunaratne 4 ปีที่แล้ว

    hi Alex, can you give code in text rather video?

  • @JeewakaKarunaratne
    @JeewakaKarunaratne 4 ปีที่แล้ว

    Dear Alex,
    Can you show how to do form and search query?
    I believe from view - form action passes to controller and then to model and bring back to search result page. can you show am example?
    appreciate

    • @AlexLancer
      @AlexLancer  4 ปีที่แล้ว

      do you mean how to search using query variables in url ?
      domain/search?quesry=findsometthing&user_id=54 and so on ?

    • @JeewakaKarunaratne
      @JeewakaKarunaratne 4 ปีที่แล้ว

      @@AlexLancer no
      I have a form that search accommodation.
      Thank you Alex

    • @AlexLancer
      @AlexLancer  4 ปีที่แล้ว +1

      @@JeewakaKarunaratne upload your code somewhere to show me, I don;t understand what exactly you want me to show.
      If it is a POST form the use in your controller $this->request->getPost('field_name')

  • @EvilGazz
    @EvilGazz 4 ปีที่แล้ว

    Thanks for the very useful content!

    • @AlexLancer
      @AlexLancer  4 ปีที่แล้ว

      Glad it was helpful!

  • @bhattacharyasamudra
    @bhattacharyasamudra 4 ปีที่แล้ว

    Thank you Alex You are doing a great work...I have subscribed your channel...want a small help...I am using Visual Studio Version: 1.46.1 (user setup) but whenever I am typing a function VS is not showing as many options as it is showing in your video...it is showing mostly php functions but not the codeIgniter functions...you must have enabled some functions in VS..please can you tell me which option??? or can you make a small tutorial how to use VS for CodeIgniter..it may help new users like me...

  • @mrpddnos
    @mrpddnos 4 ปีที่แล้ว

    Can’t you use the base model class to manually build a query without creating the custom model?

    • @AlexLancer
      @AlexLancer  4 ปีที่แล้ว

      You can use Query builder class. But some times you don't want to tie you Model to a specific Table (as 'Base Model' class requires.). Therefore, when you want to have more freedom you should use Custom Model

  • @Adventure1844
    @Adventure1844 3 ปีที่แล้ว

    Very Thanks!

  • @sakmaestro3852
    @sakmaestro3852 ปีที่แล้ว

    Hi alex, why do u prefer Codeigniter over other frameworks of PHP?

    • @vagelisilias
      @vagelisilias 8 หลายเดือนก่อน

      Stay with Laravel is better syntax, bigger community, loads resources out there, and one of the hotest backend framework with loads functionalities and build-in capabilities, codeigniter is a bit outdated these days and not much you can do, nice to have it but not much, I would highly recommended Laravel and Symfony.

  • @itsRekx
    @itsRekx 4 ปีที่แล้ว

    Sir, you imported "CodeIgniter \ Model" into the BlogModel but not into the CustomModel, will that affect it later? What's the difference?

    • @AlexLancer
      @AlexLancer  4 ปีที่แล้ว

      BlogModel extends Codeigniter's core model class, therefore you have access to some methods right away (findAll, save(), insert()), but you also have to define some properties to that class such as: $table, $allowedFields, $primaryKy etc.. So BlogModel is tight to one table in your database.
      Now, if you want more flexibility, similar to Ci3, you create a Model that does not extend any other classes, it is on it's own, and there you can create any table related rules, perform multiple joins and generally be more free to do your own logic.

  • @spampoczta2
    @spampoczta2 4 ปีที่แล้ว

    Very goog job !!!

  • @duredurrani
    @duredurrani 4 ปีที่แล้ว

    Nice tutorial

  • @ramsheedm5324
    @ramsheedm5324 4 ปีที่แล้ว

    thanks alex

  • @opensourcetech9044
    @opensourcetech9044 4 ปีที่แล้ว

    Can I use ci4 for production?

    • @AlexLancer
      @AlexLancer  4 ปีที่แล้ว

      Of course. It is a stable release.

  • @mhankalbhagt6030
    @mhankalbhagt6030 4 ปีที่แล้ว

    sir plez.. apload a video for Image Manipulation Class in codeigniter 4.0.3 as soon as posible my project aswell as complete
    i had only one proble with image compression plez.. help me sir hope you do thanks in advance

    • @AlexLancer
      @AlexLancer  4 ปีที่แล้ว +1

      Later this week my friend.

    • @mhankalbhagt6030
      @mhankalbhagt6030 4 ปีที่แล้ว

      @@AlexLancer thanks sir , iam wating for this

  • @ozanulutas3334
    @ozanulutas3334 4 ปีที่แล้ว

    I had this "CodeIgniter\Database\Exceptions\DatabaseException #8 - Unable to connect to the database" error on spark server.
    The following solution worked for me, maybe somebody benefit from it too. Btw I don't know if this solution is safe for production.
    Change the "database.default.hostname" from "localhost" to "127.0.0.1" on .env file;
    database.default.hostname = 127.0.0.1
    and
    Change the mod of writable folder to 777. Open the terminal on project folder;
    chmod 777 -R writable

  • @telenorquiz1811
    @telenorquiz1811 4 ปีที่แล้ว +1

    Recording yourself in a programming video is completely useless effort, please focus on the program when you are recording a program. Besides all of these, your programming skills are awesome. I learned a lot from your videos.