Translate

Thursday, 1 October 2020

How to link Css and Js Files in Codeigniter 4

1) Download Any Template Html/bootstrap.

2)Past all css/js files in codeigniter project/public folder 


3) Add all html files in View folder rename that file .html to .php file and load view in controller like below shown.

   <?php namespace App\Controllers;
   use CodeIgniter\Controller;
   class User extends BaseController
   {
     public function index()
     {
       return view('home');
     }

     public function about()
     {
       return view('about');
     }

   }
 

4) in header section of view give modify css link 
<link href="main.css" rel="stylesheet"></link> 
TO
<link href="<?php echo site_url('public/main.css');?>" rel="stylesheet"></link>
Same above apply to js file link also Example.
<script src="scripts/main.js" type="text/javascript"></script>
TO
<script src="<?php echo site_url('public/assets/scripts/main.js');?>" type="text/javascript"></script>


5) Add Your template will Installed properly.

I have created Youtube video with practical you watch that and learn more. Link is Given below.



Saturday, 19 September 2020

Codeigniter 4 Insert Data in Database


1) Without Model (using Query Builder) insert data in database in codeigniter 4

Controller -  User.php
location - App/Controller/User.php


     <?php namespace App\Controllers;
     use App\Models\UserModel;
     use CodeIgniter\Controller;

     class User extends BaseController
     {
             public function index()
         {
             return view('home');
         }

         public function insert()
         {
             $data = [ 'name' =>$this->request->getVar('name'),
                 'email' =>$this->request->getVar('email'),
                 'password' =>$this->request->getVar('password') ];

             $db = \Config\Database::connect();
             $builder = $db->table('fullname');
             $builder->insert($data);
         }
     }
     ?>

View - home.php

Location - app/Views/home.php


     <!DOCTYPE html>
     <html lang="en">
     <head>
     <title>Home Page</title>
     <meta charset="utf-8">
     <meta name="viewport" content="width=device-width, initial-scale=1">
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
     </head>
     <body>
     <div class="container">
     <h1>Insert Data</h1>
     <form action="<?php echo site_url('User/insert');?>" method="post">
     <div class="form-group">
         <label for="name">Name:</label>
         <input type="text" class="form-control" id="name" placeholder="Enter Name" name="name">
     </div>
     <div class="form-group">
         <label for="email">Email:</label>
         <input type="email" class="form-control" id="email" placeholder="Enter email" name="email">
     </div>
     <div class="form-group">
         <label for="pwd">Password:</label>
         <input type="password" class="form-control" id="pwd" placeholder="Enter password" name="password">
     </div>
     <button type="submit" class="btn btn-primary">Submit</button>
     </form>
     </div>
     </body>
     </html>
    



2) Codeigniter 4 Insert Data in Database Using Model

  • View File Home.php is same you have to change in controller and add UserModel.php file.
Model - UserModel.php
Location - app/Models/UserModel.php

<?php namespace App\Models;
use CodeIgniter\Model;

class UserModel extends Model
{
     protected $table = 'fullname'; //table name
     protected $allowedFields= ['name','surname','email','password']; //column name of table
}
?>

Controller -  User.php
location - app/Controller/User.php

<?php namespace App\Controllers;
use App\Models\UserModel;
use CodeIgniter\Controller;

class User extends BaseController
{
     public function index()
     {
         return view('home');
     }

     public function insert()
     {
         $data = [ 'name' =>$this->request->getVar('name'),
             'email' =>$this->request->getVar('email'),
             'password' =>$this->request->getVar('password') ];

         $model = new UserModel();
         $model->insert($data);
     }
}
?>



This You Tube Video has full explaination with Practical, you can watch that video.



Thanks.

Friday, 17 July 2020

How to create library in Codeigniter

                                       Library of Codeigniter Tutorial

Library is also class. In Codeigniter class is called as library. On Codeigniter their are lots inbuilt libraries. All inbuilt library locates into System Folder. You can read also.
Codeigniter User guide show about library in if want you can read link    https://codeigniter.com/userguide3/libraries/index.html
 I have example shown below.


 
 
this->load->library('email');

$this->email->from('your@example.com', 'Your Name');
$this->email->to('someone@example.com');
$this->email->cc('another@another-example.com');
$this->email->bcc('them@their-example.com');

$this->email->subject('Email Test');
$this->email->message('Testing the email class.');

$this->email->send();
 
If you are still confuse. This below video will helpbyou and show you detail of library of Codeigniter.




How to download and install Codeigniter in hindi

I created video on how to download and install Codeigniter in hindi. If you have any doubt please comment .
This video have solution for how to download Codeigniter and install in easy way. This tutorial will help you.
That is easiest and simplest way to install Codeigniter