A
A
Anton2015-04-01 23:37:19
Yii
Anton, 2015-04-01 23:37:19

Yii Framework: Why does PHP notice Trying to get property of non-object error appear?

Friends, I just can’t understand why the page shows “PHP notice Trying to get property of non-object” After the transfer, I transferred the Bases, transferred the files. I can't figure out what the problem is.
It exits in the browser.
PHP notice
Trying to get property of non-object
/home/dari_kz/data/www/dari.kz/protected/models/Pages.php(323)
311 return $news;
312 }
313
314 public function addView($pageId) {
315 self::model()->updateCounters(array('views' => 1), 'id=?', array($pageId));
316 }
317
318
319 public function getOnePageInCategory($sefname) {
320 $criteria = new CDbCriteria;
321 $category = Categories::model()->getCategoryBySefName($sefname);
322
323 $criteria->compare('category_id', $category->id);
324 $criteria->compare('active', '1');
325 $criteria->compare('lang_id', Controller::getLangId());
326 $criteria->limit = 1;
327 $criteria->order = 'position ASC';
328 $page = Pages::model()->find($criteria);
329
330 return $page;
331 }
332
333
334 public static function getSearchPages(CDbCriteria $criteria, CPagination $pagination, $searchString) {
335 //$pagination->pageSize = 10;
– /home/dari_kz/data/www/dari.kz/protected/controllers/MainpageController.php(21): Pages->getOnePageInCategory("mainpage")
16
17 public function actionIndex() {
18
19 $this->layout = '';
20 $this->isMainpage = true;
21 $mainpage = Pages::model()->getOnePageInCategory('mainpage');
22
23 $this->render('index', array('mainpage' => $mainpage));
24 }
25
26 public function actionError() {
#1
+ /home/dari_kz/data/www/dari.kz/framework/web/actions/CInlineAction.php(50): MainpageController->actionIndex()
#2
+ /home/dari_kz/data/www/dari.kz/framework/web/CController.php(309): CInlineAction->runWithParams(array())
#3
+ /home/dari_kz/data/www/dari.kz/ framework/web/CController.php(287): CController->runAction(CInlineAction)
#4
+ /home/dari_kz/data/www/dari.kz/framework/web/CController.php(266): CController->runActionWithFilters( CInlineAction, array())
#5
+ /home/dari_kz/data/www/dari.kz/framework/web/CWebApplication.php(283): CController->run("")
#6
+ /home/dari_kz/data /www/dari.kz/framework/web/CWebApplication.php(142): CWebApplication->runController("")
#7
+ /home/dari_kz/data/www/dari.kz/framework/base/CApplication.php( 162): CWebApplication->processRequest()
#8
– /home/dari_kz/data/www/dari.kz/index.php(13): CApplication->run()
08 defined('YII_DEBUG') or define('YII_DEBUG',true);
09 // specify how many levels of call stack should be shown in each log message
10 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
11
12 require_once($yii);
13 Yii::createWebApplication($config)->run();
14
2015-04-02 02:33:14 Apache/2.2.22 (Ubuntu) Yii Framework/1.1.12
If you update the engine, you get an error:
Error 500
Trying to get property of non-object

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
olamedia., 2015-04-01
@w999d

this error occurs when you try to access a property of a variable that is not an object (most often null)
e.g.

function f(){
   return null;// где-то произошла ошибка, возвращаем null заместо объекта
}
$x = f();
$x->a = 5;

in this case
check after
Specially for FanatPHP
function f(){
    $x = null;
    $x->id = 1;
    return $x;
}

$f = f();
var_dump($f);
/*
PHP Warning:  Creating default object from empty value in /test.php on line 6
object(stdClass)#1 (1) {
  ["id"]=>
  int(1)
}
*/

I
Igor Vasiliev, 2017-07-20
@Isolution666

Hello Anton.
Most likely, your server is configured this way, your version of php should have a php.ini file
Look at what is written in the line with the parameter
Sometimes, an error output is indicated in the servers, some change the parameters there when setting up Bitrix. To avoid the "Trying to get property of non-object"
errorwrite this:
On shared hosting, these errors are hidden, and exist as paranormal phenomena, no one believes that these errors exist, but they exist, just secret hosting providers hide the truth from you so that you do not know about it, but I assure you non-object exists !
It was sarcasm, of course you know it, otherwise you would not have written about it here.

M
Mike, 2015-04-02
@Mike77

no category

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question