you are assuming that $this->Customer is an object. that would be fine in most cases because you declared it a var $models. but if that fatal error appeared then your assuming is wrong, because it says is not an object.
so first make:
var_dump($this->Customer);
to see if in fact $this->Customer have an instance of Customer model. if not then try manually:
AK::import('Customer');
$this->Customer = new Customer();
one problem could be the word you are using. i had problems once using the name "Price", it was the same in singular and plural. are you sure plural of customer is "customers"? use AkInflector::singularize($name); (im not sure it that is the correct sintax, take a look at the API), and if works try the other way, are you sure singular of customers is customer? again use AkInflector::pluralize($arg), to check.
Insanet, thanks for your answer. Customer's plural is definitely "customers".
I tried your solution and it worked:
AK::import('Customer');
$this->Customer = new Customer();
$kunde = $this->Customer->find($this->params['id']);
Thanks! If figured out (because SCAFFOLDING used the same code like I did before without import) that it was my authentication filter that prevented my code to run properly:
class CustomerController extends ApplicationController
{
var $models = 'customer';
function __construct() {
$this->beforeFilter(array('auth'=>array('except'=>array('login', 'login2', 'signup', 'logout', 'listing'))));
}
....
Commenting the line makes my code work, but I still don't know why -- the action login2 was set to not be filtered... Do you have any suggestions? ;) I'd really like to use Akelos more, because I'm actually a RoR-developer but with this small non-profit project I have to use php... Thanks in advance, Michael.
Hi Insanet, thanks for all your help. unfortunately it still does'nt work, I tried your code with calling the super-class-constructor, but no success. Do you have any other idea? Or I have to stick to the
AK::import and $this->Customer = new Customer();
workaround =)
MichaelWhi,
Ive been using Akelos for quite some time now. A couple of things to point out here:
1) The Customer controller should automatically load the customer model. That is part of how MVC works. I would suggest checking two things. Make sure you have a model file called app/models/customer.php AND make sure it is declared as such:
class Customer extends ActiveRecord {
The point I am making above in the code is that customer is singular. Then in your app/controllers/customer_controller.php file, you should be able to reference your model, for example, like so:
$this->customer =& $this->Customer->find('first',$this->params['id']);
If you are still getting this error after checking these things out, try starting over and DO NOT use scaffolding. A lot of new users are robbing themselves of learning Akelos by allowing the scaffolding script to create the installers, models, and controllers for them. Instead, try using the scripts to generate them for you such as:
./script/generate model customer
./script/generate controller customer
Then edit your /app/installers/customer_installer.php and make the fields in the dbase. Finally install your customer table by doing:
./script/migrate customer install
Give that a shot and see if it helps. Cheers!
-- Pogey
1 to 9 of 9