Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorMichaelWhi
     
    Hello!
    I'm new to Akelos and have/had several problems... Some I managed to get fixed, but I have a big one here:

    CONTROLLER:
    <?php

    class CustomerController extends ApplicationController
    {
    var $models = 'customer';

    function login(){
    }

    function login2(){
    if(!empty($this->params['id'])){
    $kunde = $this->Customer->find($this->params['id']);
    $_SESSION['customer_id'] = $kunde->get('id');
    }
    }

    ...
    END CONTROLLER.


    Whenever I call /customer/login2/1 now, I get this error:
    Fatal error: Call to a member function find() on a non-object in <path>/customer_controller.php on line 17

    I tried everything, $this->customer, $customer and so on... Doesn't work.

    Can somebody give me any suggestions, please? :-)
    Thanks in advance,
    Michael.
    • CommentAuthorinsanet
     

    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.

    • CommentAuthorMichaelWhi
     

    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.

    • CommentAuthorinsanet
     
    show me the code of your filter.
    • CommentAuthorMichaelWhi
     
    class ApplicationController extends BaseActionController
    {
    protected function auth(){
    if(!isset($_SESSION['customer_id'])||@empty($_SESSION['customer_id'])){
    $this->redirectTo(array('controller' => 'customer', 'action' => 'login'));
    } else {
    return true;
    }
    }
    }
    • CommentAuthorinsanet
     
    looks good.try adding parent::__construct(); at the first line of the __contruct.

    function __construct() {
    parent::__construct();
    $this->beforeFilter(array('auth'=>array('except'=>array('login', 'login2', 'signup', 'logout', 'listing'))));
    }
    • CommentAuthorMichaelWhi
     

    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 =)

    • CommentAuthoralexr
     
    have you found a solution? i have the same problem!
    • CommentAuthorpogeybait4883
     

    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