Undefined Offset: 0

hi everyone. I am new to yii and i need help.

i just made one simple application using yii with the help of cookbook and some codes from stratch.

I want to validate login from the fields stored in the database, but i am getting php notice as Undefined offset: 0 and i could not find where the problem is.

my code in useridentity.php inside protected is like this

class UserIdentity extends CUserIdentity

{

private $username;








public function authenticate() {


    $users = UserTable::model()->findByAttributes(array('username' => $this->username));


    if ($users === null || $users === "") {


        echo "Username is Not Valid";


    } else {


        if ($users->password !== md5($this->password)) {


            echo "password Incorrect";


        } else 


            {


            $this->username = $users->username;


            $this->errorCode=self::ERROR_NONE;


	return !$this->errorCode;


        }


    }


}





public function getId() {


    return $this->username;


}

}

i have the controller for model UserTable which points to the one of the table in my databses user_table.

and i have 4 fields in the user_tables and its structure is like this

[i]iduser_table int(11) NOT NULL AUTO_INCREMENT,

employee_code varchar(25) NOT NULL,

username varchar(25) NOT NULL,

password varchar(42) NOT NULL,

PRIMARY KEY (iduser_table),

UNIQUE KEY employee_code_UNIQUE (employee_code),

KEY emp_code_user_tab (employee_code)[/i]

i will be grateful if someone can help me in getting rid from this Undefined offset: 0 error. i have enclosed screenshot of the error page.

The error message and stack trace should tell you which file and which line of code is producing the error. Try posting the stack trace here.

here is the stack trace part

Stack Trace

#0

– C:\wamp\www\stationary\protected\extensions\mbmenu\MbMenu.php(182): CMenu->isItemActive(array("label" => "Change password", "url" => array()), "site/login")

177 if(empty($items[$i][‘items’]) && $this->hideEmptyItems)

178 unset($items[$i][‘items’]);

179 }

180 if(!isset($item[‘active’]))

181 {

182 if(($this->activateParents && $hasActiveChild) || $this->isItemActive($item,$route))

183 $active=$items[$i][‘active’]=true;

184 else

185 $items[$i][‘active’]=false;

186 }

187 else if($item[‘active’])

#1

– C:\wamp\www\stationary\protected\extensions\mbmenu\MbMenu.php(176): MbMenu->normalizeItems(array(array("label" => "Change password", "url" => array()), array("label" => "backup", "url" => array(), "itemOptions" => array("class" => "last"))), "site/login", false, 1)

171 if($this->encodeLabel)

172 $items[$i][‘label’]=CHtml::encode($item[‘label’]);

173 $hasActiveChild=false;

174 if(isset($item[‘items’]))

175 {

176 $items[$i][‘items’]=$this->normalizeItems($item[‘items’],$route,$hasActiveChild, 1);

177 if(empty($items[$i][‘items’]) && $this->hideEmptyItems)

178 unset($items[$i][‘items’]);

179 }

180 if(!isset($item[‘active’]))

181 {

#2

  • C:\wamp\www\yii\framework\zii\widgets\CMenu.php(151): MbMenu->normalizeItems(array(array("label" => "Home", "url" => array("/site/index"), "visible" => true), array("label" => "Company setting", "items" => array(array("label" => "company details", "url" => array("/CompanyDetails/create")), array("label" => "proprieter info", "url" => array("/ProprietarInfo/create"), "itemOptions" => array("class" => "last"))), "visible" => true, "itemOptions" => array("class" => "parent")), array("label" => "masters", "items" => array(array("label" => "purchase", "url" => array("/Purchase/create"), 0 => array("label" => "sales", "url" => array("/Sales/create"), 0 => array("label" => "vendor", "url" => array("/Vendor/create"))), "itemOptions" => array("class" => "last"))), "visible" => true, "itemOptions" => array("class" => "parent")), array("label" => "human resources", "items" => array(array("label" => "department", "url" => array("/Department/create")), array("label" => "employee", "url" => array("/EmployeeTable/create")), array("label" => "department", "url" => array("/EmployeePayroll/create")), array("label" => "Salary ", "url" => array("/SalaryPayment/create"), "itemOptions" => array("class" => "last"))), "visible" => true, "itemOptions" => array("class" => "parent")), …), "site/login", null)

#3

– C:\wamp\www\stationary\protected\extensions\mbmenu\MbMenu.php(99): CMenu->init()

094

095 $this->nljs = "\n";

096 $this->items=$this->cssParentItems($this->items);

097 $this->items=$this->cssLastItems($this->items);

098

099 parent::init();

100 }

101

102

103 /**

104 * Publishes the assets

#4

  • C:\wamp\www\yii\framework\web\CBaseController.php(148): MbMenu->init()

#5

  • C:\wamp\www\yii\framework\web\CBaseController.php(173): CBaseController->createWidget("application.extensions.mbmenu.MbMenu", array("encodeLabel" => false, "items" => array(array("label" => "Home", "url" => array("/site/index"), "visible" => true), array("label" => "Company setting", "items" => array(array("label" => "company details", "url" => array("/CompanyDetails/create")), array("label" => "proprieter info", "url" => array("/ProprietarInfo/create"))), "visible" => true), array("label" => "masters", "items" => array(array("label" => "purchase", "url" => array("/Purchase/create"), 0 => array("label" => "sales", "url" => array("/Sales/create"), 0 => array("label" => "vendor", "url" => array("/Vendor/create"))))), "visible" => true), array("label" => "human resources", "items" => array(array("label" => "department", "url" => array("/Department/create")), array("label" => "employee", "url" => array("/EmployeeTable/create")), array("label" => "department", "url" => array("/EmployeePayroll/create")), array("label" => "Salary ", "url" => array("/SalaryPayment/create"))), "visible" => true), …)))

#6

  • C:\wamp\www\stationary\protected\views\layouts\menu.php(54): CBaseController->widget("application.extensions.mbmenu.MbMenu", array("encodeLabel" => false, "items" => array(array("label" => "Home", "url" => array("/site/index"), "visible" => true), array("label" => "Company setting", "items" => array(array("label" => "company details", "url" => array("/CompanyDetails/create")), array("label" => "proprieter info", "url" => array("/ProprietarInfo/create"))), "visible" => true), array("label" => "masters", "items" => array(array("label" => "purchase", "url" => array("/Purchase/create"), 0 => array("label" => "sales", "url" => array("/Sales/create"), 0 => array("label" => "vendor", "url" => array("/Vendor/create"))))), "visible" => true), array("label" => "human resources", "items" => array(array("label" => "department", "url" => array("/Department/create")), array("label" => "employee", "url" => array("/EmployeeTable/create")), array("label" => "department", "url" => array("/EmployeePayroll/create")), array("label" => "Salary ", "url" => array("/SalaryPayment/create"))), "visible" => true), …)))

#7

  • C:\wamp\www\stationary\protected\views\layouts\main.php(25): include("C:\wamp\www\stationary\protected\views\layouts\menu.php")

#8

  • C:\wamp\www\yii\framework\web\CBaseController.php(127): require("C:\wamp\www\stationary\protected\views\layouts\main.php")

#9

  • C:\wamp\www\yii\framework\web\CBaseController.php(96): CBaseController->renderInternal("C:\wamp\www\stationary\protected\views//layouts/main.php", array("content" => "<div id="content"> <h1>Login</h1> <p>Please fill out the …"), true)

#10

  • C:\wamp\www\yii\framework\web\widgets\CContentDecorator.php(77): CBaseController->renderFile("C:\wamp\www\stationary\protected\views//layouts/main.php", array("content" => "<div id="content"> <h1>Login</h1> <p>Please fill out the …"), true)

#11

  • C:\wamp\www\yii\framework\web\widgets\CContentDecorator.php(55): CContentDecorator->decorate("<div id="content"> <h1>Login</h1> <p>Please fill out the …")

#12

  • C:\wamp\www\yii\framework\web\widgets\COutputProcessor.php(45): CContentDecorator->processOutput("<div id="content"> <h1>Login</h1> <p>Please fill out the …")

#13

  • C:\wamp\www\yii\framework\web\CBaseController.php(207): COutputProcessor->run()

#14

  • C:\wamp\www\yii\framework\web\CBaseController.php(301): CBaseController->endWidget("CContentDecorator")

#15

  • C:\wamp\www\stationary\protected\views\layouts\column1.php(5): CBaseController->endContent()

#16

  • C:\wamp\www\yii\framework\web\CBaseController.php(127): require("C:\wamp\www\stationary\protected\views\layouts\column1.php")

#17

  • C:\wamp\www\yii\framework\web\CBaseController.php(96): CBaseController->renderInternal("C:\wamp\www\stationary\protected\views//layouts/column1.php", array("content" => " <h1>Login</h1> <p>Please fill out the following form with y…"), true)

#18

  • C:\wamp\www\yii\framework\web\CController.php(785): CBaseController->renderFile("C:\wamp\www\stationary\protected\views//layouts/column1.php", array("content" => " <h1>Login</h1> <p>Please fill out the following form with y…"), true)

#19

  • C:\wamp\www\stationary\protected\controllers\SiteController.php(110): CController->render("login", array("model" => LoginForm))

#20

  • C:\wamp\www\yii\framework\web\actions\CInlineAction.php(50): SiteController->actionLogin()

#21

  • C:\wamp\www\yii\framework\web\CController.php(309): CInlineAction->runWithParams(array("r" => "site/login"))

#22

  • C:\wamp\www\yii\framework\web\CController.php(287): CController->runAction(CInlineAction)

#23

  • C:\wamp\www\yii\framework\web\CController.php(266): CController->runActionWithFilters(CInlineAction, array())

#24

  • C:\wamp\www\yii\framework\web\CWebApplication.php(276): CController->run("login")

#25

  • C:\wamp\www\yii\framework\web\CWebApplication.php(135): CWebApplication->runController("site/login")

#26

  • C:\wamp\www\yii\framework\base\CApplication.php(162): CWebApplication->processRequest()

#27

  • C:\wamp\www\stationary\index.php(13): CApplication->run()

And the full error message? Note that the screenshot didn’t attach in your first post.

It looks like the menu configuration has been set incorrectly.

then can u tell me how can i set menu configuration correctly.

i have attached the menu.php and main.php and sitecontroller.php

i think its the problem most new commer face

It’s possibly caused by the empty arrays in the url attributes under your Tools menu. I’d suggest commenting out that section of the menu and seeing if that fixes the problem. If not, try commenting out different parts until you can figure out where the problem is.