Codeigniter: Undefined index error [duplicate]

I’m getting an error when trying to display database results in my view saying that the index is undefined.

The error message is- Message: Undefined index: StudentNumber

Here is my model:

class CurrentUser_model extends CI_Model {

    public function __construct(){

        $this->load->database();
    }

    public function get_userinfo($studentNumber){

        $query = $this->db->select('ProgramName, StudentNumber, UserName, FirstName, LastName, Email, Program, Year, Notes')
                          ->from('Users, Programs')
                          ->where('StudentNumber', $studentNumber)
                          ->where('ProgramID', 'Program');

        return $query->get()->result_array();
    }

My controller:

public function index(){


        $data['title'] = 'Current User';

        $studentNumber = 040828055;

        $data['userinfo']    = $this->CurrentUser_model->get_userinfo($studentNumber);

        $this->load->view('CurrentUser/index', $data);
    }

and in my view I’m trying to do this:

echo $userinfo['StudentNumber'];


Source: stackoverflow-php

Codeigniter database reset cache query after one detetion

I have a function which allow me to delete a row on a table. But the problem is that, for database integrity, I have to delete another row on another table that is in relation with the record I want to delete. This is my function :

public function delete($tab)
    {
        $this->db->where('id', $tab['id']);
        $this->db->delete('agent', $tab);
        $this->db->where('id_agent', $tab['id']);
        $this->db->delete('agent_vendeuse', $tab);
    }

I have an error database error on my function :

DELETE FROM `agent_vendeuse` WHERE `id_agent` = '2' AND `id` = '2'

Which means that after I affected the new index ‘id_agent’ for the where clause, the previous one ‘id’ is still in cache.

I guess I have to clean the case after the first deletion but how to write it ?


Source: stackoverflow-php

Rewrite URL to hide id

I have the following url on my website:
www.example.com/video?id=468/video-title

I want to rewrite it in htaccess so that it appears as:
www.example.com/video/video-title

What regex do i need to use in this scenario for the proper rewrite?


Source: stackoverflow-php

Codeigniter and google api integration fail

I am trying to call google api from codeigniter. I have unzipped the google api php library in a directory named asset of the codeigniter root directory. I use the following code to create a user.

require_once 'assets/vendor/autoload.php';
$domain="xxxxxxx.com";

class Google_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    function Create_User($dir,$Given_Name,$Family_Name,$User_Name,$Password)//create a user 
    {
        global $domain;
        $UserInstance = new Google_Service_Directory_User(); 
        $NameInstance = new Google_Service_Directory_UserName(); 

        $NameInstance -> setGivenName($Given_Name); 
        $NameInstance -> setFamilyName($Family_Name); 

        $UserInstance -> setName($NameInstance); 
        $UserInstance -> setHashFunction("MD5"); 
        $UserInstance -> setPrimaryEmail("$User_Name@$domain"); 
        $UserInstance -> setPassword(hash("md5", $Password)); 
        $Create_Error=1;
        try 
        { 
            $createUserResult = $dir -> users -> insert($UserInstance); 
            $Create_Error=0;
        } 
        catch (Google_IO_Exception $gioe) 
        { 
            $Create_Error=$gioe->getMessage(); 
        } 
        catch (Google_Service_Exception $gse) 
        { 
            $Create_Error=$gse->getMessage(); 
        } 
        return $Create_Error;
    }

    function Insert_User($First_Name,$Last_Name,$User_Name,$Password)
    {
        global $domain;
        $Error=0;

        $client = new Google_Client();
        $client->setAuthConfig('assets/auth/service_account.json');
        $client->useApplicationDefaultCredentials();
        $client->addScope('https://www.googleapis.com/auth/admin.directory.user');
        $email="admin@$domain";
        $client->setSubject($email);

        $dir = new Google_Service_Directory($client);
        $Error=self::Exist_user($dir,$User_Name);
        if(!$Error)
        {
            $Error=self::Create_User($dir,$First_Name,$Last_Name,$User_Name,$Password);
        }

        return $Error;
    }
}

When I use Insert_User routine to create a user, it fails after calling the function Create_User on the line

$createUserResult = $dir -> users -> insert($UserInstance);

with an error Severity: Error

Message: Call to undefined method Google_Service_Directory_User::toSimpleObject()

Filename: Service/Resource.php

Line Number: 108

Backtrace:

How can I fix this?


Source: stackoverflow-php

css is not loading in codeigniter 3.1

I am using codeigniter 3.1.
I am trying to read base_url from config file .
However hardcode value is working fine for the same .
my code to read base_url is :

<link rel="stylesheet" type="text/css" href='<?php echo base_url('assets/css/bootstrap.min.css'); ?>' />
<script src='<?php echo base_url('assets/js/bootstrap.min.js'); ?>' />
<link rel="stylesheet" type="text/css" href='<?php echo base_url('assests/css/styles.css'); ?>' />

My config is as follow :

$config['base_url'] = "http://localhost:63342/CI/";


Source: stackoverflow-php