Dead end :( Please hlp >> Undefined property: Index::$model in PHP: Create Your Own MVC course

+2 Moroni Lemes · March 31, 2015
Hello guys. I finished these days an app based on PHP: Create Your Own MVC course. Worked pretty well, then I started doing my ajax thing with it. The problem occured when adding a new function in the Index controller to treat data when not called by ajax script.

Message error is:

Notice: Undefined property: Index::$model in /home/moronile/public_html/rodoviariadeindaiatuba/controllers/index.php on line 71

Fatal error: Call to a member function crawlingModeGetPageContent() on a non-object in /home/moronile/public_html/rodoviariadeindaiatuba/controllers/index.php on line 71


Apparently, from my research, the message says model is not a child of Index; line 71 in my code is when my function crawlingModeGetPageContent is told to return the array resulted in a DB query. I tried explicitly load the model in the funcion, although it was never necessary before. Worked okay in localhost, but not in my hosting server, so thats not a good solution. Please advise :'(:)
// This is the option for Google Crawler to get regular stuff
public function crawlingModeGetPageContent($slug){
$this->loadModel('Index');

return $this->model->crawlingModeGetPageContent($slug);
}



My complete code is:

class Index extends Controller {

function __construct() {
parent::__construct();

 
function index() {

// Retrieves URL and try to activate crawlingMode or not
$url = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$getPos = strpos($url, "?_escaped_fragment_=");
if ($getPos > 0){

$urlArray = explode("?_escaped_fragment_=", $url);
$pageSlug = ($urlArray[1] != '') ? $urlArray[1] : 'index';
 
$this->view->crawlingMode = TRUE;
$data = $this->crawlingModeGetPageContent($pageSlug);

$this->view->bodyTitle = $data[0]['title'];
$this->view->bodyContent = $data[0]['content'];
$this->view->title = $pageSlug;
//$this->view->bodyTitle = $data['content'];

} else {
$this->view->crawlingMode = FALSE;
$myTemString = "normal life";
$this->view->js = array('index/js/default.js');
$this->view->title = "Rodoviaria de Indaiatuba";
}


$this->view->render('header');
        $this->view->render('index/index');
$this->view->render('footer');
//echo Hash::create('sha256', 'test', HASH_PASSWORD_KEY);
}



function xhrGetListings(){
$this->model->xhrGetListings();
}

// This is for Ajax called method
public function xhrGetPageContent($slug){

$this->model->novoGet($slug);
//$this->view->render('conteudo/index');
}

// This is the option for Google Crawler to get regular stuff
public function crawlingModeGetPageContent($slug){
$this->loadModel('Index');

return $this->model->crawlingModeGetPageContent($slug);
}
}


Post a Reply

Replies

Oldest  Newest  Rating
+1 Moroni Lemes · April 1, 2015
Sorry for 'the kinda wrong forum'... This code I got from studying this also neat tutorials from JREAM:

https://www.youtube.com/playlist?list=PL7A20112CF84B2229&feature=view_all

I can post more info if needed. But, the thing is all the other functions are working calling the model with no problem. That makes me believe this is the only file with problem... not sure...
  • 1

PHP

107,090 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators