<?php
class actionEdit extends CAction
{
public function run()
{
//grab city
$row = $this->getController()->loadCity(); //how to call this method
//render view
$this->getController()->render('edit', array('city' => $row));
}
}
CityController.php
<?php
class CityController extends CController
{
public $_city;
/**
* Declares class-based actions.
*/
public function actions()
{
return array(
'index' => 'application.controllers.city.actionList',
'edit' => 'application.controllers.city.actionEdit',
);
}
public function loadCity($id = NULL)
{
if ($this->_city === NULL)
{
if ($id !== NULL || isset($_GET['id']))
{
$this->_city = Citi::model()->findbyPk($id !== NULL) ? $id : $_GET['id'];
}
}
return $this->_city;
}
}
but he has also written “if i do an echo in de loadCity() it wil not displays” so I guess the problem could also be another (including the above error).
Whats your url when you try to use the edit action?
it should be something like this:
index.php/city/edit/8
when you set also the approriate settings in the main.php urlManager setting.
Don't know if you have created your classes via yiiconsole with the crud and call the wrong action?
public function loadCity($id=null)
{
if($this->_city===null)
{
if($id!==null || isset($_GET['id']))
$this->_city=Citi::model()->findbyPk($id!==null ? $id : $_GET['id']);
if($this->_city===null)
throw new CHttpException(500,'The requested city does not exist.');
}
return $this->_city;
}